2 * uuidd.c --- UUID-generation daemon
4 * Copyright (C) 2007 Theodore Ts'o
7 * This file may be redistributed under the terms of the GNU Public
16 * | operation type (1 byte) | number of uuids (if bulk request, 4 bytes) |
19 * | reply length (4 bytes) | uuid reply (16 bytes) |
21 * | reply length (4 bytes) | uuid reply (16 bytes) multiply by number when random bulk request |
23 * | reply length (4 bytes) | uuid reply (16 bytes) | number (4 bytes) time bulk |
25 * | reply length (4 bytes) | pid or maxop number string length in ascii (up to 7 bytes) |
34 #include <sys/types.h>
36 #include <sys/socket.h>
42 #include <sys/signalfd.h>
49 #include "closestream.h"
52 #include "monotonic.h"
55 #ifdef HAVE_LIBSYSTEMD
56 # include <systemd/sd-daemon.h>
61 /* Protocol segment lengths */
62 typedef uint8_t uuidd_prot_op_t
; /* client operation field */
63 typedef int32_t uuidd_prot_num_t
; /* number of requested uuids */
66 /* client - server buffer size */
67 UUIDD_PROT_BUFSZ
= ((sizeof(uuidd_prot_num_t
)) + (sizeof(uuid_t
) * 63))
70 /* server loop control structure */
72 const char *cleanup_pidfile
;
73 const char *cleanup_socket
;
75 uint32_t cont_clock_offset
;
77 unsigned int debug
: 1,
83 struct uuidd_options_t
{
84 const char *pidfile_path
;
85 const char *socket_path
;
87 uuidd_prot_op_t do_type
;
88 unsigned int do_kill
:1,
93 static void __attribute__((__noreturn__
)) usage(void)
96 fputs(USAGE_HEADER
, out
);
97 fprintf(out
, _(" %s [options]\n"), program_invocation_short_name
);
98 fputs(USAGE_SEPARATOR
, out
);
99 fputs(_("A daemon for generating UUIDs.\n"), out
);
100 fputs(USAGE_OPTIONS
, out
);
101 fputs(_(" -p, --pid <path> path to pid file\n"), out
);
102 fputs(_(" -s, --socket <path> path to socket\n"), out
);
103 fputs(_(" -T, --timeout <sec> specify inactivity timeout\n"), out
);
104 fputs(_(" -k, --kill kill running daemon\n"), out
);
105 fputs(_(" -r, --random test random-based generation\n"), out
);
106 fputs(_(" -t, --time test time-based generation\n"), out
);
107 fputs(_(" -n, --uuids <num> request number of uuids\n"), out
);
108 fputs(_(" -P, --no-pid do not create pid file\n"), out
);
109 fputs(_(" -F, --no-fork do not daemonize using double-fork\n"), out
);
110 fputs(_(" -S, --socket-activation do not create listening socket\n"), out
);
111 fputs(_(" -C, --cont-clock[=<NUM>[hd]]\n"), out
);
112 fputs(_(" activate continuous clock handling\n"), out
);
113 fputs(_(" -d, --debug run in debugging mode\n"), out
);
114 fputs(_(" -q, --quiet turn on quiet mode\n"), out
);
115 fputs(USAGE_SEPARATOR
, out
);
116 fprintf(out
, USAGE_HELP_OPTIONS(25));
117 fprintf(out
, USAGE_MAN_TAIL("uuidd(8)"));
121 static void create_daemon(void)
126 err(EXIT_FAILURE
, "daemon");
129 if (setreuid(euid
, euid
) < 0)
130 err(EXIT_FAILURE
, "setreuid");
133 static int call_daemon(const char *socket_path
, uuidd_prot_op_t op
, char *buf
,
134 size_t buflen
, uuidd_prot_num_t
*num
, const char **err_context
)
136 char op_buf
[sizeof(op
) + sizeof(*num
)];
140 int32_t reply_len
= 0;
141 struct sockaddr_un srv_addr
;
143 if (((op
== UUIDD_OP_BULK_TIME_UUID
) ||
144 (op
== UUIDD_OP_BULK_RANDOM_UUID
)) && !num
) {
146 *err_context
= _("bad arguments");
151 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) < 0) {
153 *err_context
= _("socket");
157 srv_addr
.sun_family
= AF_UNIX
;
158 assert(strlen(socket_path
) < sizeof(srv_addr
.sun_path
));
159 xstrncpy(srv_addr
.sun_path
, socket_path
, sizeof(srv_addr
.sun_path
));
161 if (connect(s
, (const struct sockaddr
*) &srv_addr
,
162 sizeof(struct sockaddr_un
)) < 0) {
164 *err_context
= _("connect");
169 if (op
== UUIDD_OP_BULK_RANDOM_UUID
) {
170 if ((buflen
- sizeof(*num
)) < (size_t)((*num
) * sizeof(uuid_t
)))
171 *num
= (buflen
- sizeof(*num
)) / sizeof(uuid_t
);
175 if ((op
== UUIDD_OP_BULK_TIME_UUID
) ||
176 (op
== UUIDD_OP_BULK_RANDOM_UUID
)) {
177 memcpy(op_buf
+ sizeof(op
), num
, sizeof(*num
));
178 op_len
+= sizeof(*num
);
181 ret
= write_all(s
, op_buf
, op_len
);
184 *err_context
= _("write");
189 ret
= read_all(s
, (char *) &reply_len
, sizeof(reply_len
));
192 *err_context
= _("read count");
196 if (reply_len
< 0 || (size_t) reply_len
> buflen
) {
198 *err_context
= _("bad response length");
202 ret
= read_all(s
, (char *) buf
, reply_len
);
204 if ((ret
> 0) && (op
== UUIDD_OP_BULK_TIME_UUID
)) {
205 if ((sizeof(uuid_t
) + sizeof(*num
)) <= (size_t) reply_len
)
206 memcpy(buf
+ sizeof(uuid_t
), num
, sizeof(*num
));
210 if ((ret
> 0) && (op
== UUIDD_OP_BULK_RANDOM_UUID
)) {
211 if (sizeof(*num
) <= (size_t) reply_len
)
212 memcpy(buf
, num
, sizeof(*num
));
223 * Exclusively create and open a pid file with path @pidfile_path
225 * Return file descriptor of the created pid_file.
227 static int create_pidfile(struct uuidd_cxt_t
*cxt
, const char *pidfile_path
)
232 fd_pidfile
= open(pidfile_path
, O_CREAT
| O_RDWR
, 0664);
233 if (fd_pidfile
< 0) {
235 warn(_("cannot open %s"), pidfile_path
);
238 cxt
->cleanup_pidfile
= pidfile_path
;
241 fl
.l_whence
= SEEK_SET
;
245 while (fcntl(fd_pidfile
, F_SETLKW
, &fl
) < 0) {
246 if ((errno
== EAGAIN
) || (errno
== EINTR
))
249 warn(_("cannot lock %s"), pidfile_path
);
257 * Create AF_UNIX, SOCK_STREAM socket and bind to @socket_path
259 * If @will_fork is true, then make sure the descriptor
260 * of the socket is >2, so that it won't be later closed
261 * during create_daemon().
263 * Return file descriptor corresponding to created socket.
265 static int create_socket(struct uuidd_cxt_t
*uuidd_cxt
,
266 const char *socket_path
, int will_fork
)
268 struct sockaddr_un my_addr
;
272 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) < 0) {
273 if (!uuidd_cxt
->quiet
)
274 warn(_("couldn't create unix stream socket"));
279 * Make sure the socket isn't using fd numbers 0-2 to avoid it
280 * getting closed by create_daemon()
282 while (will_fork
&& s
<= 2) {
285 err(EXIT_FAILURE
, "dup");
289 * Create the address we will be binding to.
291 my_addr
.sun_family
= AF_UNIX
;
292 assert(strlen(socket_path
) < sizeof(my_addr
.sun_path
));
293 xstrncpy(my_addr
.sun_path
, socket_path
, sizeof(my_addr
.sun_path
));
295 save_umask
= umask(0);
296 if (bind(s
, (const struct sockaddr
*) &my_addr
,
297 sizeof(struct sockaddr_un
)) < 0) {
298 if (!uuidd_cxt
->quiet
)
299 warn(_("couldn't bind unix socket %s"), socket_path
);
303 uuidd_cxt
->cleanup_socket
= socket_path
;
308 static void __attribute__((__noreturn__
)) all_done(const struct uuidd_cxt_t
*uuidd_cxt
, int ret
)
310 if (uuidd_cxt
->cleanup_pidfile
)
311 unlink(uuidd_cxt
->cleanup_pidfile
);
312 if (uuidd_cxt
->cleanup_socket
)
313 unlink(uuidd_cxt
->cleanup_socket
);
317 static void handle_signal(const struct uuidd_cxt_t
*uuidd_cxt
, int fd
)
319 struct signalfd_siginfo info
;
322 bytes
= read(fd
, &info
, sizeof(info
));
323 if (bytes
!= sizeof(info
)) {
326 warn(_("receiving signal failed"));
329 if (info
.ssi_signo
== SIGPIPE
)
330 return; /* ignored */
331 all_done(uuidd_cxt
, EXIT_SUCCESS
);
334 static void timeout_handler(int sig
__attribute__((__unused__
)),
336 void *context
__attribute__((__unused__
)))
338 #ifdef HAVE_TIMER_CREATE
339 if (info
->si_code
== SI_TIMER
)
341 errx(EXIT_FAILURE
, _("timed out"));
344 static void server_loop(const char *socket_path
, const char *pidfile_path
,
345 struct uuidd_cxt_t
*uuidd_cxt
)
347 struct sockaddr_un from_addr
;
349 int32_t reply_len
= 0;
351 char reply_buf
[UUIDD_PROT_BUFSZ
], *cp
;
353 char str
[UUID_STR_LEN
];
355 uuidd_prot_num_t num
; /* intentionally uninitialized */
359 struct pollfd pfd
[2];
367 #ifdef HAVE_LIBSYSTEMD
368 if (!uuidd_cxt
->no_sock
) /* no_sock implies no_fork and no_pid */
371 struct ul_timer timer
;
372 struct itimerval timeout
;
374 memset(&timeout
, 0, sizeof timeout
);
375 timeout
.it_value
.tv_sec
= 30;
376 if (setup_timer(&timer
, &timeout
, &timeout_handler
))
377 err(EXIT_FAILURE
, _("cannot set up timer"));
379 fd_pidfile
= create_pidfile(uuidd_cxt
, pidfile_path
);
380 ret
= call_daemon(socket_path
, UUIDD_OP_GETPID
, reply_buf
,
381 sizeof(reply_buf
), 0, NULL
);
382 cancel_timer(&timer
);
384 if (!uuidd_cxt
->quiet
)
385 warnx(_("uuidd daemon is already running at pid %s"),
390 s
= create_socket(uuidd_cxt
, socket_path
,
391 (!uuidd_cxt
->debug
|| !uuidd_cxt
->no_fork
));
392 if (listen(s
, SOMAXCONN
) < 0) {
393 if (!uuidd_cxt
->quiet
)
394 warn(_("couldn't listen on unix socket %s"), socket_path
);
398 if (!uuidd_cxt
->debug
&& !uuidd_cxt
->no_fork
)
402 snprintf(reply_buf
, sizeof(reply_buf
), "%8d\n", getpid());
403 if (ftruncate(fd_pidfile
, 0))
404 err(EXIT_FAILURE
, _("could not truncate file: %s"), pidfile_path
);
405 write_all(fd_pidfile
, reply_buf
, strlen(reply_buf
));
406 if (fd_pidfile
> 1 && close_fd(fd_pidfile
) != 0)
407 err(EXIT_FAILURE
, _("write failed: %s"), pidfile_path
);
412 #ifdef HAVE_LIBSYSTEMD
413 if (uuidd_cxt
->no_sock
) {
414 const int r
= sd_listen_fds(0);
418 err(EXIT_FAILURE
, _("sd_listen_fds() failed"));
421 _("no file descriptors received, check systemctl status uuidd.socket"));
424 _("too many file descriptors received, check uuidd.socket"));
425 s
= SD_LISTEN_FDS_START
+ 0;
429 sigemptyset(&sigmask
);
430 sigaddset(&sigmask
, SIGHUP
);
431 sigaddset(&sigmask
, SIGINT
);
432 sigaddset(&sigmask
, SIGTERM
);
433 sigaddset(&sigmask
, SIGALRM
);
434 sigaddset(&sigmask
, SIGPIPE
);
435 /* Block signals so that they aren't handled according to their
436 * default dispositions */
437 sigprocmask(SIG_BLOCK
, &sigmask
, NULL
);
438 if ((sigfd
= signalfd(-1, &sigmask
, 0)) < 0)
439 err(EXIT_FAILURE
, _("cannot set signal handler"));
441 pfd
[POLLFD_SIGNAL
].fd
= sigfd
;
442 pfd
[POLLFD_SOCKET
].fd
= s
;
443 pfd
[POLLFD_SIGNAL
].events
= pfd
[POLLFD_SOCKET
].events
= POLLIN
| POLLERR
| POLLHUP
;
446 if (uuidd_cxt
->cont_clock_offset
) {
447 /* trigger initialization */
448 (void) __uuid_generate_time_cont(uu
, &num
, uuidd_cxt
->cont_clock_offset
);
449 if (uuidd_cxt
->debug
)
450 fprintf(stderr
, _("max_clock_offset = %u sec\n"),
451 uuidd_cxt
->cont_clock_offset
);
455 ret
= poll(pfd
, ARRAY_SIZE(pfd
),
457 (int) uuidd_cxt
->timeout
* 1000 : -1);
461 warn(_("poll failed"));
462 all_done(uuidd_cxt
, EXIT_FAILURE
);
464 if (ret
== 0) { /* true when poll() times out */
465 if (uuidd_cxt
->debug
)
466 fprintf(stderr
, _("timeout [%d sec]\n"), uuidd_cxt
->timeout
);
467 all_done(uuidd_cxt
, EXIT_SUCCESS
);
469 if (pfd
[POLLFD_SIGNAL
].revents
!= 0)
470 handle_signal(uuidd_cxt
, sigfd
);
471 if (pfd
[POLLFD_SOCKET
].revents
== 0)
473 fromlen
= sizeof(from_addr
);
474 ns
= accept(s
, (struct sockaddr
*) &from_addr
, &fromlen
);
476 if ((errno
== EAGAIN
) || (errno
== EINTR
))
478 err(EXIT_FAILURE
, "accept");
480 len
= read(ns
, &op
, sizeof(op
));
481 if (len
!= sizeof(op
)) {
483 warn(_("read failed"));
485 warnx(_("error reading from client, len = %d"),
487 goto shutdown_socket
;
489 if ((op
== UUIDD_OP_BULK_TIME_UUID
) ||
490 (op
== UUIDD_OP_BULK_RANDOM_UUID
)) {
491 if (read_all(ns
, (char *) &num
, sizeof(num
)) != sizeof(num
))
492 goto shutdown_socket
;
493 if (uuidd_cxt
->debug
)
494 fprintf(stderr
, _("operation %d, incoming num = %d\n"),
496 } else if (uuidd_cxt
->debug
)
497 fprintf(stderr
, _("operation %d\n"), op
);
500 case UUIDD_OP_GETPID
:
501 snprintf(reply_buf
, sizeof(reply_buf
), "%d", getpid());
502 reply_len
= strlen(reply_buf
) + 1;
504 case UUIDD_OP_GET_MAXOP
:
505 snprintf(reply_buf
, sizeof(reply_buf
), "%d", UUIDD_MAX_OP
);
506 reply_len
= strlen(reply_buf
) + 1;
508 case UUIDD_OP_TIME_UUID
:
510 ret
= __uuid_generate_time_cont(uu
, &num
, uuidd_cxt
->cont_clock_offset
);
511 if (ret
< 0 && !uuidd_cxt
->quiet
)
512 warnx(_("failed to open/lock clock counter"));
513 if (uuidd_cxt
->debug
) {
514 uuid_unparse(uu
, str
);
515 fprintf(stderr
, _("Generated time UUID: %s\n"), str
);
517 memcpy(reply_buf
, uu
, sizeof(uu
));
518 reply_len
= sizeof(uu
);
520 case UUIDD_OP_RANDOM_UUID
:
522 __uuid_generate_random(uu
, &num
);
523 if (uuidd_cxt
->debug
) {
524 uuid_unparse(uu
, str
);
525 fprintf(stderr
, _("Generated random UUID: %s\n"), str
);
527 memcpy(reply_buf
, uu
, sizeof(uu
));
528 reply_len
= sizeof(uu
);
530 case UUIDD_OP_BULK_TIME_UUID
:
531 ret
= __uuid_generate_time_cont(uu
, &num
, uuidd_cxt
->cont_clock_offset
);
532 if (ret
< 0 && !uuidd_cxt
->quiet
)
533 warnx(_("failed to open/lock clock counter"));
534 if (uuidd_cxt
->debug
) {
535 uuid_unparse(uu
, str
);
536 fprintf(stderr
, P_("Generated time UUID %s "
537 "and %d following\n",
538 "Generated time UUID %s "
539 "and %d following\n", num
- 1),
542 memcpy(reply_buf
, uu
, sizeof(uu
));
543 reply_len
= sizeof(uu
);
544 memcpy(reply_buf
+ reply_len
, &num
, sizeof(num
));
545 reply_len
+= sizeof(num
);
547 case UUIDD_OP_BULK_RANDOM_UUID
:
550 if ((sizeof(reply_buf
) - sizeof(num
)) < (size_t) (sizeof(uu
) * num
))
551 num
= (sizeof(reply_buf
) - sizeof(num
)) / sizeof(uu
);
552 __uuid_generate_random((unsigned char *) reply_buf
+
554 reply_len
= sizeof(num
) + (sizeof(uu
) * num
);
555 memcpy(reply_buf
, &num
, sizeof(num
));
556 if (uuidd_cxt
->debug
) {
557 fprintf(stderr
, P_("Generated %d UUID:\n",
558 "Generated %d UUIDs:\n", num
), num
);
559 cp
= reply_buf
+ sizeof(num
);
560 for (i
= 0; i
< num
; i
++) {
561 uuid_unparse((unsigned char *)cp
, str
);
562 fprintf(stderr
, "\t%s\n", str
);
568 if (uuidd_cxt
->debug
)
569 fprintf(stderr
, _("Invalid operation %d\n"), op
);
570 goto shutdown_socket
;
572 write_all(ns
, (char *) &reply_len
, sizeof(num
));
573 write_all(ns
, reply_buf
, reply_len
);
579 static void __attribute__ ((__noreturn__
)) unexpected_size(int size
)
581 errx(EXIT_FAILURE
, _("Unexpected reply length from server %d"), size
);
584 static uint32_t parse_cont_clock(char *arg
)
586 uint32_t min_val
= 60,
587 max_val
= (3600 * 24 * 365),
589 char *p
= &arg
[strlen(arg
)-1];
601 return factor
* str2num_or_err(optarg
, 10, _("failed to parse --cont-clock/-C"),
602 min_val
, max_val
/ factor
);
605 static void parse_options(int argc
, char **argv
, struct uuidd_cxt_t
*uuidd_cxt
,
606 struct uuidd_options_t
*uuidd_opts
)
608 const struct option longopts
[] = {
609 {"pid", required_argument
, NULL
, 'p'},
610 {"socket", required_argument
, NULL
, 's'},
611 {"timeout", required_argument
, NULL
, 'T'},
612 {"kill", no_argument
, NULL
, 'k'},
613 {"random", no_argument
, NULL
, 'r'},
614 {"time", no_argument
, NULL
, 't'},
615 {"uuids", required_argument
, NULL
, 'n'},
616 {"no-pid", no_argument
, NULL
, 'P'},
617 {"no-fork", no_argument
, NULL
, 'F'},
618 {"socket-activation", no_argument
, NULL
, 'S'},
619 {"cont-clock", optional_argument
, NULL
, 'C'},
620 {"debug", no_argument
, NULL
, 'd'},
621 {"quiet", no_argument
, NULL
, 'q'},
622 {"version", no_argument
, NULL
, 'V'},
623 {"help", no_argument
, NULL
, 'h'},
626 const ul_excl_t excl
[] = {
632 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
635 while ((c
= getopt_long(argc
, argv
, "p:s:T:krtn:PFSC::dqVh", longopts
, NULL
)) != -1) {
636 err_exclusive_options(c
, longopts
, excl
, excl_st
);
640 uuidd_cxt
->cont_clock_offset
= parse_cont_clock(optarg
);
642 uuidd_cxt
->cont_clock_offset
= 7200; /* default 2h */
645 uuidd_cxt
->debug
= 1;
648 uuidd_opts
->do_kill
= 1;
651 uuidd_opts
->num
= (uuidd_prot_num_t
) strtou16_or_err(optarg
,
652 _("failed to parse --uuids"));
655 uuidd_opts
->pidfile_path
= optarg
;
658 uuidd_opts
->no_pid
= 1;
661 uuidd_cxt
->no_fork
= 1;
664 #ifdef HAVE_LIBSYSTEMD
665 uuidd_cxt
->no_sock
= 1;
666 uuidd_cxt
->no_fork
= 1;
667 uuidd_opts
->no_pid
= 1;
669 errx(EXIT_FAILURE
, _("uuidd has been built without "
670 "support for socket activation"));
674 uuidd_cxt
->quiet
= 1;
677 uuidd_opts
->do_type
= UUIDD_OP_RANDOM_UUID
;
680 uuidd_opts
->socket_path
= optarg
;
681 uuidd_opts
->s_flag
= 1;
684 uuidd_opts
->do_type
= UUIDD_OP_TIME_UUID
;
687 uuidd_cxt
->timeout
= strtou32_or_err(optarg
,
688 _("failed to parse --timeout"));
692 print_version(EXIT_SUCCESS
);
696 errtryhelp(EXIT_FAILURE
);
700 if (0 < uuidd_opts
->num
) {
701 switch (uuidd_opts
->do_type
) {
702 case UUIDD_OP_RANDOM_UUID
:
703 uuidd_opts
->do_type
= UUIDD_OP_BULK_RANDOM_UUID
;
705 case UUIDD_OP_TIME_UUID
:
706 uuidd_opts
->do_type
= UUIDD_OP_BULK_TIME_UUID
;
712 int main(int argc
, char **argv
)
714 const char *err_context
= NULL
;
718 struct uuidd_cxt_t uuidd_cxt
= { .timeout
= 0, .cont_clock_offset
= 0 };
719 struct uuidd_options_t uuidd_opts
= { .socket_path
= UUIDD_SOCKET_PATH
};
721 setlocale(LC_ALL
, "");
722 bindtextdomain(PACKAGE
, LOCALEDIR
);
724 close_stdout_atexit();
726 parse_options(argc
, argv
, &uuidd_cxt
, &uuidd_opts
);
728 if (strlen(uuidd_opts
.socket_path
) >= sizeof_member(struct sockaddr_un
, sun_path
))
729 errx(EXIT_FAILURE
, _("socket name too long: %s"), uuidd_opts
.socket_path
);
731 if (!uuidd_opts
.no_pid
&& !uuidd_opts
.pidfile_path
)
732 uuidd_opts
.pidfile_path
= UUIDD_PIDFILE_PATH
;
734 /* custom socket path and socket-activation make no sense */
735 if (uuidd_opts
.s_flag
&& uuidd_cxt
.no_sock
&& !uuidd_cxt
.quiet
)
736 warnx(_("Both --socket-activation and --socket specified. "
737 "Ignoring --socket."));
739 if (uuidd_opts
.num
&& uuidd_opts
.do_type
) {
740 char buf
[UUIDD_PROT_BUFSZ
];
741 char str
[UUID_STR_LEN
];
743 ret
= call_daemon(uuidd_opts
.socket_path
, uuidd_opts
.do_type
, buf
,
744 sizeof(buf
), &uuidd_opts
.num
, &err_context
);
747 err(EXIT_FAILURE
, _("error calling uuidd daemon (%s)"),
748 err_context
? : _("unexpected error"));
750 if (uuidd_opts
.do_type
== UUIDD_OP_BULK_TIME_UUID
) {
751 if (ret
!= sizeof(uuid_t
) + sizeof(uuidd_opts
.num
))
752 unexpected_size(ret
);
754 uuid_unparse((unsigned char *) buf
, str
);
756 printf(P_("%s and %d subsequent UUID\n",
757 "%s and %d subsequent UUIDs\n", uuidd_opts
.num
- 1),
758 str
, uuidd_opts
.num
- 1);
762 printf(_("List of UUIDs:\n"));
763 cp
= buf
+ sizeof(uuidd_opts
.num
);
764 if (ret
!= (int) (sizeof(uuidd_opts
.num
) + uuidd_opts
.num
* sizeof(uuid_t
)))
765 unexpected_size(ret
);
766 for (i
= 0; i
< uuidd_opts
.num
; i
++, cp
+= sizeof(uuid_t
)) {
767 uuid_unparse((unsigned char *) cp
, str
);
768 printf("\t%s\n", str
);
774 if (uuidd_opts
.do_type
) {
776 char str
[UUID_STR_LEN
];
778 ret
= call_daemon(uuidd_opts
.socket_path
, uuidd_opts
.do_type
, (char *) &uu
,
779 sizeof(uu
), 0, &err_context
);
782 err(EXIT_FAILURE
, _("error calling uuidd daemon (%s)"),
783 err_context
? : _("unexpected error"));
784 if (ret
!= sizeof(uu
))
785 unexpected_size(ret
);
787 uuid_unparse(uu
, str
);
793 if (uuidd_opts
.do_kill
) {
796 ret
= call_daemon(uuidd_opts
.socket_path
, UUIDD_OP_GETPID
, buf
, sizeof(buf
), 0, NULL
);
800 pid
= (pid_t
)strtou32_or_err(buf
, _("failed to parse pid"));
801 ret
= kill(pid
, SIGTERM
);
803 if (!uuidd_cxt
.quiet
)
804 warn(_("couldn't kill uuidd running "
808 if (!uuidd_cxt
.quiet
)
809 printf(_("Killed uuidd running at pid %d.\n"), pid
);
814 server_loop(uuidd_opts
.socket_path
, uuidd_opts
.pidfile_path
, &uuidd_cxt
);