diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-05 11:36:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-10 11:39:03 +0200 |
commit | c7dd2095269923915b872b31404579e31da36012 (patch) | |
tree | 2efbbc936c0207be6c51c0ad0a3150a7fe068d01 | |
parent | e693a9323599ed6675ea598000362a9671214147 (diff) | |
download | systemd-c7dd2095269923915b872b31404579e31da36012.tar.gz systemd-c7dd2095269923915b872b31404579e31da36012.tar.bz2 systemd-c7dd2095269923915b872b31404579e31da36012.zip |
reply-password: define main through macro
-rw-r--r-- | src/reply-password/reply-password.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c index 7fd1fc5d1d..455788a184 100644 --- a/src/reply-password/reply-password.c +++ b/src/reply-password/reply-password.c @@ -7,6 +7,7 @@ #include <sys/un.h> #include "alloc-util.h" +#include "main-func.h" #include "fd-util.h" #include "fileio.h" #include "log.h" @@ -34,7 +35,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s return 0; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { _cleanup_(erase_and_freep) char *packet = NULL; _cleanup_close_ int fd = -1; size_t length = 0; @@ -42,56 +43,41 @@ int main(int argc, char *argv[]) { log_setup_service(); - if (argc != 3) { - log_error("Wrong number of arguments."); - return EXIT_FAILURE; - } + if (argc != 3) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Wrong number of arguments."); if (streq(argv[1], "1")) { _cleanup_string_free_erase_ char *line = NULL; r = read_line(stdin, LONG_LINE_MAX, &line); - if (r < 0) { - log_error_errno(r, "Failed to read password: %m"); - goto finish; - } - if (r == 0) { - log_error("Got EOF while reading password."); - r = -EIO; - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to read password: %m"); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(EIO), + "Got EOF while reading password."); packet = strjoin("+", line); - if (!packet) { - r = log_oom(); - goto finish; - } + if (!packet) + return log_oom(); length = 1 + strlen(line) + 1; } else if (streq(argv[1], "0")) { packet = strdup("-"); - if (!packet) { - r = log_oom(); - goto finish; - } + if (!packet) + return log_oom(); length = 1; - } else { - log_error("Invalid first argument %s", argv[1]); - r = -EINVAL; - goto finish; - } + } else + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid first argument %s", argv[1]); fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - if (fd < 0) { - r = log_error_errno(errno, "socket() failed: %m"); - goto finish; - } + if (fd < 0) + return log_error_errno(errno, "socket() failed: %m"); - r = send_on_socket(fd, argv[2], packet, length); - -finish: - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return send_on_socket(fd, argv[2], packet, length); } + +DEFINE_MAIN_FUNCTION(run); |