mirror of https://github.com/D4-project/d4-core
Generate an UUID if no one was set
parent
423261613b
commit
6843c61ba0
|
@ -1,2 +1,2 @@
|
||||||
d4: d4.c
|
d4: d4.c
|
||||||
gcc -Wall -o d4 d4.c
|
gcc -Wall -o d4 d4.c -luuid
|
||||||
|
|
42
client/d4.c
42
client/d4.c
|
@ -9,8 +9,47 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <uuid/uuid.h>
|
||||||
#include "d4.h"
|
#include "d4.h"
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generate a uuid if no one was set
|
||||||
|
*/
|
||||||
|
void d4_update_uuid(d4_t* d4)
|
||||||
|
{
|
||||||
|
uuid_t uuid;
|
||||||
|
int fd,ret;
|
||||||
|
char* filename;
|
||||||
|
char* uuid_text;
|
||||||
|
|
||||||
|
if (d4->conf[UUID][0] == 0){
|
||||||
|
uuid_generate(uuid);
|
||||||
|
memcpy(&(d4->header.uuid), uuid, SZUUID);
|
||||||
|
filename = calloc(1,2*FILENAME_MAX);
|
||||||
|
uuid_text = calloc(1, SZUUID_TEXT);
|
||||||
|
if ((filename != NULL) && (uuid != NULL)) {
|
||||||
|
snprintf(filename, 2*FILENAME_MAX, "%s/%s",d4->confdir, d4params[UUID]);
|
||||||
|
fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR |S_IWUSR);
|
||||||
|
if (fd > 0) {
|
||||||
|
uuid_unparse(uuid, uuid_text);
|
||||||
|
ret = write(fd, uuid_text, SZUUID_TEXT-1);
|
||||||
|
if (ret < 0) {
|
||||||
|
d4->errno_copy = errno;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
} else {
|
||||||
|
// Cannot open file
|
||||||
|
d4->errno_copy = errno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* If there is an error the uuid is not stored and a new one is
|
||||||
|
* generated for the next boot
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int d4_check_config(d4_t* d4)
|
int d4_check_config(d4_t* d4)
|
||||||
{
|
{
|
||||||
// TODO implement other sources, file, fifo, unix_socket ...
|
// TODO implement other sources, file, fifo, unix_socket ...
|
||||||
|
@ -27,6 +66,9 @@ int d4_check_config(d4_t* d4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d4->snaplen = atoi(d4->conf[SNAPLEN]);
|
d4->snaplen = atoi(d4->conf[SNAPLEN]);
|
||||||
|
|
||||||
|
d4_update_uuid(d4);
|
||||||
|
|
||||||
if ((d4->snaplen < 0) || (d4->snaplen > MAXSNAPLEN)) {
|
if ((d4->snaplen < 0) || (d4->snaplen > MAXSNAPLEN)) {
|
||||||
d4->snaplen = 0;
|
d4->snaplen = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#define STDOUT "stdout"
|
#define STDOUT "stdout"
|
||||||
#define MAXSNAPLEN 65535
|
#define MAXSNAPLEN 65535
|
||||||
#define SZUUID 128
|
#define SZUUID 128
|
||||||
|
#define SZUUID_TEXT 37
|
||||||
#define INSERT_ERROR(...) do { \
|
#define INSERT_ERROR(...) do { \
|
||||||
if (d4->err_idx < NERRORS) \
|
if (d4->err_idx < NERRORS) \
|
||||||
snprintf(d4->errors[d4->err_idx],SZERRVALUE,__VA_ARGS__); \
|
snprintf(d4->errors[d4->err_idx],SZERRVALUE,__VA_ARGS__); \
|
||||||
|
|
Loading…
Reference in New Issue