uniformly suffix time span properties with their unit

This commit is contained in:
Lennart Poettering 2010-07-04 21:12:10 +02:00
parent 393a2f9be1
commit 03fae01822
10 changed files with 81 additions and 56 deletions

4
fixme
View file

@ -41,10 +41,12 @@
* get rid of Subscribe() in systemctl * 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 * Turn around negative options
* Add missing man pages: update systemd.1, finish daemon.7
External: External:
* patch /etc/init.d/functions with: * patch /etc/init.d/functions with:

View file

@ -497,13 +497,19 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>TimerSlackNS=</varname></term> <term><varname>TimerSlackNSec=</varname></term>
<listitem><para>Sets the timer slack <listitem><para>Sets the timer slack
in nanoseconds for the executed in nanoseconds for the executed
processes The timer slack controls the accuracy processes The timer slack controls the
of wake-ups triggered by timers. See accuracy of wake-ups triggered by
timers. See
<citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
for more information.</para></listitem> 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.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -99,27 +99,27 @@
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><varname>OnActive=</varname></term> <term><varname>OnActiveSec=</varname></term>
<term><varname>OnBootup=</varname></term> <term><varname>OnBootSec=</varname></term>
<term><varname>OnStartup=</varname></term> <term><varname>OnStartupSec=</varname></term>
<term><varname>OnUnitActive=</varname></term> <term><varname>OnUnitActiveSec=</varname></term>
<term><varname>OnUnitInactive=</varname></term> <term><varname>OnUnitInactiveSec=</varname></term>
<listitem><para>Defines timers <listitem><para>Defines timers
relative to different starting points: relative to different starting points:
<varname>OnActive=</varname> defines a <varname>OnActiveSec=</varname> defines a
timer relative to the moment the timer timer relative to the moment the timer
itself is itself is
activated. <varname>OnBootup=</varname> activated. <varname>OnBootSec=</varname>
defines a timer relative to when the defines a timer relative to when the
machine was booted machine was booted
up. <varname>OnStartup=</varname> up. <varname>OnStartupSec=</varname>
defines a timer relative to when defines a timer relative to when
systemd was systemd was
started. <varname>OnUnitActive=</varname> started. <varname>OnUnitActiveSec=</varname>
defines a timer relative to when the defines a timer relative to when the
unit the timer is activating was last unit the timer is activating was last
activated. <varname>OnUnitInactive=</varname> activated. <varname>OnUnitInactiveSec=</varname>
defines a timer relative to when the defines a timer relative to when the
unit the timer is activating was last unit the timer is activating was last
deactivated.</para> deactivated.</para>
@ -127,8 +127,8 @@
<para>Multiple directives may be <para>Multiple directives may be
combined of the same and of different combined of the same and of different
types. For example, by combining types. For example, by combining
<varname>OnBoot=</varname> and <varname>OnBootSec=</varname> and
<varname>OnUnitActive=</varname> it is <varname>OnUnitActiveSec=</varname> it is
possible to define a timer that possible to define a timer that
elapses in regular intervals and elapses in regular intervals and
activates a specific service each activates a specific service each
@ -136,17 +136,17 @@
<para>The arguments to the directives <para>The arguments to the directives
are time spans configured in are time spans configured in
seconds. Example: "OnBoot=50" means seconds. Example: "OnBootSec=50" means
50s after boot-up. The argument may 50s after boot-up. The argument may
also include time units. Example: 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 minutes after boot-up. For details
about the syntax of time spans see about the syntax of time spans see
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
<para>If a timer configured with <para>If a timer configured with
<varname>OnBootup=</varname> or <varname>OnBootSec=</varname> or
<varname>OnStartup=</varname> is <varname>OnStartupSec=</varname> is
already in the past when the timer already in the past when the timer
unit is activated, it will immediately unit is activated, it will immediately
elapse and the configured unit is elapse and the configured unit is

View file

@ -171,7 +171,7 @@ int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *prop
return 0; 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; ExecContext *c = data;
uint64_t u; uint64_t u;
@ -180,8 +180,8 @@ int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char
assert(property); assert(property);
assert(c); assert(c);
if (c->timer_slack_ns_set) if (c->timer_slack_nsec_set)
u = (uint64_t) c->timer_slack_ns_set; u = (uint64_t) c->timer_slack_nsec;
else else
u = (uint64_t) prctl(PR_GET_TIMERSLACK); u = (uint64_t) prctl(PR_GET_TIMERSLACK);

View file

@ -115,7 +115,7 @@
{ interface, "CPUSchedulingPolicy", bus_execute_append_cpu_sched_policy, "i", &(context) }, \ { interface, "CPUSchedulingPolicy", bus_execute_append_cpu_sched_policy, "i", &(context) }, \
{ interface, "CPUSchedulingPriority", bus_execute_append_cpu_sched_priority, "i", &(context) }, \ { interface, "CPUSchedulingPriority", bus_execute_append_cpu_sched_priority, "i", &(context) }, \
{ interface, "CPUAffinity", bus_execute_append_affinity,"ay", &(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, "CPUSchedulingResetOnFork", bus_property_append_bool, "b", &(context).cpu_sched_reset_on_fork }, \
{ interface, "NonBlocking", bus_property_append_bool, "b", &(context).non_blocking }, \ { interface, "NonBlocking", bus_property_append_bool, "b", &(context).non_blocking }, \
{ interface, "StandardInput", bus_execute_append_input, "s", &(context).std_input }, \ { 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_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_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_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_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_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_execute_append_command(Manager *m, DBusMessageIter *u, const char *property, void *data); int bus_execute_append_command(Manager *m, DBusMessageIter *u, const char *property, void *data);

View file

@ -29,7 +29,7 @@
" <interface name=\"org.freedesktop.systemd1.Timer\">\n" \ " <interface name=\"org.freedesktop.systemd1.Timer\">\n" \
" <property name=\"Unit\" type=\"s\" access=\"read\"/>\n" \ " <property name=\"Unit\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Timers\" type=\"a(stt)\" access=\"read\"/>\n" \ " <property name=\"Timers\" type=\"a(stt)\" access=\"read\"/>\n" \
" <property name=\"NextElapse\" type=\"t\" access=\"read\"/>\n" \ " <property name=\"NextElapseUSec\" type=\"t\" access=\"read\"/>\n" \
" </interface>\n" " </interface>\n"
#define INTROSPECTION \ #define INTROSPECTION \
@ -57,13 +57,30 @@ static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *p
return -ENOMEM; return -ENOMEM;
LIST_FOREACH(value, k, p->values) { 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) || t = timer_base_to_string(k->base);
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &t) || assert(endswith(t, "Sec"));
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->value) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->next_elapse) || /* s/Sec/USec/ */
!dbus_message_iter_close_container(&sub, &sub2)) 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; 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) { DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = { const BusProperty properties[] = {
BUS_UNIT_PROPERTIES, BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", u->timer.unit->meta.id }, { "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", "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", "NextElapseUSec", bus_property_append_usec, "t", &u->timer.next_elapse },
{ NULL, NULL, NULL, NULL, NULL } { NULL, NULL, NULL, NULL, NULL }
}; };

View file

@ -1083,8 +1083,8 @@ int exec_spawn(ExecCommand *command,
goto fail; goto fail;
} }
if (context->timer_slack_ns_set) if (context->timer_slack_nsec_set)
if (prctl(PR_SET_TIMERSLACK, context->timer_slack_ns_set) < 0) { if (prctl(PR_SET_TIMERSLACK, context->timer_slack_nsec) < 0) {
r = EXIT_TIMERSLACK; r = EXIT_TIMERSLACK;
goto fail; goto fail;
} }
@ -1468,8 +1468,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
fputs("\n", f); fputs("\n", f);
} }
if (c->timer_slack_ns_set) if (c->timer_slack_nsec_set)
fprintf(f, "%sTimerSlackNS: %lu\n", prefix, c->timer_slack_ns); fprintf(f, "%sTimerSlackNSec: %lu\n", prefix, c->timer_slack_nsec);
fprintf(f, fprintf(f,
"%sStandardInput: %s\n" "%sStandardInput: %s\n"

View file

@ -95,7 +95,7 @@ struct ExecContext {
cpu_set_t *cpuset; cpu_set_t *cpuset;
unsigned cpuset_ncpus; unsigned cpuset_ncpus;
unsigned long timer_slack_ns; unsigned long timer_slack_nsec;
ExecInput std_input; ExecInput std_input;
ExecOutput std_output; ExecOutput std_output;
@ -135,7 +135,7 @@ struct ExecContext {
bool nice_set:1; bool nice_set:1;
bool ioprio_set:1; bool ioprio_set:1;
bool cpu_sched_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 /* This is not exposed to the user but available
* internally. We need it to make sure that whenever we spawn * internally. We need it to make sure that whenever we spawn

View file

@ -857,7 +857,7 @@ static int config_parse_bounding_set(
return 0; return 0;
} }
static int config_parse_timer_slack_ns( static int config_parse_timer_slack_nsec(
const char *filename, const char *filename,
unsigned line, unsigned line,
const char *section, const char *section,
@ -880,7 +880,7 @@ static int config_parse_timer_slack_ns(
return r; return r;
} }
c->timer_slack_ns = u; c->timer_slack_nsec = u;
return 0; return 0;
} }
@ -1373,7 +1373,7 @@ static void dump_items(FILE *f, const ConfigItem *items) {
{ config_parse_capabilities, "CAPABILITIES" }, { config_parse_capabilities, "CAPABILITIES" },
{ config_parse_secure_bits, "SECUREBITS" }, { config_parse_secure_bits, "SECUREBITS" },
{ config_parse_bounding_set, "BOUNDINGSET" }, { config_parse_bounding_set, "BOUNDINGSET" },
{ config_parse_timer_slack_ns, "TIMERSLACK" }, { config_parse_timer_slack_nsec, "TIMERSLACK" },
{ config_parse_limit, "LIMIT" }, { config_parse_limit, "LIMIT" },
{ config_parse_cgroup, "CGROUP [...]" }, { config_parse_cgroup, "CGROUP [...]" },
{ config_parse_deps, "UNIT [...]" }, { config_parse_deps, "UNIT [...]" },
@ -1468,7 +1468,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "Capabilities", config_parse_capabilities, &(context), section }, \ { "Capabilities", config_parse_capabilities, &(context), section }, \
{ "SecureBits", config_parse_secure_bits, &(context), section }, \ { "SecureBits", config_parse_secure_bits, &(context), section }, \
{ "CapabilityBoundingSetDrop", config_parse_bounding_set, &(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 }, \ { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
{ "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \ { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
{ "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], 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" }, { "What", config_parse_path, &u->swap.parameters_fragment.what, "Swap" },
{ "Priority", config_parse_int, &u->swap.parameters_fragment.priority, "Swap" }, { "Priority", config_parse_int, &u->swap.parameters_fragment.priority, "Swap" },
{ "OnActive", config_parse_timer, &u->timer, "Timer" }, { "OnActiveSec", config_parse_timer, &u->timer, "Timer" },
{ "OnBoot", config_parse_timer, &u->timer, "Timer" }, { "OnBootSec", config_parse_timer, &u->timer, "Timer" },
{ "OnStartup", config_parse_timer, &u->timer, "Timer" }, { "OnStartupSec", config_parse_timer, &u->timer, "Timer" },
{ "OnUnitActive", config_parse_timer, &u->timer, "Timer" }, { "OnUnitActiveSec", config_parse_timer, &u->timer, "Timer" },
{ "OnUnitInactive", config_parse_timer, &u->timer, "Timer" }, { "OnUnitInactiveSec", config_parse_timer, &u->timer, "Timer" },
{ "Unit", config_parse_timer_unit, &u->timer, "Timer" }, { "Unit", config_parse_timer_unit, &u->timer, "Timer" },
{ "PathExists", config_parse_path_spec, &u->path, "Path" }, { "PathExists", config_parse_path_spec, &u->path, "Path" },

View file

@ -440,11 +440,11 @@ static const char* const timer_state_table[_TIMER_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState); DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
static const char* const timer_base_table[_TIMER_BASE_MAX] = { static const char* const timer_base_table[_TIMER_BASE_MAX] = {
[TIMER_ACTIVE] = "OnActive", [TIMER_ACTIVE] = "OnActiveSec",
[TIMER_BOOT] = "OnBoot", [TIMER_BOOT] = "OnBootSec",
[TIMER_STARTUP] = "OnStartup", [TIMER_STARTUP] = "OnStartupSec",
[TIMER_UNIT_ACTIVE] = "OnUnitActive", [TIMER_UNIT_ACTIVE] = "OnUnitActiveSec",
[TIMER_UNIT_INACTIVE] = "OnUnitInactive" [TIMER_UNIT_INACTIVE] = "OnUnitInactiveSec"
}; };
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase); DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);