-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a random UUID on startup, store and read from bootid
Fixes #1166
- Loading branch information
Showing
8 changed files
with
47 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "utils/uuid.h" | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
// https://stackoverflow.com/a/71826534 | ||
void uuid4_generate(char *uuid) { | ||
srand(time(NULL)); | ||
|
||
char v[] = {'0', '1', '2', '3', '4', '5', '6', '7', | ||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
for (int i = 0; i < 36; ++i) { | ||
uuid[i] = v[rand() % 16]; | ||
} | ||
|
||
uuid[8] = '-'; | ||
uuid[13] = '-'; | ||
uuid[18] = '-'; | ||
uuid[23] = '-'; | ||
uuid[36] = '\0'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef UUID_H | ||
#define UUID_H | ||
#define _GNU_SOURCE | ||
|
||
#define UUID_STR_LEN 37 | ||
|
||
void uuid4_generate(char *uuid); | ||
|
||
#endif // UUID_H |