{"action":"created","comment":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/38352644","id":38352644,"diff_hunk":"@@ -45,3 +59,107 @@ sol_util_timespec_get_realtime(struct timespec *t)\n {\n     return clock_gettime(CLOCK_REALTIME, t);\n }\n+\n+static int\n+rand_gen(struct sol_uuid *p)\n+{\n+    struct sol_buffer buffer = SOL_BUFFER_INIT_EMPTY;\n+    int n = sizeof(*p);\n+    int fd = -1;\n+    int r;\n+\n+#ifdef HAVE_GETRANDOM\n+    r = syscall(SYS_getrandom, p, n, 0);\n+    if (r == n)\n+        return 0;\n+\n+    if (r < 0) {\n+        if (errno != EAGAIN) { /* fallback to /dev/urandom on EAGAIN\n+                                * -- good enough for our uses */\n+            return -errno;\n+        }\n+    } else\n+        return -ENODATA;\n+#endif\n+\n+    fd = open(\"/dev/urandom\", O_RDONLY | O_CLOEXEC | O_NOCTTY);\n+    if (fd < 0)\n+        return errno == ENOENT ? -ENOSYS : -errno;\n+\n+    r = sol_buffer_ensure(&buffer, n);\n+    if (r < 0) {\n+        close(fd);\n+        return -ENOMEM;\n+    }\n+    r = sol_util_fill_buffer(fd, &buffer, n);\n+    if (r < 0)\n+        goto end;\n+\n+    memcpy(p, buffer.data, n);\n+\n+end:\n+    close(fd);\n+    sol_buffer_fini(&buffer);\n+    return r;\n+}\n+\n+static struct sol_uuid\n+assert_uuid_v4(struct sol_uuid id)\n+{\n+    id.bytes[6] = (id.bytes[6] & 0x0F) | 0x40;\n+    id.bytes[8] = (id.bytes[8] & 0x3F) | 0x80;\n+\n+    return id;\n+}\n+\n+static int\n+uuid_gen(struct sol_uuid *ret)\n+{\n+    struct sol_uuid t;\n+    int r;\n+\n+    SOL_NULL_CHECK(ret, -EINVAL);\n+\n+    r = rand_gen(&t);\n+    SOL_INT_CHECK(r, < 0, r);\n+\n+    *ret = assert_uuid_v4(t);\n+    return 0;\n+}\n+\n+// 37 = 2 * 16 (chars) + 4 (hyphens) + 1 (\\0)\n+int\n+sol_util_uuid_gen(bool upcase,\n+    bool with_hyphens,\n+    char id[37])\n+{\n+    struct sol_str_slice hyphen = SOL_STR_SLICE_LITERAL(\"-\");\n+    /* hyphens on positions 8, 13, 18, 23 (from 0) */\n+    const int hyphens_pos[] = { 8, 13, 18, 23 };","path":"src/shared/sol-util-linux.c","position":101,"original_position":101,"commit_id":"d0989d87c93ed89ee8b2ad68ddb82bdbb1f47a41","original_commit_id":"d0989d87c93ed89ee8b2ad68ddb82bdbb1f47a41","user":{"login":"lpereira","id":15001,"avatar_url":"https://avatars.githubusercontent.com/u/15001?v=3","gravatar_id":"","url":"https://api.github.com/users/lpereira","html_url":"https://github.com/lpereira","followers_url":"https://api.github.com/users/lpereira/followers","following_url":"https://api.github.com/users/lpereira/following{/other_user}","gists_url":"https://api.github.com/users/lpereira/gists{/gist_id}","starred_url":"https://api.github.com/users/lpereira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpereira/subscriptions","organizations_url":"https://api.github.com/users/lpereira/orgs","repos_url":"https://api.github.com/users/lpereira/repos","events_url":"https://api.github.com/users/lpereira/events{/privacy}","received_events_url":"https://api.github.com/users/lpereira/received_events","type":"User","site_admin":false},"body":"static const","created_at":"2015-08-31T20:01:15Z","updated_at":"2015-08-31T20:01:15Z","html_url":"https://github.com/solettaproject/soletta/pull/656#discussion_r38352644","pull_request_url":"https://api.github.com/repos/solettaproject/soletta/pulls/656","_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/38352644"},"html":{"href":"https://github.com/solettaproject/soletta/pull/656#discussion_r38352644"},"pull_request":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/656"}}},"pull_request":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/656","id":43790621,"html_url":"https://github.com/solettaproject/soletta/pull/656","diff_url":"https://github.com/solettaproject/soletta/pull/656.diff","patch_url":"https://github.com/solettaproject/soletta/pull/656.patch","issue_url":"https://api.github.com/repos/solettaproject/soletta/issues/656","number":656,"state":"open","locked":false,"title":"Uuid [v2]","user":{"login":"glima","id":67689,"avatar_url":"https://avatars.githubusercontent.com/u/67689?v=3","gravatar_id":"","url":"https://api.github.com/users/glima","html_url":"https://github.com/glima","followers_url":"https://api.github.com/users/glima/followers","following_url":"https://api.github.com/users/glima/following{/other_user}","gists_url":"https://api.github.com/users/glima/gists{/gist_id}","starred_url":"https://api.github.com/users/glima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glima/subscriptions","organizations_url":"https://api.github.com/users/glima/orgs","repos_url":"https://api.github.com/users/glima/repos","events_url":"https://api.github.com/users/glima/events{/privacy}","received_events_url":"https://api.github.com/users/glima/received_events","type":"User","site_admin":false},"body":"Changes since #650 \r\n - Pass better flags to getrandom()\r\n - Use sol_buffer_append_printf() to generate uuid string\r\n - Accept an env var as machine id too (I'll work with Anselmo to test that on the bot)\r\n - sol_util_get_machine_id() moved to plaform headers, where other ID getters will land soon.","created_at":"2015-08-31T17:56:11Z","updated_at":"2015-08-31T20:01:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d0aa75b7926678489a64c0653af0fe5048df51f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/solettaproject/soletta/pulls/656/commits","review_comments_url":"https://api.github.com/repos/solettaproject/soletta/pulls/656/comments","review_comment_url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solettaproject/soletta/issues/656/comments","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/d0989d87c93ed89ee8b2ad68ddb82bdbb1f47a41","head":{"label":"glima:uuid","ref":"uuid","sha":"d0989d87c93ed89ee8b2ad68ddb82bdbb1f47a41","user":{"login":"glima","id":67689,"avatar_url":"https://avatars.githubusercontent.com/u/67689?v=3","gravatar_id":"","url":"https://api.github.com/users/glima","html_url":"https://github.com/glima","followers_url":"https://api.github.com/users/glima/followers","following_url":"https://api.github.com/users/glima/following{/other_user}","gists_url":"https://api.github.com/users/glima/gists{/gist_id}","starred_url":"https://api.github.com/users/glima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glima/subscriptions","organizations_url":"https://api.github.com/users/glima/orgs","repos_url":"https://api.github.com/users/glima/repos","events_url":"https://api.github.com/users/glima/events{/privacy}","received_events_url":"https://api.github.com/users/glima/received_events","type":"User","site_admin":false},"repo":{"id":37601201,"name":"soletta","full_name":"glima/soletta","owner":{"login":"glima","id":67689,"avatar_url":"https://avatars.githubusercontent.com/u/67689?v=3","gravatar_id":"","url":"https://api.github.com/users/glima","html_url":"https://github.com/glima","followers_url":"https://api.github.com/users/glima/followers","following_url":"https://api.github.com/users/glima/following{/other_user}","gists_url":"https://api.github.com/users/glima/gists{/gist_id}","starred_url":"https://api.github.com/users/glima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glima/subscriptions","organizations_url":"https://api.github.com/users/glima/orgs","repos_url":"https://api.github.com/users/glima/repos","events_url":"https://api.github.com/users/glima/events{/privacy}","received_events_url":"https://api.github.com/users/glima/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/glima/soletta","description":"Soletta Project is a framework for making IoT devices.","fork":true,"url":"https://api.github.com/repos/glima/soletta","forks_url":"https://api.github.com/repos/glima/soletta/forks","keys_url":"https://api.github.com/repos/glima/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/glima/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/glima/soletta/teams","hooks_url":"https://api.github.com/repos/glima/soletta/hooks","issue_events_url":"https://api.github.com/repos/glima/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/glima/soletta/events","assignees_url":"https://api.github.com/repos/glima/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/glima/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/glima/soletta/tags","blobs_url":"https://api.github.com/repos/glima/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/glima/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/glima/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/glima/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/glima/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/glima/soletta/languages","stargazers_url":"https://api.github.com/repos/glima/soletta/stargazers","contributors_url":"https://api.github.com/repos/glima/soletta/contributors","subscribers_url":"https://api.github.com/repos/glima/soletta/subscribers","subscription_url":"https://api.github.com/repos/glima/soletta/subscription","commits_url":"https://api.github.com/repos/glima/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/glima/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/glima/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/glima/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/glima/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/glima/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/glima/soletta/merges","archive_url":"https://api.github.com/repos/glima/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/glima/soletta/downloads","issues_url":"https://api.github.com/repos/glima/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/glima/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/glima/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/glima/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/glima/soletta/labels{/name}","releases_url":"https://api.github.com/repos/glima/soletta/releases{/id}","created_at":"2015-06-17T14:49:23Z","updated_at":"2015-06-17T14:49:24Z","pushed_at":"2015-08-31T17:53:50Z","git_url":"git://github.com/glima/soletta.git","ssh_url":"git@github.com:glima/soletta.git","clone_url":"https://github.com/glima/soletta.git","svn_url":"https://github.com/glima/soletta","homepage":"","size":3074,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"solettaproject:master","ref":"master","sha":"cdc150465b4b8104ec3857827227567574555445","user":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"repo":{"id":37087063,"name":"soletta","full_name":"solettaproject/soletta","owner":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solettaproject/soletta","description":"Soletta Project is a framework for making IoT devices.  With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.  ","fork":false,"url":"https://api.github.com/repos/solettaproject/soletta","forks_url":"https://api.github.com/repos/solettaproject/soletta/forks","keys_url":"https://api.github.com/repos/solettaproject/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solettaproject/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solettaproject/soletta/teams","hooks_url":"https://api.github.com/repos/solettaproject/soletta/hooks","issue_events_url":"https://api.github.com/repos/solettaproject/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/solettaproject/soletta/events","assignees_url":"https://api.github.com/repos/solettaproject/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/solettaproject/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/solettaproject/soletta/tags","blobs_url":"https://api.github.com/repos/solettaproject/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solettaproject/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solettaproject/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/solettaproject/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/solettaproject/soletta/languages","stargazers_url":"https://api.github.com/repos/solettaproject/soletta/stargazers","contributors_url":"https://api.github.com/repos/solettaproject/soletta/contributors","subscribers_url":"https://api.github.com/repos/solettaproject/soletta/subscribers","subscription_url":"https://api.github.com/repos/solettaproject/soletta/subscription","commits_url":"https://api.github.com/repos/solettaproject/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/solettaproject/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/solettaproject/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/solettaproject/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/solettaproject/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/solettaproject/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solettaproject/soletta/merges","archive_url":"https://api.github.com/repos/solettaproject/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solettaproject/soletta/downloads","issues_url":"https://api.github.com/repos/solettaproject/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/solettaproject/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/solettaproject/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/solettaproject/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solettaproject/soletta/labels{/name}","releases_url":"https://api.github.com/repos/solettaproject/soletta/releases{/id}","created_at":"2015-06-08T19:13:18Z","updated_at":"2015-07-12T18:54:34Z","pushed_at":"2015-08-31T19:14:16Z","git_url":"git://github.com/solettaproject/soletta.git","ssh_url":"git@github.com:solettaproject/soletta.git","clone_url":"https://github.com/solettaproject/soletta.git","svn_url":"https://github.com/solettaproject/soletta","homepage":"","size":8728,"stargazers_count":39,"watchers_count":39,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":25,"forks":31,"open_issues":25,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/656"},"html":{"href":"https://github.com/solettaproject/soletta/pull/656"},"issue":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/656"},"comments":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/656/comments"},"review_comments":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/656/comments"},"review_comment":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/656/commits"},"statuses":{"href":"https://api.github.com/repos/solettaproject/soletta/statuses/d0989d87c93ed89ee8b2ad68ddb82bdbb1f47a41"}}}}