From: Lennart Poettering Date: Sun, 4 Jul 2010 19:12:10 +0000 (+0200) Subject: uniformly suffix time span properties with their unit X-Git-Tag: v1~36 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=03fae01822b5275a2940458f65644796283a8a23 uniformly suffix time span properties with their unit --- diff --git a/fixme b/fixme index 55e47d71c..8143f013b 100644 --- a/fixme +++ b/fixme @@ -41,10 +41,12 @@ * get rid of Subscribe() in systemctl -* Unify NS, USec, NSec, Sec suffixes in properties, use format_timespan +* use format_timespan where applicable * Turn around negative options +* Add missing man pages: update systemd.1, finish daemon.7 + External: * patch /etc/init.d/functions with: diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 6e9051db7..83eef32f5 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -497,13 +497,19 @@ - TimerSlackNS= + TimerSlackNSec= Sets the timer slack in nanoseconds for the executed - processes The timer slack controls the accuracy - of wake-ups triggered by timers. See + processes The timer slack controls the + accuracy of wake-ups triggered by + timers. See prctl2 - for more information. + for more information. Note that in + contrast to most other time span + definitions this value is takes a + nano-seconds integer and does not + understand any other + units. diff --git a/man/systemd.timer.xml b/man/systemd.timer.xml index ef89693f1..557a45e0f 100644 --- a/man/systemd.timer.xml +++ b/man/systemd.timer.xml @@ -99,27 +99,27 @@ - OnActive= - OnBootup= - OnStartup= - OnUnitActive= - OnUnitInactive= + OnActiveSec= + OnBootSec= + OnStartupSec= + OnUnitActiveSec= + OnUnitInactiveSec= Defines timers relative to different starting points: - OnActive= defines a + OnActiveSec= defines a timer relative to the moment the timer itself is - activated. OnBootup= + activated. OnBootSec= defines a timer relative to when the machine was booted - up. OnStartup= + up. OnStartupSec= defines a timer relative to when systemd was - started. OnUnitActive= + started. OnUnitActiveSec= defines a timer relative to when the unit the timer is activating was last - activated. OnUnitInactive= + activated. OnUnitInactiveSec= defines a timer relative to when the unit the timer is activating was last deactivated. @@ -127,8 +127,8 @@ Multiple directives may be combined of the same and of different types. For example, by combining - OnBoot= and - OnUnitActive= it is + OnBootSec= and + OnUnitActiveSec= it is possible to define a timer that elapses in regular intervals and activates a specific service each @@ -136,17 +136,17 @@ The arguments to the directives are time spans configured in - seconds. Example: "OnBoot=50" means + seconds. Example: "OnBootSec=50" means 50s after boot-up. The argument may also include time units. Example: - "OnBoot=5h 30min" means 5 hours and 30 + "OnBootSec=5h 30min" means 5 hours and 30 minutes after boot-up. For details about the syntax of time spans see systemd.unit5. If a timer configured with - OnBootup= or - OnStartup= is + OnBootSec= or + OnStartupSec= is already in the past when the timer unit is activated, it will immediately elapse and the configured unit is diff --git a/src/dbus-execute.c b/src/dbus-execute.c index 529f72dfa..d37bd5560 100644 --- a/src/dbus-execute.c +++ b/src/dbus-execute.c @@ -171,7 +171,7 @@ int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *prop return 0; } -int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data) { ExecContext *c = data; uint64_t u; @@ -180,8 +180,8 @@ int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char assert(property); assert(c); - if (c->timer_slack_ns_set) - u = (uint64_t) c->timer_slack_ns_set; + if (c->timer_slack_nsec_set) + u = (uint64_t) c->timer_slack_nsec; else u = (uint64_t) prctl(PR_GET_TIMERSLACK); diff --git a/src/dbus-execute.h b/src/dbus-execute.h index 95d400d28..520815969 100644 --- a/src/dbus-execute.h +++ b/src/dbus-execute.h @@ -115,7 +115,7 @@ { interface, "CPUSchedulingPolicy", bus_execute_append_cpu_sched_policy, "i", &(context) }, \ { interface, "CPUSchedulingPriority", bus_execute_append_cpu_sched_priority, "i", &(context) }, \ { interface, "CPUAffinity", bus_execute_append_affinity,"ay", &(context) }, \ - { interface, "TimerSlackNS", bus_execute_append_timer_slack_ns, "t", &(context) }, \ + { interface, "TimerSlackNSec", bus_execute_append_timer_slack_nsec, "t", &(context) }, \ { interface, "CPUSchedulingResetOnFork", bus_property_append_bool, "b", &(context).cpu_sched_reset_on_fork }, \ { interface, "NonBlocking", bus_property_append_bool, "b", &(context).non_blocking }, \ { interface, "StandardInput", bus_execute_append_input, "s", &(context).std_input }, \ @@ -158,7 +158,7 @@ int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *proper int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data); -int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_command(Manager *m, DBusMessageIter *u, const char *property, void *data); diff --git a/src/dbus-timer.c b/src/dbus-timer.c index d548227b5..0cd37d971 100644 --- a/src/dbus-timer.c +++ b/src/dbus-timer.c @@ -29,7 +29,7 @@ " \n" \ " \n" \ " \n" \ - " \n" \ + " \n" \ " \n" #define INTROSPECTION \ @@ -57,13 +57,30 @@ static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *p return -ENOMEM; LIST_FOREACH(value, k, p->values) { - const char *t = timer_base_to_string(k->base); + char *buf; + const char *t; + size_t l; + bool b; - if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) || - !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &t) || - !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->value) || - !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->next_elapse) || - !dbus_message_iter_close_container(&sub, &sub2)) + t = timer_base_to_string(k->base); + assert(endswith(t, "Sec")); + + /* s/Sec/USec/ */ + l = strlen(t); + if (!(buf = new(char, l+2))) + return -ENOMEM; + + memcpy(buf, t, l-3); + memcpy(buf+l-3, "USec", 5); + + b = dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) && + dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &buf) && + dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->value) && + dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->next_elapse) && + dbus_message_iter_close_container(&sub, &sub2); + + free(buf); + if (!b) return -ENOMEM; } @@ -76,9 +93,9 @@ static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *p DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { const BusProperty properties[] = { BUS_UNIT_PROPERTIES, - { "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", u->timer.unit->meta.id }, - { "org.freedesktop.systemd1.Timer", "Timers", bus_timer_append_timers, "a(stt)", u }, - { "org.freedesktop.systemd1.Timer", "NextElapse", bus_property_append_usec, "t", &u->timer.next_elapse }, + { "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", u->timer.unit->meta.id }, + { "org.freedesktop.systemd1.Timer", "Timers", bus_timer_append_timers, "a(stt)", u }, + { "org.freedesktop.systemd1.Timer", "NextElapseUSec", bus_property_append_usec, "t", &u->timer.next_elapse }, { NULL, NULL, NULL, NULL, NULL } }; diff --git a/src/execute.c b/src/execute.c index f3f95ff75..982b7d1bc 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1083,8 +1083,8 @@ int exec_spawn(ExecCommand *command, goto fail; } - if (context->timer_slack_ns_set) - if (prctl(PR_SET_TIMERSLACK, context->timer_slack_ns_set) < 0) { + if (context->timer_slack_nsec_set) + if (prctl(PR_SET_TIMERSLACK, context->timer_slack_nsec) < 0) { r = EXIT_TIMERSLACK; goto fail; } @@ -1468,8 +1468,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { fputs("\n", f); } - if (c->timer_slack_ns_set) - fprintf(f, "%sTimerSlackNS: %lu\n", prefix, c->timer_slack_ns); + if (c->timer_slack_nsec_set) + fprintf(f, "%sTimerSlackNSec: %lu\n", prefix, c->timer_slack_nsec); fprintf(f, "%sStandardInput: %s\n" diff --git a/src/execute.h b/src/execute.h index aa5f56667..1ab6a24d9 100644 --- a/src/execute.h +++ b/src/execute.h @@ -95,7 +95,7 @@ struct ExecContext { cpu_set_t *cpuset; unsigned cpuset_ncpus; - unsigned long timer_slack_ns; + unsigned long timer_slack_nsec; ExecInput std_input; ExecOutput std_output; @@ -135,7 +135,7 @@ struct ExecContext { bool nice_set:1; bool ioprio_set:1; bool cpu_sched_set:1; - bool timer_slack_ns_set:1; + bool timer_slack_nsec_set:1; /* This is not exposed to the user but available * internally. We need it to make sure that whenever we spawn diff --git a/src/load-fragment.c b/src/load-fragment.c index a5ea0e41b..8e777fdbc 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -857,7 +857,7 @@ static int config_parse_bounding_set( return 0; } -static int config_parse_timer_slack_ns( +static int config_parse_timer_slack_nsec( const char *filename, unsigned line, const char *section, @@ -880,7 +880,7 @@ static int config_parse_timer_slack_ns( return r; } - c->timer_slack_ns = u; + c->timer_slack_nsec = u; return 0; } @@ -1373,7 +1373,7 @@ static void dump_items(FILE *f, const ConfigItem *items) { { config_parse_capabilities, "CAPABILITIES" }, { config_parse_secure_bits, "SECUREBITS" }, { config_parse_bounding_set, "BOUNDINGSET" }, - { config_parse_timer_slack_ns, "TIMERSLACK" }, + { config_parse_timer_slack_nsec, "TIMERSLACK" }, { config_parse_limit, "LIMIT" }, { config_parse_cgroup, "CGROUP [...]" }, { config_parse_deps, "UNIT [...]" }, @@ -1468,7 +1468,7 @@ static int load_from_path(Unit *u, const char *path) { { "Capabilities", config_parse_capabilities, &(context), section }, \ { "SecureBits", config_parse_secure_bits, &(context), section }, \ { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \ - { "TimerSlackNS", config_parse_timer_slack_ns, &(context), section }, \ + { "TimerSlackNSec", config_parse_timer_slack_nsec,&(context), section }, \ { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \ { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \ { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \ @@ -1574,11 +1574,11 @@ static int load_from_path(Unit *u, const char *path) { { "What", config_parse_path, &u->swap.parameters_fragment.what, "Swap" }, { "Priority", config_parse_int, &u->swap.parameters_fragment.priority, "Swap" }, - { "OnActive", config_parse_timer, &u->timer, "Timer" }, - { "OnBoot", config_parse_timer, &u->timer, "Timer" }, - { "OnStartup", config_parse_timer, &u->timer, "Timer" }, - { "OnUnitActive", config_parse_timer, &u->timer, "Timer" }, - { "OnUnitInactive", config_parse_timer, &u->timer, "Timer" }, + { "OnActiveSec", config_parse_timer, &u->timer, "Timer" }, + { "OnBootSec", config_parse_timer, &u->timer, "Timer" }, + { "OnStartupSec", config_parse_timer, &u->timer, "Timer" }, + { "OnUnitActiveSec", config_parse_timer, &u->timer, "Timer" }, + { "OnUnitInactiveSec", config_parse_timer, &u->timer, "Timer" }, { "Unit", config_parse_timer_unit, &u->timer, "Timer" }, { "PathExists", config_parse_path_spec, &u->path, "Path" }, diff --git a/src/timer.c b/src/timer.c index e3c916bb0..b4521e6ef 100644 --- a/src/timer.c +++ b/src/timer.c @@ -440,11 +440,11 @@ static const char* const timer_state_table[_TIMER_STATE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState); static const char* const timer_base_table[_TIMER_BASE_MAX] = { - [TIMER_ACTIVE] = "OnActive", - [TIMER_BOOT] = "OnBoot", - [TIMER_STARTUP] = "OnStartup", - [TIMER_UNIT_ACTIVE] = "OnUnitActive", - [TIMER_UNIT_INACTIVE] = "OnUnitInactive" + [TIMER_ACTIVE] = "OnActiveSec", + [TIMER_BOOT] = "OnBootSec", + [TIMER_STARTUP] = "OnStartupSec", + [TIMER_UNIT_ACTIVE] = "OnUnitActiveSec", + [TIMER_UNIT_INACTIVE] = "OnUnitInactiveSec" }; DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);