X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=34d70792990f122233665ab098b0cdb1f90c4d0b;hb=bdd13f6be4b588568683a1ab54f421fc6a636dbb;hp=b9d9b3aa961e8ace832a607d5a842a655f0c6aac;hpb=ac3efa8ac62b60261d6c101bc98831316523b07a;p=elogind.git diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b9d9b3aa9..34d707929 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -58,7 +58,6 @@ #include "path-lookup.h" #include "conf-parser.h" #include "exit-status.h" -#include "bus-errors.h" #include "build.h" #include "unit-name.h" #include "pager.h" @@ -909,6 +908,31 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) { return 0; } +static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) { + usec_t next_elapse; + + assert(nw); + assert(next); + + if (next->monotonic != (usec_t) -1 && next->monotonic > 0) { + usec_t converted; + + if (next->monotonic > nw->monotonic) + converted = nw->realtime + (next->monotonic - nw->monotonic); + else + converted = nw->realtime - (nw->monotonic - next->monotonic); + + if (next->realtime != (usec_t) -1 && next->realtime > 0) + next_elapse = MIN(converted, next->realtime); + else + next_elapse = converted; + + } else + next_elapse = next->realtime; + + return next_elapse; +} + static int list_timers(sd_bus *bus, char **args) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; @@ -931,7 +955,7 @@ static int list_timers(sd_bus *bus, char **args) { for (u = unit_infos; u < unit_infos + n; u++) { _cleanup_strv_free_ char **triggered = NULL; - dual_timestamp next; + dual_timestamp next = {}; usec_t m; if (!endswith(u->id, ".timer")) @@ -945,26 +969,13 @@ static int list_timers(sd_bus *bus, char **args) { if (r < 0) goto cleanup; - if (next.monotonic != (usec_t) -1 && next.monotonic > 0) { - usec_t converted; - - if (next.monotonic > nw.monotonic) - converted = nw.realtime + (next.monotonic - nw.monotonic); - else - converted = nw.realtime - (nw.monotonic - next.monotonic); - - if (next.realtime != (usec_t) -1 && next.realtime > 0) - m = MIN(converted, next.realtime); - else - m = converted; - } else - m = next.realtime; - if (!GREEDY_REALLOC(timer_infos, size, c+1)) { r = log_oom(); goto cleanup; } + m = calc_next_elapse(&nw, &next); + timer_infos[c++] = (struct timer_info) { .id = u->id, .next_elapse = m, @@ -2512,14 +2523,16 @@ static int start_special(sd_bus *bus, char **args) { static int check_unit_generic(sd_bus *bus, int code, const char *good_states, char **args) { _cleanup_strv_free_ char **names = NULL; char **name; - int r = code; + int r; assert(bus); assert(args); r = expand_names(bus, args, NULL, &names); - if (r < 0) + if (r < 0) { log_error("Failed to expand names: %s", strerror(-r)); + return r; + } STRV_FOREACH(name, names) { int state; @@ -2527,8 +2540,8 @@ static int check_unit_generic(sd_bus *bus, int code, const char *good_states, ch state = check_one_unit(bus, *name, good_states, arg_quiet); if (state < 0) return state; - if (state > 0) - r = 0; + if (state == 0) + r = code; } return r; @@ -3405,6 +3418,48 @@ static int print_property(const char *name, sd_bus_message *m, const char *conte if (arg_all || !isempty(a) || !isempty(b)) printf("%s=%s \"%s\"\n", name, strempty(a), strempty(b)); + return 0; + } else if (streq_ptr(name, "SystemCallFilter")) { + _cleanup_strv_free_ char **l = NULL; + int whitelist; + + r = sd_bus_message_enter_container(m, 'r', "bas"); + if (r < 0) + return bus_log_parse_error(r); + + r = sd_bus_message_read(m, "b", &whitelist); + if (r < 0) + return bus_log_parse_error(r); + + r = sd_bus_message_read_strv(m, &l); + if (r < 0) + return bus_log_parse_error(r); + + r = sd_bus_message_exit_container(m); + if (r < 0) + return bus_log_parse_error(r); + + if (arg_all || whitelist || !strv_isempty(l)) { + bool first = true; + char **i; + + fputs(name, stdout); + fputc('=', stdout); + + if (!whitelist) + fputc('~', stdout); + + STRV_FOREACH(i, l) { + if (first) + first = false; + else + fputc(' ', stdout); + + fputs(*i, stdout); + } + fputc('\n', stdout); + } + return 0; } @@ -4002,7 +4057,7 @@ static int append_assignment(sd_bus_message *m, const char *assignment) { } else if (streq(field, "MemoryLimit")) { off_t bytes; - r = parse_bytes(eq, &bytes); + r = parse_size(eq, 1024, &bytes); if (r < 0) { log_error("Failed to parse bytes specification %s", assignment); return -EINVAL; @@ -4072,7 +4127,7 @@ static int append_assignment(sd_bus_message *m, const char *assignment) { return -EINVAL; } - r = parse_bytes(bandwidth, &bytes); + r = parse_size(bandwidth, 1000, &bytes); if (r < 0) { log_error("Failed to parse byte value %s.", bandwidth); return -EINVAL; @@ -4132,11 +4187,11 @@ static int set_property(sd_bus *bus, char **args) { r = sd_bus_message_new_method_call( bus, + &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", - "SetUnitProperties", - &m); + "SetUnitProperties"); if (r < 0) return bus_log_create_error(r); @@ -4447,11 +4502,11 @@ static int set_environment(sd_bus *bus, char **args) { r = sd_bus_message_new_method_call( bus, + &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", - method, - &m); + method); if (r < 0) return bus_log_create_error(r); @@ -4478,11 +4533,11 @@ static int import_environment(sd_bus *bus, char **args) { r = sd_bus_message_new_method_call( bus, + &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", - "SetEnvironment", - &m); + "SetEnvironment"); if (r < 0) return bus_log_create_error(r); @@ -4740,6 +4795,11 @@ static int enable_unit(sd_bus *bus, char **args) { if (r < 0) return r; + /* If the operation was fully executed by the SysV compat, + * let's finish early */ + if (strv_isempty(names)) + return 0; + if (!bus || avoid_bus()) { if (streq(verb, "enable")) { r = unit_file_enable(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes); @@ -4801,11 +4861,11 @@ static int enable_unit(sd_bus *bus, char **args) { r = sd_bus_message_new_method_call( bus, + &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", - method, - &m); + method); if (r < 0) return bus_log_create_error(r); @@ -5831,7 +5891,6 @@ static int runlevel_parse_argv(int argc, char *argv[]) { case ARG_HELP: return runlevel_help(); - return 0; case '?': return -EINVAL;