uuidd: clean up error messages
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
28b856ff88
commit
bcb693de80
|
@ -76,7 +76,7 @@ endif
|
||||||
if BUILD_UUIDD
|
if BUILD_UUIDD
|
||||||
usrsbin_exec_PROGRAMS += uuidd
|
usrsbin_exec_PROGRAMS += uuidd
|
||||||
dist_man_MANS += misc-utils/uuidd.8
|
dist_man_MANS += misc-utils/uuidd.8
|
||||||
uuidd_LDADD = $(LDADD) libuuid.la
|
uuidd_LDADD = $(LDADD) libuuid.la libcommon.la
|
||||||
uuidd_CFLAGS = $(AM_CFLAGS) -I$(ul_libuuid_incdir)
|
uuidd_CFLAGS = $(AM_CFLAGS) -I$(ul_libuuid_incdir)
|
||||||
uuidd_SOURCES = misc-utils/uuidd.c
|
uuidd_SOURCES = misc-utils/uuidd.c
|
||||||
if USE_SOCKET_ACTIVATION
|
if USE_SOCKET_ACTIVATION
|
||||||
|
|
|
@ -36,6 +36,7 @@ extern int optind;
|
||||||
#include "all-io.h"
|
#include "all-io.h"
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "closestream.h"
|
#include "closestream.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
#ifdef USE_SOCKET_ACTIVATION
|
#ifdef USE_SOCKET_ACTIVATION
|
||||||
#include "sd-daemon.h"
|
#include "sd-daemon.h"
|
||||||
|
@ -217,8 +218,7 @@ static int create_pidfile(const char *pidfile_path, int quiet)
|
||||||
fd_pidfile = open(pidfile_path, O_CREAT | O_RDWR, 0664);
|
fd_pidfile = open(pidfile_path, O_CREAT | O_RDWR, 0664);
|
||||||
if (fd_pidfile < 0) {
|
if (fd_pidfile < 0) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(stderr, _("Failed to open/create %s: %m\n"),
|
warn(_("cannot open %s"), pidfile_path);
|
||||||
pidfile_path);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
cleanup_pidfile = pidfile_path;
|
cleanup_pidfile = pidfile_path;
|
||||||
|
@ -232,7 +232,7 @@ static int create_pidfile(const char *pidfile_path, int quiet)
|
||||||
if ((errno == EAGAIN) || (errno == EINTR))
|
if ((errno == EAGAIN) || (errno == EINTR))
|
||||||
continue;
|
continue;
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(stderr, _("Failed to lock %s: %m\n"), pidfile_path);
|
warn(_("cannot lock %s"), pidfile_path);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ static int create_socket(const char *socket_path, int will_fork, int quiet)
|
||||||
|
|
||||||
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(stderr, _("Couldn't create unix stream socket: %m"));
|
warn(_("couldn't create unix stream socket"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,8 +281,7 @@ static int create_socket(const char *socket_path, int will_fork, int quiet)
|
||||||
if (bind(s, (const struct sockaddr *) &my_addr,
|
if (bind(s, (const struct sockaddr *) &my_addr,
|
||||||
sizeof(struct sockaddr_un)) < 0) {
|
sizeof(struct sockaddr_un)) < 0) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(stderr,
|
warn(_("couldn't bind unix socket %s"), socket_path);
|
||||||
_("Couldn't bind unix socket %s: %m\n"), socket_path);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
umask(save_umask);
|
umask(save_umask);
|
||||||
|
@ -319,8 +318,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
|
||||||
sizeof(reply_buf), 0, NULL);
|
sizeof(reply_buf), 0, NULL);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
if (!uuidd_cxt->quiet)
|
if (!uuidd_cxt->quiet)
|
||||||
fprintf(stderr,
|
warnx(_("uuidd daemon already running at pid %s"),
|
||||||
_("uuidd daemon already running at pid %s\n"),
|
|
||||||
reply_buf);
|
reply_buf);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -331,8 +329,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
|
||||||
uuidd_cxt->quiet);
|
uuidd_cxt->quiet);
|
||||||
if (listen(s, SOMAXCONN) < 0) {
|
if (listen(s, SOMAXCONN) < 0) {
|
||||||
if (!uuidd_cxt->quiet)
|
if (!uuidd_cxt->quiet)
|
||||||
fprintf(stderr, _("Couldn't listen on unix "
|
warn(_("couldn't listen on unix socket %s"), socket_path);
|
||||||
"socket %s: %m\n"), socket_path);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,10 +354,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
|
||||||
|
|
||||||
#ifdef USE_SOCKET_ACTIVATION
|
#ifdef USE_SOCKET_ACTIVATION
|
||||||
if (uuidd_cxt->no_sock) {
|
if (uuidd_cxt->no_sock) {
|
||||||
if (sd_listen_fds(0) != 1) {
|
if (sd_listen_fds(0) != 1)
|
||||||
fprintf(stderr, _("No or too many file descriptors received.\n"));
|
errx(EXIT_FAILURE, _("no or too many file descriptors received."));
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
s = SD_LISTEN_FDS_START + 0;
|
s = SD_LISTEN_FDS_START + 0;
|
||||||
}
|
}
|
||||||
|
@ -381,10 +376,10 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
|
||||||
len = read(ns, &op, 1);
|
len = read(ns, &op, 1);
|
||||||
if (len != 1) {
|
if (len != 1) {
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
perror("read");
|
warn(_("read failed"));
|
||||||
else
|
else
|
||||||
fprintf(stderr, _("Error reading from client, "
|
warnx(_("rrror reading from client, len = %d"),
|
||||||
"len = %d\n"), len);
|
len);
|
||||||
goto shutdown_socket;
|
goto shutdown_socket;
|
||||||
}
|
}
|
||||||
if ((op == UUIDD_OP_BULK_TIME_UUID) ||
|
if ((op == UUIDD_OP_BULK_TIME_UUID) ||
|
||||||
|
@ -487,7 +482,7 @@ int main(int argc, char **argv)
|
||||||
const char *pidfile_path_param = NULL;
|
const char *pidfile_path_param = NULL;
|
||||||
const char *err_context;
|
const char *err_context;
|
||||||
char buf[1024], *cp;
|
char buf[1024], *cp;
|
||||||
char str[UUID_STR_LEN], *tmp;
|
char str[UUID_STR_LEN];
|
||||||
uuid_t uu;
|
uuid_t uu;
|
||||||
int i, c, ret;
|
int i, c, ret;
|
||||||
int do_type = 0, do_kill = 0, num = 0;
|
int do_type = 0, do_kill = 0, num = 0;
|
||||||
|
@ -530,11 +525,8 @@ int main(int argc, char **argv)
|
||||||
do_kill++;
|
do_kill++;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
num = strtol(optarg, &tmp, 0);
|
num = strtou32_or_err(optarg,
|
||||||
if ((num < 1) || *tmp) {
|
_("failed to parse --uuids"));
|
||||||
fprintf(stderr, _("Bad number: %s\n"), optarg);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pidfile_path_param = optarg;
|
pidfile_path_param = optarg;
|
||||||
|
@ -551,9 +543,8 @@ int main(int argc, char **argv)
|
||||||
uuidd_cxt.no_fork = 1;
|
uuidd_cxt.no_fork = 1;
|
||||||
no_pid = 1;
|
no_pid = 1;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,
|
errx(EXIT_FAILURE, _("uuidd has been built without "
|
||||||
_("uuidd has been built without support for socket activation.\n"));
|
"support for socket activation."));
|
||||||
return EXIT_FAILURE;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -570,11 +561,8 @@ int main(int argc, char **argv)
|
||||||
do_type = UUIDD_OP_TIME_UUID;
|
do_type = UUIDD_OP_TIME_UUID;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
uuidd_cxt.timeout = strtol(optarg, &tmp, 0);
|
uuidd_cxt.timeout = strtou32_or_err(optarg,
|
||||||
if (uuidd_cxt.timeout < 0 || *tmp) {
|
_("failed to parse --timeout"));
|
||||||
fprintf(stderr, _("Bad number: %s\n"), optarg);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf(UTIL_LINUX_VERSION);
|
printf(UTIL_LINUX_VERSION);
|
||||||
|
@ -587,8 +575,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_pid && pidfile_path_param && !uuidd_cxt.quiet)
|
if (no_pid && pidfile_path_param && !uuidd_cxt.quiet)
|
||||||
fprintf(stderr, _("Both --pid and --no-pid specified. "
|
warnx(_("Both --pid and --no-pid specified. Ignoring --no-pid."));
|
||||||
"Ignoring --no-pid.\n"));
|
|
||||||
|
|
||||||
if (!no_pid && !pidfile_path_param)
|
if (!no_pid && !pidfile_path_param)
|
||||||
pidfile_path = UUIDD_PIDFILE_PATH;
|
pidfile_path = UUIDD_PIDFILE_PATH;
|
||||||
|
@ -597,16 +584,16 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* custom socket path and socket-activation make no sense */
|
/* custom socket path and socket-activation make no sense */
|
||||||
if (s_flag && uuidd_cxt.no_sock && !uuidd_cxt.quiet)
|
if (s_flag && uuidd_cxt.no_sock && !uuidd_cxt.quiet)
|
||||||
fprintf(stderr, _("Both --socket-activation and --socket specified. "
|
warnx(_("Both --socket-activation and --socket specified. "
|
||||||
"Ignoring --socket\n"));
|
"Ignoring --socket"));
|
||||||
|
|
||||||
if (num && do_type) {
|
if (num && do_type) {
|
||||||
ret = call_daemon(socket_path, do_type + 2, buf,
|
ret = call_daemon(socket_path, do_type + 2, buf,
|
||||||
sizeof(buf), &num, &err_context);
|
sizeof(buf), &num, &err_context);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
printf(_("Error calling uuidd daemon (%s): %m\n"), err_context);
|
err(EXIT_FAILURE, _("error calling uuidd daemon (%s)"),
|
||||||
return EXIT_FAILURE;
|
err_context);
|
||||||
}
|
|
||||||
if (do_type == UUIDD_OP_TIME_UUID) {
|
if (do_type == UUIDD_OP_TIME_UUID) {
|
||||||
if (ret != sizeof(uu) + sizeof(num))
|
if (ret != sizeof(uu) + sizeof(num))
|
||||||
unexpected_size(ret);
|
unexpected_size(ret);
|
||||||
|
@ -631,10 +618,9 @@ int main(int argc, char **argv)
|
||||||
if (do_type) {
|
if (do_type) {
|
||||||
ret = call_daemon(socket_path, do_type, (char *) &uu,
|
ret = call_daemon(socket_path, do_type, (char *) &uu,
|
||||||
sizeof(uu), 0, &err_context);
|
sizeof(uu), 0, &err_context);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
printf(_("Error calling uuidd daemon (%s): %m\n"), err_context);
|
err(EXIT_FAILURE, _("error calling uuidd daemon (%s)"),
|
||||||
return EXIT_FAILURE;
|
err_context);
|
||||||
}
|
|
||||||
if (ret != sizeof(uu))
|
if (ret != sizeof(uu))
|
||||||
unexpected_size(ret);
|
unexpected_size(ret);
|
||||||
|
|
||||||
|
@ -650,9 +636,8 @@ int main(int argc, char **argv)
|
||||||
ret = kill(do_kill, SIGTERM);
|
ret = kill(do_kill, SIGTERM);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (!uuidd_cxt.quiet)
|
if (!uuidd_cxt.quiet)
|
||||||
fprintf(stderr,
|
warn(_("couldn't kill uuidd running "
|
||||||
_("Couldn't kill uuidd running "
|
"at pid %d"), do_kill);
|
||||||
"at pid %d: %m\n"), do_kill);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (!uuidd_cxt.quiet)
|
if (!uuidd_cxt.quiet)
|
||||||
|
|
Loading…
Reference in New Issue