X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmachine%2Fmachinectl.c;h=f60c66055dd7258e5d823302f30e90d920cb4147;hb=46e65dcc3a522b5e992e165b5e61d14254026859;hp=8468436646bf330de1d7309e9ae70219fd9cc128;hpb=9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75;p=elogind.git diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 846843664..f60c66055 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -19,13 +19,13 @@ along with systemd; If not, see . ***/ +#include #include #include #include #include #include #include -#include #include #include "sd-bus.h" @@ -284,7 +284,7 @@ static int show_properties(sd_bus *bus, const char *path, bool *new_line) { *new_line = true; - r = bus_print_all_properties(bus, path, arg_property, arg_all); + r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all); if (r < 0) log_error("Could not get properties: %s", strerror(-r)); @@ -409,11 +409,14 @@ static int openpt_in_namespace(pid_t pid, int flags) { _cleanup_close_ int nsfd = -1, rootfd = -1; _cleanup_free_ char *ns = NULL, *root = NULL; _cleanup_close_pipe_ int sock[2] = { -1, -1 }; - struct msghdr mh; union { struct cmsghdr cmsghdr; uint8_t buf[CMSG_SPACE(sizeof(int))]; - } control; + } control = {}; + struct msghdr mh = { + .msg_control = &control, + .msg_controllen = sizeof(control), + }; struct cmsghdr *cmsg; int master = -1, r; pid_t child; @@ -438,11 +441,6 @@ static int openpt_in_namespace(pid_t pid, int flags) { if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sock) < 0) return -errno; - zero(control); - zero(mh); - mh.msg_control = &control; - mh.msg_controllen = sizeof(control); - child = fork(); if (child < 0) return -errno; @@ -686,7 +684,7 @@ static int parse_argv(int argc, char *argv[]) { { "host", required_argument, NULL, 'H' }, { "machine", required_argument, NULL, 'M' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, - { NULL, 0, NULL, 0 } + {} }; int c, r; @@ -699,8 +697,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -760,8 +757,7 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } @@ -797,7 +793,7 @@ static int machinectl_main(sd_bus *bus, int argc, char *argv[]) { left = argc - optind; if (left <= 0) - /* Special rule: no arguments means "list-sessions" */ + /* Special rule: no arguments means "list" */ i = 0; else { if (streq(argv[optind], "help")) { @@ -849,35 +845,29 @@ static int machinectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char*argv[]) { - int r, ret = EXIT_FAILURE; _cleanup_bus_unref_ sd_bus *bus = NULL; + int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); - if (r < 0) - goto finish; - else if (r == 0) { - ret = EXIT_SUCCESS; + if (r <= 0) goto finish; - } r = bus_open_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error("Failed to create bus connection: %s", strerror(-r)); - ret = EXIT_FAILURE; goto finish; } r = machinectl_main(bus, argc, argv); - ret = r < 0 ? EXIT_FAILURE : r; finish: - strv_free(arg_property); - pager_close(); - return ret; + strv_free(arg_property); + + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }