#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
-#include <sys/wait.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
#include <sys/syscall.h>
#endif
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
#include "uuidP.h"
#include "uuidd.h"
#include "randutils.h"
-#include "fileutils.h"
#ifdef HAVE_TLS
#define THREAD_LOCAL static __thread
return c;
}
-/*
- * Close all file descriptors
- */
-static void close_all_fds(void)
-{
- int i, max = get_fd_tabsize();
-
- for (i=0; i < max; i++) {
- close(i);
- if (i <= 2)
- open("/dev/null", O_RDWR);
- }
-}
-
/*
* Try using the uuidd daemon to generate the UUID
*
ssize_t ret;
int32_t reply_len = 0, expected = 16;
struct sockaddr_un srv_addr;
- struct stat st;
- pid_t pid;
- static const char *uuidd_path = UUIDD_PATH;
- static int access_ret = -2;
- static int start_attempts = 0;
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
return -1;
strcpy(srv_addr.sun_path, UUIDD_SOCKET_PATH);
if (connect(s, (const struct sockaddr *) &srv_addr,
- sizeof(struct sockaddr_un)) < 0) {
- if (access_ret == -2)
- access_ret = access(uuidd_path, X_OK);
- if (access_ret == 0)
- access_ret = stat(uuidd_path, &st);
- if (access_ret == 0 && (st.st_mode & (S_ISUID | S_ISGID)) == 0)
- access_ret = access(UUIDD_DIR, W_OK);
- if (access_ret == 0 && start_attempts++ < 5) {
- if ((pid = fork()) == 0) {
- close_all_fds();
- execl(uuidd_path, "uuidd", "-qT", "300",
- (char *) NULL);
- exit(EXIT_FAILURE);
- }
- (void) waitpid(pid, 0, 0);
- if (connect(s, (const struct sockaddr *) &srv_addr,
- sizeof(struct sockaddr_un)) < 0)
- goto fail;
- } else
- goto fail;
- }
+ sizeof(struct sockaddr_un)) < 0)
+ goto fail;
+
op_buf[0] = op;
op_len = 1;
if (op == UUIDD_OP_BULK_TIME_UUID) {