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 ret
= poll(pfd
, ARRAY_SIZE(pfd
),
448 (int) uuidd_cxt
->timeout
* 1000 : -1);
452 warn(_("poll failed"));
453 all_done(uuidd_cxt
, EXIT_FAILURE
);
455 if (ret
== 0) { /* true when poll() times out */
456 if (uuidd_cxt
->debug
)
457 fprintf(stderr
, _("timeout [%d sec]\n"), uuidd_cxt
->timeout
);
458 all_done(uuidd_cxt
, EXIT_SUCCESS
);
460 if (pfd
[POLLFD_SIGNAL
].revents
!= 0)
461 handle_signal(uuidd_cxt
, sigfd
);
462 if (pfd
[POLLFD_SOCKET
].revents
== 0)
464 fromlen
= sizeof(from_addr
);
465 ns
= accept(s
, (struct sockaddr
*) &from_addr
, &fromlen
);
467 if ((errno
== EAGAIN
) || (errno
== EINTR
))
469 err(EXIT_FAILURE
, "accept");
471 len
= read(ns
, &op
, sizeof(op
));
472 if (len
!= sizeof(op
)) {
474 warn(_("read failed"));
476 warnx(_("error reading from client, len = %d"),
478 goto shutdown_socket
;
480 if ((op
== UUIDD_OP_BULK_TIME_UUID
) ||
481 (op
== UUIDD_OP_BULK_RANDOM_UUID
)) {
482 if (read_all(ns
, (char *) &num
, sizeof(num
)) != sizeof(num
))
483 goto shutdown_socket
;
484 if (uuidd_cxt
->debug
)
485 fprintf(stderr
, _("operation %d, incoming num = %d\n"),
487 } else if (uuidd_cxt
->debug
)
488 fprintf(stderr
, _("operation %d\n"), op
);
491 case UUIDD_OP_GETPID
:
492 snprintf(reply_buf
, sizeof(reply_buf
), "%d", getpid());
493 reply_len
= strlen(reply_buf
) + 1;
495 case UUIDD_OP_GET_MAXOP
:
496 snprintf(reply_buf
, sizeof(reply_buf
), "%d", UUIDD_MAX_OP
);
497 reply_len
= strlen(reply_buf
) + 1;
499 case UUIDD_OP_TIME_UUID
:
501 ret
= __uuid_generate_time_cont(uu
, &num
, uuidd_cxt
->cont_clock_offset
);
502 if (ret
< 0 && !uuidd_cxt
->quiet
)
503 warnx(_("failed to open/lock clock counter"));
504 if (uuidd_cxt
->debug
) {
505 uuid_unparse(uu
, str
);
506 fprintf(stderr
, _("Generated time UUID: %s\n"), str
);
508 memcpy(reply_buf
, uu
, sizeof(uu
));
509 reply_len
= sizeof(uu
);
511 case UUIDD_OP_RANDOM_UUID
:
513 __uuid_generate_random(uu
, &num
);
514 if (uuidd_cxt
->debug
) {
515 uuid_unparse(uu
, str
);
516 fprintf(stderr
, _("Generated random UUID: %s\n"), str
);
518 memcpy(reply_buf
, uu
, sizeof(uu
));
519 reply_len
= sizeof(uu
);
521 case UUIDD_OP_BULK_TIME_UUID
:
522 ret
= __uuid_generate_time_cont(uu
, &num
, uuidd_cxt
->cont_clock_offset
);
523 if (ret
< 0 && !uuidd_cxt
->quiet
)
524 warnx(_("failed to open/lock clock counter"));
525 if (uuidd_cxt
->debug
) {
526 uuid_unparse(uu
, str
);
527 fprintf(stderr
, P_("Generated time UUID %s "
528 "and %d following\n",
529 "Generated time UUID %s "
530 "and %d following\n", num
- 1),
533 memcpy(reply_buf
, uu
, sizeof(uu
));
534 reply_len
= sizeof(uu
);
535 memcpy(reply_buf
+ reply_len
, &num
, sizeof(num
));
536 reply_len
+= sizeof(num
);
538 case UUIDD_OP_BULK_RANDOM_UUID
:
541 if ((sizeof(reply_buf
) - sizeof(num
)) < (size_t) (sizeof(uu
) * num
))
542 num
= (sizeof(reply_buf
) - sizeof(num
)) / sizeof(uu
);
543 __uuid_generate_random((unsigned char *) reply_buf
+
545 reply_len
= sizeof(num
) + (sizeof(uu
) * num
);
546 memcpy(reply_buf
, &num
, sizeof(num
));
547 if (uuidd_cxt
->debug
) {
548 fprintf(stderr
, P_("Generated %d UUID:\n",
549 "Generated %d UUIDs:\n", num
), num
);
550 cp
= reply_buf
+ sizeof(num
);
551 for (i
= 0; i
< num
; i
++) {
552 uuid_unparse((unsigned char *)cp
, str
);
553 fprintf(stderr
, "\t%s\n", str
);
559 if (uuidd_cxt
->debug
)
560 fprintf(stderr
, _("Invalid operation %d\n"), op
);
561 goto shutdown_socket
;
563 write_all(ns
, (char *) &reply_len
, sizeof(num
));
564 write_all(ns
, reply_buf
, reply_len
);
570 static void __attribute__ ((__noreturn__
)) unexpected_size(int size
)
572 errx(EXIT_FAILURE
, _("Unexpected reply length from server %d"), size
);
575 static uint32_t parse_cont_clock(char *arg
)
577 uint32_t min_val
= 60,
578 max_val
= (3600 * 24 * 365),
580 char *p
= &arg
[strlen(arg
)-1];
592 return factor
* str2num_or_err(optarg
, 10, _("failed to parse --cont-clock/-C"),
593 min_val
, max_val
/ factor
);
596 static void parse_options(int argc
, char **argv
, struct uuidd_cxt_t
*uuidd_cxt
,
597 struct uuidd_options_t
*uuidd_opts
)
599 const struct option longopts
[] = {
600 {"pid", required_argument
, NULL
, 'p'},
601 {"socket", required_argument
, NULL
, 's'},
602 {"timeout", required_argument
, NULL
, 'T'},
603 {"kill", no_argument
, NULL
, 'k'},
604 {"random", no_argument
, NULL
, 'r'},
605 {"time", no_argument
, NULL
, 't'},
606 {"uuids", required_argument
, NULL
, 'n'},
607 {"no-pid", no_argument
, NULL
, 'P'},
608 {"no-fork", no_argument
, NULL
, 'F'},
609 {"socket-activation", no_argument
, NULL
, 'S'},
610 {"cont-clock", optional_argument
, NULL
, 'C'},
611 {"debug", no_argument
, NULL
, 'd'},
612 {"quiet", no_argument
, NULL
, 'q'},
613 {"version", no_argument
, NULL
, 'V'},
614 {"help", no_argument
, NULL
, 'h'},
617 const ul_excl_t excl
[] = {
623 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
626 while ((c
= getopt_long(argc
, argv
, "p:s:T:krtn:PFSC::dqVh", longopts
, NULL
)) != -1) {
627 err_exclusive_options(c
, longopts
, excl
, excl_st
);
631 uuidd_cxt
->cont_clock_offset
= parse_cont_clock(optarg
);
633 uuidd_cxt
->cont_clock_offset
= 7200; /* default 2h */
636 uuidd_cxt
->debug
= 1;
639 uuidd_opts
->do_kill
= 1;
642 uuidd_opts
->num
= (uuidd_prot_num_t
) strtou16_or_err(optarg
,
643 _("failed to parse --uuids"));
646 uuidd_opts
->pidfile_path
= optarg
;
649 uuidd_opts
->no_pid
= 1;
652 uuidd_cxt
->no_fork
= 1;
655 #ifdef HAVE_LIBSYSTEMD
656 uuidd_cxt
->no_sock
= 1;
657 uuidd_cxt
->no_fork
= 1;
658 uuidd_opts
->no_pid
= 1;
660 errx(EXIT_FAILURE
, _("uuidd has been built without "
661 "support for socket activation"));
665 uuidd_cxt
->quiet
= 1;
668 uuidd_opts
->do_type
= UUIDD_OP_RANDOM_UUID
;
671 uuidd_opts
->socket_path
= optarg
;
672 uuidd_opts
->s_flag
= 1;
675 uuidd_opts
->do_type
= UUIDD_OP_TIME_UUID
;
678 uuidd_cxt
->timeout
= strtou32_or_err(optarg
,
679 _("failed to parse --timeout"));
683 print_version(EXIT_SUCCESS
);
687 errtryhelp(EXIT_FAILURE
);
691 if (0 < uuidd_opts
->num
) {
692 switch (uuidd_opts
->do_type
) {
693 case UUIDD_OP_RANDOM_UUID
:
694 uuidd_opts
->do_type
= UUIDD_OP_BULK_RANDOM_UUID
;
696 case UUIDD_OP_TIME_UUID
:
697 uuidd_opts
->do_type
= UUIDD_OP_BULK_TIME_UUID
;
703 int main(int argc
, char **argv
)
705 const char *err_context
= NULL
;
709 struct uuidd_cxt_t uuidd_cxt
= { .timeout
= 0, .cont_clock_offset
= 0 };
710 struct uuidd_options_t uuidd_opts
= { .socket_path
= UUIDD_SOCKET_PATH
};
712 setlocale(LC_ALL
, "");
713 bindtextdomain(PACKAGE
, LOCALEDIR
);
715 close_stdout_atexit();
717 parse_options(argc
, argv
, &uuidd_cxt
, &uuidd_opts
);
719 if (strlen(uuidd_opts
.socket_path
) >= sizeof_member(struct sockaddr_un
, sun_path
))
720 errx(EXIT_FAILURE
, _("socket name too long: %s"), uuidd_opts
.socket_path
);
722 if (!uuidd_opts
.no_pid
&& !uuidd_opts
.pidfile_path
)
723 uuidd_opts
.pidfile_path
= UUIDD_PIDFILE_PATH
;
725 /* custom socket path and socket-activation make no sense */
726 if (uuidd_opts
.s_flag
&& uuidd_cxt
.no_sock
&& !uuidd_cxt
.quiet
)
727 warnx(_("Both --socket-activation and --socket specified. "
728 "Ignoring --socket."));
730 if (uuidd_opts
.num
&& uuidd_opts
.do_type
) {
731 char buf
[UUIDD_PROT_BUFSZ
];
732 char str
[UUID_STR_LEN
];
734 ret
= call_daemon(uuidd_opts
.socket_path
, uuidd_opts
.do_type
, buf
,
735 sizeof(buf
), &uuidd_opts
.num
, &err_context
);
738 err(EXIT_FAILURE
, _("error calling uuidd daemon (%s)"),
739 err_context
? : _("unexpected error"));
741 if (uuidd_opts
.do_type
== UUIDD_OP_BULK_TIME_UUID
) {
742 if (ret
!= sizeof(uuid_t
) + sizeof(uuidd_opts
.num
))
743 unexpected_size(ret
);
745 uuid_unparse((unsigned char *) buf
, str
);
747 printf(P_("%s and %d subsequent UUID\n",
748 "%s and %d subsequent UUIDs\n", uuidd_opts
.num
- 1),
749 str
, uuidd_opts
.num
- 1);
753 printf(_("List of UUIDs:\n"));
754 cp
= buf
+ sizeof(uuidd_opts
.num
);
755 if (ret
!= (int) (sizeof(uuidd_opts
.num
) + uuidd_opts
.num
* sizeof(uuid_t
)))
756 unexpected_size(ret
);
757 for (i
= 0; i
< uuidd_opts
.num
; i
++, cp
+= sizeof(uuid_t
)) {
758 uuid_unparse((unsigned char *) cp
, str
);
759 printf("\t%s\n", str
);
765 if (uuidd_opts
.do_type
) {
767 char str
[UUID_STR_LEN
];
769 ret
= call_daemon(uuidd_opts
.socket_path
, uuidd_opts
.do_type
, (char *) &uu
,
770 sizeof(uu
), 0, &err_context
);
773 err(EXIT_FAILURE
, _("error calling uuidd daemon (%s)"),
774 err_context
? : _("unexpected error"));
775 if (ret
!= sizeof(uu
))
776 unexpected_size(ret
);
778 uuid_unparse(uu
, str
);
784 if (uuidd_opts
.do_kill
) {
787 ret
= call_daemon(uuidd_opts
.socket_path
, UUIDD_OP_GETPID
, buf
, sizeof(buf
), 0, NULL
);
791 pid
= (pid_t
)strtou32_or_err(buf
, _("failed to parse pid"));
792 ret
= kill(pid
, SIGTERM
);
794 if (!uuidd_cxt
.quiet
)
795 warn(_("couldn't kill uuidd running "
799 if (!uuidd_cxt
.quiet
)
800 printf(_("Killed uuidd running at pid %d.\n"), pid
);
805 server_loop(uuidd_opts
.socket_path
, uuidd_opts
.pidfile_path
, &uuidd_cxt
);