[systemd-commits] 8 commits - TODO src/automount.c src/automount.h src/dbus-automount.c src/dbus-automount.h src/dbus-mount.c src/dbus-path.c src/dbus-path.h src/dbus-service.c src/dbus-socket.c src/dbus-swap.c src/dbus-timer.c src/mount.c src/mount.h src/path.c src/path.h src/service.c src/service.h src/socket.c src/socket.h src/swap.c src/swap.h src/systemctl.c src/timer.c src/timer.h
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Feb 2 20:06:21 PST 2012
TODO | 2
src/automount.c | 46 ++++---
src/automount.h | 12 +-
src/dbus-automount.c | 9 +
src/dbus-automount.h | 1
src/dbus-mount.c | 7 +
src/dbus-path.c | 7 +
src/dbus-path.h | 2
src/dbus-service.c | 8 +
src/dbus-socket.c | 6 -
src/dbus-swap.c | 7 +
src/dbus-timer.c | 7 +
src/mount.c | 175 +++++++++++++++++------------
src/mount.h | 18 ++-
src/path.c | 43 +++++--
src/path.h | 13 ++
src/service.c | 298 ++++++++++++++++++++++++++++-----------------------
src/service.h | 18 ++-
src/socket.c | 172 +++++++++++++++++------------
src/socket.h | 16 ++
src/swap.c | 122 ++++++++++++--------
src/swap.h | 18 ++-
src/systemctl.c | 10 +
src/timer.c | 37 ++++--
src/timer.h | 12 +-
25 files changed, 689 insertions(+), 377 deletions(-)
New commits:
commit cd43ca73e19511f999c80995937e418c35c30ee8
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 05:04:48 2012 +0100
path: convert failure field to enum
diff --git a/src/dbus-path.c b/src/dbus-path.c
index 083ba9e..5506784 100644
--- a/src/dbus-path.c
+++ b/src/dbus-path.c
@@ -32,6 +32,7 @@
" <property name=\"Paths\" type=\"a(ss)\" access=\"read\"/>\n" \
" <property name=\"MakeDirectory\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -50,6 +51,9 @@
const char bus_path_interface[] _introspect_("Path") = BUS_PATH_INTERFACE;
+const char bus_path_invalidating_properties[] =
+ "Result\0";
+
static int bus_path_append_paths(DBusMessageIter *i, const char *property, void *data) {
Path *p = data;
DBusMessageIter sub, sub2;
@@ -92,11 +96,14 @@ static int bus_path_append_unit(DBusMessageIter *i, const char *property, void *
return dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t) ? 0 : -ENOMEM;
}
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_path_append_path_result, path_result, PathResult);
+
static const BusProperty bus_path_properties[] = {
{ "Unit", bus_path_append_unit, "s", 0 },
{ "Paths", bus_path_append_paths, "a(ss)", 0 },
{ "MakeDirectory", bus_property_append_bool, "b", offsetof(Path, make_directory) },
{ "DirectoryMode", bus_property_append_mode, "u", offsetof(Path, directory_mode) },
+ { "Result", bus_path_append_path_result, "s", offsetof(Path, result) },
{ NULL, }
};
diff --git a/src/dbus-path.h b/src/dbus-path.h
index f825e13..2888400 100644
--- a/src/dbus-path.h
+++ b/src/dbus-path.h
@@ -30,4 +30,6 @@ DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessa
extern const char bus_path_interface[];
+extern const char bus_path_invalidating_properties[];
+
#endif
diff --git a/src/path.c b/src/path.c
index a16d3fa..e97cd09 100644
--- a/src/path.c
+++ b/src/path.c
@@ -369,10 +369,12 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sPath State: %s\n"
+ "%sResult: %s\n"
"%sUnit: %s\n"
"%sMakeDirectory: %s\n"
"%sDirectoryMode: %04o\n",
prefix, path_state_to_string(p->state),
+ prefix, path_result_to_string(p->result),
prefix, UNIT_DEREF(p->unit)->id,
prefix, yes_no(p->make_directory),
prefix, p->directory_mode);
@@ -443,13 +445,13 @@ static int path_coldplug(Unit *u) {
return 0;
}
-static void path_enter_dead(Path *p, bool success) {
+static void path_enter_dead(Path *p, PathResult f) {
assert(p);
- if (!success)
- p->failure = true;
+ if (f != PATH_SUCCESS)
+ p->result = f;
- path_set_state(p, p->failure ? PATH_FAILED : PATH_DEAD);
+ path_set_state(p, p->result != PATH_SUCCESS ? PATH_FAILED : PATH_DEAD);
}
static void path_enter_running(Path *p) {
@@ -476,7 +478,7 @@ static void path_enter_running(Path *p) {
fail:
log_warning("%s failed to queue unit startup job: %s", UNIT(p)->id, bus_error(&error, r));
- path_enter_dead(p, false);
+ path_enter_dead(p, PATH_FAILURE_RESOURCES);
dbus_error_free(&error);
}
@@ -526,7 +528,7 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) {
fail:
log_warning("%s failed to enter waiting state: %s", UNIT(p)->id, strerror(-r));
- path_enter_dead(p, false);
+ path_enter_dead(p, PATH_FAILURE_RESOURCES);
}
static void path_mkdir(Path *p) {
@@ -552,7 +554,7 @@ static int path_start(Unit *u) {
path_mkdir(p);
- p->failure = false;
+ p->result = PATH_SUCCESS;
path_enter_waiting(p, true, true);
return 0;
@@ -564,7 +566,7 @@ static int path_stop(Unit *u) {
assert(p);
assert(p->state == PATH_WAITING || p->state == PATH_RUNNING);
- path_enter_dead(p, true);
+ path_enter_dead(p, PATH_SUCCESS);
return 0;
}
@@ -576,6 +578,7 @@ static int path_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", path_state_to_string(p->state));
+ unit_serialize_item(u, f, "result", path_result_to_string(p->result));
return 0;
}
@@ -595,6 +598,16 @@ static int path_deserialize_item(Unit *u, const char *key, const char *value, FD
log_debug("Failed to parse state value %s", value);
else
p->deserialized_state = state;
+
+ } else if (streq(key, "result")) {
+ PathResult f;
+
+ f = path_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != PATH_SUCCESS)
+ p->result = f;
+
} else
log_debug("Unknown serialization key '%s'", key);
@@ -653,7 +666,7 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
return;
fail:
- path_enter_dead(p, false);
+ path_enter_dead(p, PATH_FAILURE_RESOURCES);
}
void path_unit_notify(Unit *u, UnitActiveState new_state) {
@@ -693,7 +706,7 @@ static void path_reset_failed(Unit *u) {
if (p->state == PATH_FAILED)
path_set_state(p, PATH_DEAD);
- p->failure = false;
+ p->result = PATH_SUCCESS;
}
static const char* const path_state_table[_PATH_STATE_MAX] = {
@@ -715,6 +728,13 @@ static const char* const path_type_table[_PATH_TYPE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(path_type, PathType);
+static const char* const path_result_table[_PATH_RESULT_MAX] = {
+ [PATH_SUCCESS] = "success",
+ [PATH_FAILURE_RESOURCES] = "resources"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(path_result, PathResult);
+
const UnitVTable path_vtable = {
.suffix = ".path",
.object_size = sizeof(Path),
@@ -745,5 +765,6 @@ const UnitVTable path_vtable = {
.reset_failed = path_reset_failed,
.bus_interface = "org.freedesktop.systemd1.Path",
- .bus_message_handler = bus_path_message_handler
+ .bus_message_handler = bus_path_message_handler,
+ .bus_invalidating_properties = bus_path_invalidating_properties
};
diff --git a/src/path.h b/src/path.h
index 04d43c8..efb6b5e 100644
--- a/src/path.h
+++ b/src/path.h
@@ -69,6 +69,13 @@ static inline bool path_spec_owns_inotify_fd(PathSpec *s, int fd) {
return s->inotify_fd == fd;
}
+typedef enum PathResult {
+ PATH_SUCCESS,
+ PATH_FAILURE_RESOURCES,
+ _PATH_RESULT_MAX,
+ _PATH_RESULT_INVALID = -1
+} PathResult;
+
struct Path {
Unit meta;
@@ -78,11 +85,12 @@ struct Path {
PathState state, deserialized_state;
- bool failure;
bool inotify_triggered;
bool make_directory;
mode_t directory_mode;
+
+ PathResult result;
};
void path_unit_notify(Unit *u, UnitActiveState new_state);
@@ -99,4 +107,7 @@ PathState path_state_from_string(const char *s);
const char* path_type_to_string(PathType i);
PathType path_type_from_string(const char *s);
+const char* path_result_to_string(PathResult i);
+PathResult path_result_from_string(const char *s);
+
#endif
commit e1770af8122a74ee21036e16976cac3f223fe0b2
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 04:47:32 2012 +0100
swap: replace failure boolean by result enum
diff --git a/src/dbus-swap.c b/src/dbus-swap.c
index 5ed33b5..09cd1e8 100644
--- a/src/dbus-swap.c
+++ b/src/dbus-swap.c
@@ -36,6 +36,7 @@
BUS_EXEC_COMMAND_INTERFACE("ExecDeactivate") \
BUS_EXEC_CONTEXT_INTERFACE \
" <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -59,7 +60,8 @@ const char bus_swap_invalidating_properties[] =
"Priority\0"
"ExecActivate\0"
"ExecDeactivate\0"
- "ControlPID\0";
+ "ControlPID\0"
+ "Result\0";
static int bus_swap_append_priority(DBusMessageIter *i, const char *property, void *data) {
Swap *s = data;
@@ -84,12 +86,15 @@ static int bus_swap_append_priority(DBusMessageIter *i, const char *property, vo
return 0;
}
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_swap_append_swap_result, swap_result, SwapResult);
+
static const BusProperty bus_swap_properties[] = {
{ "What", bus_property_append_string, "s", offsetof(Swap, what), true },
{ "Priority", bus_swap_append_priority, "i", 0 },
BUS_EXEC_COMMAND_PROPERTY("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), false),
BUS_EXEC_COMMAND_PROPERTY("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), false),
{ "ControlPID", bus_property_append_pid, "u", offsetof(Swap, control_pid) },
+ { "Result", bus_swap_append_swap_result,"s", offsetof(Swap, result) },
{ NULL, }
};
diff --git a/src/swap.c b/src/swap.c
index b4a5b3c..9c72732 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -90,7 +90,7 @@ static void swap_init(Unit *u) {
s->timer_watch.type = WATCH_INVALID;
- s->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
+ s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
UNIT(s)->ignore_on_isolate = true;
}
@@ -571,6 +571,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sSwap State: %s\n"
+ "%sResult: %s\n"
"%sWhat: %s\n"
"%sPriority: %i\n"
"%sNoAuto: %s\n"
@@ -580,6 +581,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
"%sFrom /proc/swaps: %s\n"
"%sFrom fragment: %s\n",
prefix, swap_state_to_string(s->state),
+ prefix, swap_result_to_string(s->result),
prefix, s->what,
prefix, p->priority,
prefix, yes_no(p->noauto),
@@ -636,33 +638,33 @@ fail:
return r;
}
-static void swap_enter_dead(Swap *s, bool success) {
+static void swap_enter_dead(Swap *s, SwapResult f) {
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SWAP_SUCCESS)
+ s->result = f;
- swap_set_state(s, s->failure ? SWAP_FAILED : SWAP_DEAD);
+ swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
}
-static void swap_enter_active(Swap *s, bool success) {
+static void swap_enter_active(Swap *s, SwapResult f) {
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SWAP_SUCCESS)
+ s->result = f;
swap_set_state(s, SWAP_ACTIVE);
}
-static void swap_enter_signal(Swap *s, SwapState state, bool success) {
+static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) {
int r;
Set *pid_set = NULL;
bool wait_for_exit = false;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SWAP_SUCCESS)
+ s->result = f;
if (s->exec_context.kill_mode != KILL_NONE) {
int sig = (state == SWAP_ACTIVATING_SIGTERM ||
@@ -705,14 +707,14 @@ static void swap_enter_signal(Swap *s, SwapState state, bool success) {
swap_set_state(s, state);
} else
- swap_enter_dead(s, true);
+ swap_enter_dead(s, SWAP_SUCCESS);
return;
fail:
log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
- swap_enter_dead(s, false);
+ swap_enter_dead(s, SWAP_FAILURE_RESOURCES);
if (pid_set)
set_free(pid_set);
@@ -767,17 +769,14 @@ static void swap_enter_activating(Swap *s) {
fail:
log_warning("%s failed to run 'swapon' task: %s", UNIT(s)->id, strerror(-r));
- swap_enter_dead(s, false);
+ swap_enter_dead(s, SWAP_FAILURE_RESOURCES);
}
-static void swap_enter_deactivating(Swap *s, bool success) {
+static void swap_enter_deactivating(Swap *s) {
int r;
assert(s);
- if (!success)
- s->failure = true;
-
s->control_command_id = SWAP_EXEC_DEACTIVATE;
s->control_command = s->exec_command + SWAP_EXEC_DEACTIVATE;
@@ -799,7 +798,7 @@ static void swap_enter_deactivating(Swap *s, bool success) {
fail:
log_warning("%s failed to run 'swapoff' task: %s", UNIT(s)->id, strerror(-r));
- swap_enter_active(s, false);
+ swap_enter_active(s, SWAP_FAILURE_RESOURCES);
}
static int swap_start(Unit *u) {
@@ -822,7 +821,7 @@ static int swap_start(Unit *u) {
assert(s->state == SWAP_DEAD || s->state == SWAP_FAILED);
- s->failure = false;
+ s->result = SWAP_SUCCESS;
swap_enter_activating(s);
return 0;
}
@@ -842,7 +841,7 @@ static int swap_stop(Unit *u) {
assert(s->state == SWAP_ACTIVATING ||
s->state == SWAP_ACTIVE);
- swap_enter_deactivating(s, true);
+ swap_enter_deactivating(s);
return 0;
}
@@ -854,7 +853,7 @@ static int swap_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", swap_state_to_string(s->state));
- unit_serialize_item(u, f, "failure", yes_no(s->failure));
+ unit_serialize_item(u, f, "result", swap_result_to_string(s->result));
if (s->control_pid > 0)
unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
@@ -878,14 +877,14 @@ static int swap_deserialize_item(Unit *u, const char *key, const char *value, FD
log_debug("Failed to parse state value %s", value);
else
s->deserialized_state = state;
- } else if (streq(key, "failure")) {
- int b;
-
- if ((b = parse_boolean(value)) < 0)
- log_debug("Failed to parse failure value %s", value);
- else
- s->failure = b || s->failure;
-
+ } else if (streq(key, "result")) {
+ SwapResult f;
+
+ f = swap_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != SWAP_SUCCESS)
+ s->result = f;
} else if (streq(key, "control-pid")) {
pid_t pid;
@@ -932,7 +931,7 @@ static bool swap_check_gc(Unit *u) {
static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
Swap *s = SWAP(u);
- bool success;
+ SwapResult f;
assert(s);
assert(pid >= 0);
@@ -942,16 +941,28 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
s->control_pid = 0;
- success = is_clean_exit(code, status);
- s->failure = s->failure || !success;
+ if (is_clean_exit(code, status))
+ f = SWAP_SUCCESS;
+ else if (code == CLD_EXITED)
+ f = SWAP_FAILURE_EXIT_CODE;
+ else if (code == CLD_KILLED)
+ f = SWAP_FAILURE_SIGNAL;
+ else if (code == CLD_DUMPED)
+ f = SWAP_FAILURE_CORE_DUMP;
+ else
+ assert_not_reached("Unknown code");
+
+ if (f != SWAP_SUCCESS)
+ s->result = f;
if (s->control_command) {
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
+
s->control_command = NULL;
s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
}
- log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ log_full(f == SWAP_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
"%s swap process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
switch (s->state) {
@@ -960,20 +971,20 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case SWAP_ACTIVATING_SIGTERM:
case SWAP_ACTIVATING_SIGKILL:
- if (success)
- swap_enter_active(s, true);
+ if (f == SWAP_SUCCESS)
+ swap_enter_active(s, f);
else
- swap_enter_dead(s, false);
+ swap_enter_dead(s, f);
break;
case SWAP_DEACTIVATING:
case SWAP_DEACTIVATING_SIGKILL:
case SWAP_DEACTIVATING_SIGTERM:
- if (success)
- swap_enter_dead(s, true);
+ if (f == SWAP_SUCCESS)
+ swap_enter_dead(s, f);
else
- swap_enter_dead(s, false);
+ swap_enter_dead(s, f);
break;
default:
@@ -999,38 +1010,38 @@ static void swap_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
case SWAP_ACTIVATING:
log_warning("%s activation timed out. Stopping.", u->id);
- swap_enter_signal(s, SWAP_ACTIVATING_SIGTERM, false);
+ swap_enter_signal(s, SWAP_ACTIVATING_SIGTERM, SWAP_FAILURE_TIMEOUT);
break;
case SWAP_DEACTIVATING:
log_warning("%s deactivation timed out. Stopping.", u->id);
- swap_enter_signal(s, SWAP_DEACTIVATING_SIGTERM, false);
+ swap_enter_signal(s, SWAP_DEACTIVATING_SIGTERM, SWAP_FAILURE_TIMEOUT);
break;
case SWAP_ACTIVATING_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s activation timed out. Killing.", u->id);
- swap_enter_signal(s, SWAP_ACTIVATING_SIGKILL, false);
+ swap_enter_signal(s, SWAP_ACTIVATING_SIGKILL, SWAP_FAILURE_TIMEOUT);
} else {
log_warning("%s activation timed out. Skipping SIGKILL. Ignoring.", u->id);
- swap_enter_dead(s, false);
+ swap_enter_dead(s, SWAP_FAILURE_TIMEOUT);
}
break;
case SWAP_DEACTIVATING_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s deactivation timed out. Killing.", u->id);
- swap_enter_signal(s, SWAP_DEACTIVATING_SIGKILL, false);
+ swap_enter_signal(s, SWAP_DEACTIVATING_SIGKILL, SWAP_FAILURE_TIMEOUT);
} else {
log_warning("%s deactivation timed out. Skipping SIGKILL. Ignoring.", u->id);
- swap_enter_dead(s, false);
+ swap_enter_dead(s, SWAP_FAILURE_TIMEOUT);
}
break;
case SWAP_ACTIVATING_SIGKILL:
case SWAP_DEACTIVATING_SIGKILL:
log_warning("%s swap process still around after SIGKILL. Ignoring.", u->id);
- swap_enter_dead(s, false);
+ swap_enter_dead(s, SWAP_FAILURE_TIMEOUT);
break;
default:
@@ -1129,7 +1140,7 @@ int swap_fd_event(Manager *m, int events) {
switch (swap->state) {
case SWAP_ACTIVE:
- swap_enter_dead(swap, true);
+ swap_enter_dead(swap, SWAP_SUCCESS);
break;
default:
@@ -1145,7 +1156,7 @@ int swap_fd_event(Manager *m, int events) {
case SWAP_DEAD:
case SWAP_FAILED:
- swap_enter_active(swap, true);
+ swap_enter_active(swap, SWAP_SUCCESS);
break;
default:
@@ -1272,7 +1283,7 @@ static void swap_reset_failed(Unit *u) {
if (s->state == SWAP_FAILED)
swap_set_state(s, SWAP_DEAD);
- s->failure = false;
+ s->result = SWAP_SUCCESS;
}
static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
@@ -1343,6 +1354,17 @@ static const char* const swap_exec_command_table[_SWAP_EXEC_COMMAND_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(swap_exec_command, SwapExecCommand);
+static const char* const swap_result_table[_SWAP_RESULT_MAX] = {
+ [SWAP_SUCCESS] = "success",
+ [SWAP_FAILURE_RESOURCES] = "resources",
+ [SWAP_FAILURE_TIMEOUT] = "timeout",
+ [SWAP_FAILURE_EXIT_CODE] = "exit-code",
+ [SWAP_FAILURE_SIGNAL] = "signal",
+ [SWAP_FAILURE_CORE_DUMP] = "core-dump"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
+
const UnitVTable swap_vtable = {
.suffix = ".swap",
.object_size = sizeof(Swap),
diff --git a/src/swap.h b/src/swap.h
index ea98bc2..62d08da 100644
--- a/src/swap.h
+++ b/src/swap.h
@@ -56,6 +56,17 @@ typedef struct SwapParameters {
bool handle:1;
} SwapParameters;
+typedef enum SwapResult {
+ SWAP_SUCCESS,
+ SWAP_FAILURE_RESOURCES,
+ SWAP_FAILURE_TIMEOUT,
+ SWAP_FAILURE_EXIT_CODE,
+ SWAP_FAILURE_SIGNAL,
+ SWAP_FAILURE_CORE_DUMP,
+ _SWAP_RESULT_MAX,
+ _SWAP_RESULT_INVALID = -1
+} SwapResult;
+
struct Swap {
Unit meta;
@@ -69,13 +80,13 @@ struct Swap {
bool from_proc_swaps:1;
bool from_fragment:1;
- bool failure:1;
-
/* Used while looking for swaps that vanished or got added
* from/to /proc/swaps */
bool is_active:1;
bool just_activated:1;
+ SwapResult result;
+
usec_t timeout_usec;
ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
@@ -111,4 +122,7 @@ SwapState swap_state_from_string(const char *s);
const char* swap_exec_command_to_string(SwapExecCommand i);
SwapExecCommand swap_exec_command_from_string(const char *s);
+const char* swap_result_to_string(SwapResult i);
+SwapResult swap_result_from_string(const char *s);
+
#endif
commit 067d72c9fe698d305a07db17fc5b328e4a17cc8f
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 04:03:21 2012 +0100
timer: convert failure bool into enum
diff --git a/src/automount.c b/src/automount.c
index 507fc25..cf2fb60 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -881,7 +881,7 @@ const UnitVTable automount_vtable = {
.bus_interface = "org.freedesktop.systemd1.Automount",
.bus_message_handler = bus_automount_message_handler,
- .bus_invalidating_properties = bus_automount_invalidating_properties,
+ .bus_invalidating_properties = bus_automount_invalidating_properties,
.shutdown = automount_shutdown
};
diff --git a/src/dbus-timer.c b/src/dbus-timer.c
index 0988b3e..b396aed 100644
--- a/src/dbus-timer.c
+++ b/src/dbus-timer.c
@@ -31,6 +31,7 @@
" <property name=\"Unit\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Timers\" type=\"a(stt)\" access=\"read\"/>\n" \
" <property name=\"NextElapseUSec\" type=\"t\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -51,7 +52,8 @@ const char bus_timer_interface[] _introspect_("Timer") = BUS_TIMER_INTERFACE;
const char bus_timer_invalidating_properties[] =
"Timers\0"
- "NextElapseUSec\0";
+ "NextElapseUSec\0"
+ "Result\0";
static int bus_timer_append_timers(DBusMessageIter *i, const char *property, void *data) {
Timer *p = data;
@@ -113,10 +115,13 @@ static int bus_timer_append_unit(DBusMessageIter *i, const char *property, void
return dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t) ? 0 : -ENOMEM;
}
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_timer_append_timer_result, timer_result, TimerResult);
+
static const BusProperty bus_timer_properties[] = {
{ "Unit", bus_timer_append_unit, "s", 0 },
{ "Timers", bus_timer_append_timers, "a(stt)", 0 },
{ "NextElapseUSec", bus_property_append_usec, "t", offsetof(Timer, next_elapse) },
+ { "Result", bus_timer_append_timer_result,"s", offsetof(Timer, result) },
{ NULL, }
};
diff --git a/src/timer.c b/src/timer.c
index ce7fd6b..e318fee 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -133,8 +133,10 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sTimer State: %s\n"
+ "%sResult: %s\n"
"%sUnit: %s\n",
prefix, timer_state_to_string(t->state),
+ prefix, timer_result_to_string(t->result),
prefix, UNIT_DEREF(t->unit)->id);
LIST_FOREACH(value, v, t->values)
@@ -183,13 +185,13 @@ static int timer_coldplug(Unit *u) {
return 0;
}
-static void timer_enter_dead(Timer *t, bool success) {
+static void timer_enter_dead(Timer *t, TimerResult f) {
assert(t);
- if (!success)
- t->failure = true;
+ if (f != TIMER_SUCCESS)
+ t->result = f;
- timer_set_state(t, t->failure ? TIMER_FAILED : TIMER_DEAD);
+ timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
}
static void timer_enter_waiting(Timer *t, bool initial) {
@@ -273,7 +275,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
fail:
log_warning("%s failed to enter waiting state: %s", UNIT(t)->id, strerror(-r));
- timer_enter_dead(t, false);
+ timer_enter_dead(t, TIMER_FAILURE_RESOURCES);
}
static void timer_enter_running(Timer *t) {
@@ -295,7 +297,7 @@ static void timer_enter_running(Timer *t) {
fail:
log_warning("%s failed to queue unit startup job: %s", UNIT(t)->id, bus_error(&error, r));
- timer_enter_dead(t, false);
+ timer_enter_dead(t, TIMER_FAILURE_RESOURCES);
dbus_error_free(&error);
}
@@ -309,7 +311,7 @@ static int timer_start(Unit *u) {
if (UNIT_DEREF(t->unit)->load_state != UNIT_LOADED)
return -ENOENT;
- t->failure = false;
+ t->result = TIMER_SUCCESS;
timer_enter_waiting(t, true);
return 0;
}
@@ -320,7 +322,7 @@ static int timer_stop(Unit *u) {
assert(t);
assert(t->state == TIMER_WAITING || t->state == TIMER_RUNNING || t->state == TIMER_ELAPSED);
- timer_enter_dead(t, true);
+ timer_enter_dead(t, TIMER_SUCCESS);
return 0;
}
@@ -332,6 +334,7 @@ static int timer_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", timer_state_to_string(t->state));
+ unit_serialize_item(u, f, "result", timer_result_to_string(t->result));
return 0;
}
@@ -351,6 +354,15 @@ static int timer_deserialize_item(Unit *u, const char *key, const char *value, F
log_debug("Failed to parse state value %s", value);
else
t->deserialized_state = state;
+ } else if (streq(key, "result")) {
+ TimerResult f;
+
+ f = timer_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != TIMER_SUCCESS)
+ t->result = f;
+
} else
log_debug("Unknown serialization key '%s'", key);
@@ -443,7 +455,7 @@ static void timer_reset_failed(Unit *u) {
if (t->state == TIMER_FAILED)
timer_set_state(t, TIMER_DEAD);
- t->failure = false;
+ t->result = TIMER_SUCCESS;
}
static const char* const timer_state_table[_TIMER_STATE_MAX] = {
@@ -466,6 +478,13 @@ static const char* const timer_base_table[_TIMER_BASE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
+static const char* const timer_result_table[_TIMER_RESULT_MAX] = {
+ [TIMER_SUCCESS] = "success",
+ [TIMER_FAILURE_RESOURCES] = "resources"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
+
const UnitVTable timer_vtable = {
.suffix = ".timer",
.object_size = sizeof(Timer),
diff --git a/src/timer.h b/src/timer.h
index d5cbc11..f5c5c64 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -56,6 +56,13 @@ typedef struct TimerValue {
bool disabled;
} TimerValue;
+typedef enum TimerResult {
+ TIMER_SUCCESS,
+ TIMER_FAILURE_RESOURCES,
+ _TIMER_RESULT_MAX,
+ _TIMER_RESULT_INVALID = -1
+} TimerResult;
+
struct Timer {
Unit meta;
@@ -67,7 +74,7 @@ struct Timer {
Watch timer_watch;
- bool failure;
+ TimerResult result;
};
void timer_unit_notify(Unit *u, UnitActiveState new_state);
@@ -80,4 +87,7 @@ TimerState timer_state_from_string(const char *s);
const char *timer_base_to_string(TimerBase i);
TimerBase timer_base_from_string(const char *s);
+const char* timer_result_to_string(TimerResult i);
+TimerResult timer_result_from_string(const char *s);
+
#endif
commit 81a5c6d03ef1e43e33bfb5ad006cf883c927a339
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 03:27:25 2012 +0100
automount: convert failure boolean to enum
diff --git a/src/automount.c b/src/automount.c
index aa38492..507fc25 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -288,20 +288,22 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sAutomount State: %s\n"
+ "%sResult: %s\n"
"%sWhere: %s\n"
"%sDirectoryMode: %04o\n",
prefix, automount_state_to_string(a->state),
+ prefix, automount_result_to_string(a->result),
prefix, a->where,
prefix, a->directory_mode);
}
-static void automount_enter_dead(Automount *a, bool success) {
+static void automount_enter_dead(Automount *a, AutomountResult f) {
assert(a);
- if (!success)
- a->failure = true;
+ if (f != AUTOMOUNT_SUCCESS)
+ a->result = f;
- automount_set_state(a, a->failure ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
+ automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
}
static int open_dev_autofs(Manager *m) {
@@ -565,7 +567,7 @@ fail:
repeat_unmout(a->where);
log_error("Failed to initialize automounter: %s", strerror(-r));
- automount_enter_dead(a, false);
+ automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
}
static void automount_enter_runnning(Automount *a) {
@@ -605,7 +607,7 @@ static void automount_enter_runnning(Automount *a) {
return;
fail:
- automount_enter_dead(a, false);
+ automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
dbus_error_free(&error);
}
@@ -624,7 +626,7 @@ static int automount_start(Unit *u) {
if (UNIT_DEREF(a->mount)->load_state != UNIT_LOADED)
return -ENOENT;
- a->failure = false;
+ a->result = AUTOMOUNT_SUCCESS;
automount_enter_waiting(a);
return 0;
}
@@ -636,7 +638,7 @@ static int automount_stop(Unit *u) {
assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
- automount_enter_dead(a, true);
+ automount_enter_dead(a, AUTOMOUNT_SUCCESS);
return 0;
}
@@ -650,7 +652,7 @@ static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", automount_state_to_string(a->state));
- unit_serialize_item(u, f, "failure", yes_no(a->failure));
+ unit_serialize_item(u, f, "result", automount_result_to_string(a->result));
unit_serialize_item_format(u, f, "dev-id", "%u", (unsigned) a->dev_id);
SET_FOREACH(p, a->tokens, i)
@@ -682,13 +684,15 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
log_debug("Failed to parse state value %s", value);
else
a->deserialized_state = state;
- } else if (streq(key, "failure")) {
- int b;
+ } else if (streq(key, "result")) {
+ AutomountResult f;
+
+ f = automount_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != AUTOMOUNT_SUCCESS)
+ a->result = f;
- if ((b = parse_boolean(value)) < 0)
- log_debug("Failed to parse failure value %s", value);
- else
- a->failure = b || a->failure;
} else if (streq(key, "dev-id")) {
unsigned d;
@@ -804,7 +808,7 @@ static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
return;
fail:
- automount_enter_dead(a, false);
+ automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
}
static void automount_shutdown(Manager *m) {
@@ -822,7 +826,7 @@ static void automount_reset_failed(Unit *u) {
if (a->state == AUTOMOUNT_FAILED)
automount_set_state(a, AUTOMOUNT_DEAD);
- a->failure = false;
+ a->result = AUTOMOUNT_SUCCESS;
}
static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
@@ -834,6 +838,13 @@ static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
+static const char* const automount_result_table[_AUTOMOUNT_RESULT_MAX] = {
+ [AUTOMOUNT_SUCCESS] = "success",
+ [AUTOMOUNT_FAILURE_RESOURCES] = "resources"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(automount_result, AutomountResult);
+
const UnitVTable automount_vtable = {
.suffix = ".automount",
.object_size = sizeof(Automount),
@@ -870,6 +881,7 @@ const UnitVTable automount_vtable = {
.bus_interface = "org.freedesktop.systemd1.Automount",
.bus_message_handler = bus_automount_message_handler,
+ .bus_invalidating_properties = bus_automount_invalidating_properties,
.shutdown = automount_shutdown
};
diff --git a/src/automount.h b/src/automount.h
index 8334c97..19baee2 100644
--- a/src/automount.h
+++ b/src/automount.h
@@ -35,6 +35,13 @@ typedef enum AutomountState {
_AUTOMOUNT_STATE_INVALID = -1
} AutomountState;
+typedef enum AutomountResult {
+ AUTOMOUNT_SUCCESS,
+ AUTOMOUNT_FAILURE_RESOURCES,
+ _AUTOMOUNT_RESULT_MAX,
+ _AUTOMOUNT_RESULT_INVALID = -1
+} AutomountResult;
+
struct Automount {
Unit meta;
@@ -51,7 +58,7 @@ struct Automount {
Set *tokens;
- bool failure:1;
+ AutomountResult result;
};
extern const UnitVTable automount_vtable;
@@ -63,4 +70,7 @@ int automount_add_one_mount_link(Automount *a, Mount *m);
const char* automount_state_to_string(AutomountState i);
AutomountState automount_state_from_string(const char *s);
+const char* automount_result_to_string(AutomountResult i);
+AutomountResult automount_result_from_string(const char *s);
+
#endif
diff --git a/src/dbus-automount.c b/src/dbus-automount.c
index 938768b..8e45f81 100644
--- a/src/dbus-automount.c
+++ b/src/dbus-automount.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <errno.h>
+
#include "dbus-unit.h"
#include "dbus-automount.h"
#include "dbus-common.h"
@@ -27,6 +29,7 @@
" <interface name=\"org.freedesktop.systemd1.Automount\">\n" \
" <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -45,9 +48,15 @@
const char bus_automount_interface[] _introspect_("Automount") = BUS_AUTOMOUNT_INTERFACE;
+const char bus_automount_invalidating_properties[] =
+ "Result\0";
+
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_automount_append_automount_result, automount_result, AutomountResult);
+
static const BusProperty bus_automount_properties[] = {
{ "Where", bus_property_append_string, "s", offsetof(Automount, where), true },
{ "DirectoryMode", bus_property_append_mode, "u", offsetof(Automount, directory_mode) },
+ { "Result", bus_automount_append_automount_result, "s", offsetof(Automount, result) },
{ NULL, }
};
diff --git a/src/dbus-automount.h b/src/dbus-automount.h
index 84b573c..2fc8345 100644
--- a/src/dbus-automount.h
+++ b/src/dbus-automount.h
@@ -29,5 +29,6 @@
DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_automount_interface[];
+extern const char bus_automount_invalidating_properties[];
#endif
diff --git a/src/mount.c b/src/mount.c
index 0eba1a5..3411b73 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -750,6 +750,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sMount State: %s\n"
+ "%sResult: %s\n"
"%sWhere: %s\n"
"%sWhat: %s\n"
"%sFile System Type: %s\n"
@@ -759,6 +760,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
"%sFrom fragment: %s\n"
"%sDirectoryMode: %04o\n",
prefix, mount_state_to_string(m->state),
+ prefix, mount_result_to_string(m->result),
prefix, m->where,
prefix, strna(p->what),
prefix, strna(p->fstype),
diff --git a/src/socket.c b/src/socket.c
index f247d09..15a517b 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -407,6 +407,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sSocket State: %s\n"
+ "%sResult: %s\n"
"%sBindIPv6Only: %s\n"
"%sBacklog: %u\n"
"%sSocketMode: %04o\n"
@@ -418,6 +419,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
"%sPassCredentials: %s\n"
"%sTCPCongestion: %s\n",
prefix, socket_state_to_string(s->state),
+ prefix, socket_result_to_string(s->result),
prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
prefix, s->backlog,
prefix, s->socket_mode,
commit 9d2f51788e17355cdc287cc6d23169bef363d72e
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 03:10:56 2012 +0100
mount: replace failure boolean by enum
diff --git a/src/dbus-mount.c b/src/dbus-mount.c
index 17d29d6..35d6ea7 100644
--- a/src/dbus-mount.c
+++ b/src/dbus-mount.c
@@ -39,6 +39,7 @@
BUS_EXEC_CONTEXT_INTERFACE \
" <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -64,7 +65,8 @@ const char bus_mount_invalidating_properties[] =
"ExecMount\0"
"ExecUnmount\0"
"ExecRemount\0"
- "ControlPID\0";
+ "ControlPID\0"
+ "Result\0";
static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
@@ -135,6 +137,8 @@ static int bus_mount_append_type(DBusMessageIter *i, const char *property, void
return 0;
}
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
+
static const BusProperty bus_mount_properties[] = {
{ "Where", bus_property_append_string, "s", offsetof(Mount, where), true },
{ "What", bus_mount_append_what, "s", 0 },
@@ -146,6 +150,7 @@ static const BusProperty bus_mount_properties[] = {
BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
{ "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) },
{ "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) },
+ { "Result", bus_mount_append_mount_result, "s", offsetof(Mount, result) },
{ NULL, }
};
diff --git a/src/mount.c b/src/mount.c
index 965f705..0eba1a5 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -693,8 +693,8 @@ static void mount_set_state(Mount *m, MountState state) {
mount_state_to_string(old_state),
mount_state_to_string(state));
- unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state], !m->reload_failure);
- m->reload_failure = false;
+ unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state], m->reload_result == MOUNT_SUCCESS);
+ m->reload_result = MOUNT_SUCCESS;
}
static int mount_coldplug(Unit *u) {
@@ -815,33 +815,33 @@ fail:
return r;
}
-static void mount_enter_dead(Mount *m, bool success) {
+static void mount_enter_dead(Mount *m, MountResult f) {
assert(m);
- if (!success)
- m->failure = true;
+ if (f != MOUNT_SUCCESS)
+ m->result = f;
- mount_set_state(m, m->failure ? MOUNT_FAILED : MOUNT_DEAD);
+ mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
}
-static void mount_enter_mounted(Mount *m, bool success) {
+static void mount_enter_mounted(Mount *m, MountResult f) {
assert(m);
- if (!success)
- m->failure = true;
+ if (f != MOUNT_SUCCESS)
+ m->result = f;
mount_set_state(m, MOUNT_MOUNTED);
}
-static void mount_enter_signal(Mount *m, MountState state, bool success) {
+static void mount_enter_signal(Mount *m, MountState state, MountResult f) {
int r;
Set *pid_set = NULL;
bool wait_for_exit = false;
assert(m);
- if (!success)
- m->failure = true;
+ if (f != MOUNT_SUCCESS)
+ m->result = f;
if (m->exec_context.kill_mode != KILL_NONE) {
int sig = (state == MOUNT_MOUNTING_SIGTERM ||
@@ -885,9 +885,9 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) {
mount_set_state(m, state);
} else if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
- mount_enter_mounted(m, true);
+ mount_enter_mounted(m, MOUNT_SUCCESS);
else
- mount_enter_dead(m, true);
+ mount_enter_dead(m, MOUNT_SUCCESS);
return;
@@ -895,22 +895,19 @@ fail:
log_warning("%s failed to kill processes: %s", UNIT(m)->id, strerror(-r));
if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_RESOURCES);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_RESOURCES);
if (pid_set)
set_free(pid_set);
}
-static void mount_enter_unmounting(Mount *m, bool success) {
+static void mount_enter_unmounting(Mount *m) {
int r;
assert(m);
- if (!success)
- m->failure = true;
-
m->control_command_id = MOUNT_EXEC_UNMOUNT;
m->control_command = m->exec_command + MOUNT_EXEC_UNMOUNT;
@@ -932,7 +929,7 @@ static void mount_enter_unmounting(Mount *m, bool success) {
fail:
log_warning("%s failed to run 'umount' task: %s", UNIT(m)->id, strerror(-r));
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_RESOURCES);
}
static void mount_enter_mounting(Mount *m) {
@@ -983,7 +980,7 @@ static void mount_enter_mounting(Mount *m) {
fail:
log_warning("%s failed to run 'mount' task: %s", UNIT(m)->id, strerror(-r));
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_RESOURCES);
}
static void mount_enter_mounting_done(Mount *m) {
@@ -992,14 +989,11 @@ static void mount_enter_mounting_done(Mount *m) {
mount_set_state(m, MOUNT_MOUNTING_DONE);
}
-static void mount_enter_remounting(Mount *m, bool success) {
+static void mount_enter_remounting(Mount *m) {
int r;
assert(m);
- if (!success)
- m->failure = true;
-
m->control_command_id = MOUNT_EXEC_REMOUNT;
m->control_command = m->exec_command + MOUNT_EXEC_REMOUNT;
@@ -1051,8 +1045,8 @@ static void mount_enter_remounting(Mount *m, bool success) {
fail:
log_warning("%s failed to run 'remount' task: %s", UNIT(m)->id, strerror(-r));
- m->reload_failure = true;
- mount_enter_mounted(m, true);
+ m->reload_result = MOUNT_FAILURE_RESOURCES;
+ mount_enter_mounted(m, MOUNT_SUCCESS);
}
static int mount_start(Unit *u) {
@@ -1075,7 +1069,9 @@ static int mount_start(Unit *u) {
assert(m->state == MOUNT_DEAD || m->state == MOUNT_FAILED);
- m->failure = false;
+ m->result = MOUNT_SUCCESS;
+ m->reload_result = MOUNT_SUCCESS;
+
mount_enter_mounting(m);
return 0;
}
@@ -1100,7 +1096,7 @@ static int mount_stop(Unit *u) {
m->state == MOUNT_REMOUNTING_SIGTERM ||
m->state == MOUNT_REMOUNTING_SIGKILL);
- mount_enter_unmounting(m, true);
+ mount_enter_unmounting(m);
return 0;
}
@@ -1114,7 +1110,7 @@ static int mount_reload(Unit *u) {
assert(m->state == MOUNT_MOUNTED);
- mount_enter_remounting(m, true);
+ mount_enter_remounting(m);
return 0;
}
@@ -1126,7 +1122,8 @@ static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", mount_state_to_string(m->state));
- unit_serialize_item(u, f, "failure", yes_no(m->failure));
+ unit_serialize_item(u, f, "result", mount_result_to_string(m->result));
+ unit_serialize_item(u, f, "reload-result", mount_result_to_string(m->reload_result));
if (m->control_pid > 0)
unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) m->control_pid);
@@ -1152,13 +1149,23 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
log_debug("Failed to parse state value %s", value);
else
m->deserialized_state = state;
- } else if (streq(key, "failure")) {
- int b;
+ } else if (streq(key, "result")) {
+ MountResult f;
- if ((b = parse_boolean(value)) < 0)
- log_debug("Failed to parse failure value %s", value);
- else
- m->failure = b || m->failure;
+ f = mount_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != MOUNT_SUCCESS)
+ m->result = f;
+
+ } else if (streq(key, "reload-result")) {
+ MountResult f;
+
+ f = mount_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse reload result value %s", value);
+ else if (f != MOUNT_SUCCESS)
+ m->reload_result = f;
} else if (streq(key, "control-pid")) {
pid_t pid;
@@ -1205,7 +1212,7 @@ static bool mount_check_gc(Unit *u) {
static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
Mount *m = MOUNT(u);
- bool success;
+ MountResult f;
assert(m);
assert(pid >= 0);
@@ -1215,16 +1222,28 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
m->control_pid = 0;
- success = is_clean_exit(code, status);
- m->failure = m->failure || !success;
+ if (is_clean_exit(code, status))
+ f = MOUNT_SUCCESS;
+ else if (code == CLD_EXITED)
+ f = MOUNT_FAILURE_EXIT_CODE;
+ else if (code == CLD_KILLED)
+ f = MOUNT_FAILURE_SIGNAL;
+ else if (code == CLD_DUMPED)
+ f = MOUNT_FAILURE_CORE_DUMP;
+ else
+ assert_not_reached("Unknown code");
+
+ if (f != MOUNT_SUCCESS)
+ m->result = f;
if (m->control_command) {
exec_status_exit(&m->control_command->exec_status, &m->exec_context, pid, code, status);
+
m->control_command = NULL;
m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
}
- log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ log_full(f == MOUNT_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
"%s mount process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
/* Note that mount(8) returning and the kernel sending us a
@@ -1241,23 +1260,23 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case MOUNT_MOUNTING_SIGKILL:
case MOUNT_MOUNTING_SIGTERM:
- if (success)
- mount_enter_mounted(m, true);
+ if (f == MOUNT_SUCCESS)
+ mount_enter_mounted(m, f);
else if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, f);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, f);
break;
case MOUNT_REMOUNTING:
case MOUNT_REMOUNTING_SIGKILL:
case MOUNT_REMOUNTING_SIGTERM:
- m->reload_failure = !success;
+ m->reload_result = f;
if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, true);
+ mount_enter_mounted(m, MOUNT_SUCCESS);
else
- mount_enter_dead(m, true);
+ mount_enter_dead(m, MOUNT_SUCCESS);
break;
@@ -1265,12 +1284,12 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case MOUNT_UNMOUNTING_SIGKILL:
case MOUNT_UNMOUNTING_SIGTERM:
- if (success)
- mount_enter_dead(m, true);
+ if (f == MOUNT_SUCCESS)
+ mount_enter_dead(m, f);
else if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, f);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, f);
break;
default:
@@ -1293,59 +1312,59 @@ static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
case MOUNT_MOUNTING:
case MOUNT_MOUNTING_DONE:
log_warning("%s mounting timed out. Stopping.", u->id);
- mount_enter_signal(m, MOUNT_MOUNTING_SIGTERM, false);
+ mount_enter_signal(m, MOUNT_MOUNTING_SIGTERM, MOUNT_FAILURE_TIMEOUT);
break;
case MOUNT_REMOUNTING:
log_warning("%s remounting timed out. Stopping.", u->id);
- m->reload_failure = true;
- mount_enter_mounted(m, true);
+ m->reload_result = MOUNT_FAILURE_TIMEOUT;
+ mount_enter_mounted(m, MOUNT_SUCCESS);
break;
case MOUNT_UNMOUNTING:
log_warning("%s unmounting timed out. Stopping.", u->id);
- mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, false);
+ mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, MOUNT_FAILURE_TIMEOUT);
break;
case MOUNT_MOUNTING_SIGTERM:
if (m->exec_context.send_sigkill) {
log_warning("%s mounting timed out. Killing.", u->id);
- mount_enter_signal(m, MOUNT_MOUNTING_SIGKILL, false);
+ mount_enter_signal(m, MOUNT_MOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT);
} else {
log_warning("%s mounting timed out. Skipping SIGKILL. Ignoring.", u->id);
if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_TIMEOUT);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_TIMEOUT);
}
break;
case MOUNT_REMOUNTING_SIGTERM:
if (m->exec_context.send_sigkill) {
log_warning("%s remounting timed out. Killing.", u->id);
- mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, false);
+ mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT);
} else {
log_warning("%s remounting timed out. Skipping SIGKILL. Ignoring.", u->id);
if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_TIMEOUT);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_TIMEOUT);
}
break;
case MOUNT_UNMOUNTING_SIGTERM:
if (m->exec_context.send_sigkill) {
log_warning("%s unmounting timed out. Killing.", u->id);
- mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, false);
+ mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT);
} else {
log_warning("%s unmounting timed out. Skipping SIGKILL. Ignoring.", u->id);
if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_TIMEOUT);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_TIMEOUT);
}
break;
@@ -1355,9 +1374,9 @@ static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
log_warning("%s mount process still around after SIGKILL. Ignoring.", u->id);
if (m->from_proc_self_mountinfo)
- mount_enter_mounted(m, false);
+ mount_enter_mounted(m, MOUNT_FAILURE_TIMEOUT);
else
- mount_enter_dead(m, false);
+ mount_enter_dead(m, MOUNT_FAILURE_TIMEOUT);
break;
default:
@@ -1720,7 +1739,7 @@ void mount_fd_event(Manager *m, int events) {
switch (mount->state) {
case MOUNT_MOUNTED:
- mount_enter_dead(mount, true);
+ mount_enter_dead(mount, MOUNT_SUCCESS);
break;
default:
@@ -1737,7 +1756,7 @@ void mount_fd_event(Manager *m, int events) {
case MOUNT_DEAD:
case MOUNT_FAILED:
- mount_enter_mounted(mount, true);
+ mount_enter_mounted(mount, MOUNT_SUCCESS);
break;
case MOUNT_MOUNTING:
@@ -1768,7 +1787,8 @@ static void mount_reset_failed(Unit *u) {
if (m->state == MOUNT_FAILED)
mount_set_state(m, MOUNT_DEAD);
- m->failure = false;
+ m->result = MOUNT_SUCCESS;
+ m->reload_result = MOUNT_SUCCESS;
}
static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
@@ -1844,6 +1864,17 @@ static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
+static const char* const mount_result_table[_MOUNT_RESULT_MAX] = {
+ [MOUNT_SUCCESS] = "success",
+ [MOUNT_FAILURE_RESOURCES] = "resources",
+ [MOUNT_FAILURE_TIMEOUT] = "timeout",
+ [MOUNT_FAILURE_EXIT_CODE] = "exit-code",
+ [MOUNT_FAILURE_SIGNAL] = "signal",
+ [MOUNT_FAILURE_CORE_DUMP] = "core-dump"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(mount_result, MountResult);
+
const UnitVTable mount_vtable = {
.suffix = ".mount",
.object_size = sizeof(Mount),
diff --git a/src/mount.h b/src/mount.h
index 730c4c2..9318444 100644
--- a/src/mount.h
+++ b/src/mount.h
@@ -59,6 +59,17 @@ typedef struct MountParameters {
int passno;
} MountParameters;
+typedef enum MountResult {
+ MOUNT_SUCCESS,
+ MOUNT_FAILURE_RESOURCES,
+ MOUNT_FAILURE_TIMEOUT,
+ MOUNT_FAILURE_EXIT_CODE,
+ MOUNT_FAILURE_SIGNAL,
+ MOUNT_FAILURE_CORE_DUMP,
+ _MOUNT_RESULT_MAX,
+ _MOUNT_RESULT_INVALID = -1
+} MountResult;
+
struct Mount {
Unit meta;
@@ -78,8 +89,8 @@ struct Mount {
bool just_mounted:1;
bool just_changed:1;
- bool failure:1;
- bool reload_failure:1;
+ MountResult result;
+ MountResult reload_result;
mode_t directory_mode;
@@ -107,4 +118,7 @@ MountState mount_state_from_string(const char *s);
const char* mount_exec_command_to_string(MountExecCommand i);
MountExecCommand mount_exec_command_from_string(const char *s);
+const char* mount_result_to_string(MountResult i);
+MountResult mount_result_from_string(const char *s);
+
#endif
commit cfc4eb4cbaa3434fac145cbabbd51c5f41bd20a6
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 02:31:54 2012 +0100
socket: replace failure boolean by enum
diff --git a/src/dbus-socket.c b/src/dbus-socket.c
index 995b672..9fef676 100644
--- a/src/dbus-socket.c
+++ b/src/dbus-socket.c
@@ -58,6 +58,7 @@
" <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
" <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n" \
#define INTROSPECTION \
@@ -83,9 +84,11 @@ const char bus_socket_invalidating_properties[] =
"ExecStopPost\0"
"ControlPID\0"
"NAccepted\0"
- "NConnections\0";
+ "NConnections\0"
+ "Result\0";
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_socket_result, socket_result, SocketResult);
static const BusProperty bus_socket_properties[] = {
{ "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", offsetof(Socket, bind_ipv6_only) },
@@ -117,6 +120,7 @@ static const BusProperty bus_socket_properties[] = {
{ "NAccepted", bus_property_append_unsigned, "u", offsetof(Socket, n_accepted) },
{ "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg) },
{ "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize) },
+ { "Result", bus_socket_append_socket_result, "s", offsetof(Socket, result) },
{ NULL, }
};
diff --git a/src/service.c b/src/service.c
index 25ebca0..b6bbfab 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2402,9 +2402,9 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
if (s->status_text)
unit_serialize_item(u, f, "status-text", s->status_text);
- /* There's a minor uncleanliness here: if there are multiple
- * commands attached here, we will start from the first one
- * again */
+ /* FIXME: There's a minor uncleanliness here: if there are
+ * multiple commands attached here, we will start from the
+ * first one again */
if (s->control_command_id >= 0)
unit_serialize_item(u, f, "control-command", service_exec_command_to_string(s->control_command_id));
@@ -2693,7 +2693,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
else if (code == CLD_DUMPED)
f = SERVICE_FAILURE_CORE_DUMP;
else
- f = SERVICE_FAILURE_RESOURCES;
+ assert_not_reached("Unknown code");
if (s->main_pid == pid) {
/* Forking services may occasionally move to a new PID.
diff --git a/src/socket.c b/src/socket.c
index 244b124..f247d09 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1156,23 +1156,23 @@ fail:
return r;
}
-static void socket_enter_dead(Socket *s, bool success) {
+static void socket_enter_dead(Socket *s, SocketResult f) {
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SOCKET_SUCCESS)
+ s->result = f;
- socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD);
+ socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD);
}
-static void socket_enter_signal(Socket *s, SocketState state, bool success);
+static void socket_enter_signal(Socket *s, SocketState state, SocketResult f);
-static void socket_enter_stop_post(Socket *s, bool success) {
+static void socket_enter_stop_post(Socket *s, SocketResult f) {
int r;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SOCKET_SUCCESS)
+ s->result = f;
socket_unwatch_control_pid(s);
@@ -1184,24 +1184,24 @@ static void socket_enter_stop_post(Socket *s, bool success) {
socket_set_state(s, SOCKET_STOP_POST);
} else
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_SUCCESS);
return;
fail:
log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->id, strerror(-r));
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_RESOURCES);
}
-static void socket_enter_signal(Socket *s, SocketState state, bool success) {
+static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
int r;
Set *pid_set = NULL;
bool wait_for_exit = false;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SOCKET_SUCCESS)
+ s->result = f;
if (s->exec_context.kill_mode != KILL_NONE) {
int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
@@ -1243,9 +1243,9 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) {
socket_set_state(s, state);
} else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
- socket_enter_stop_post(s, true);
+ socket_enter_stop_post(s, SOCKET_SUCCESS);
else
- socket_enter_dead(s, true);
+ socket_enter_dead(s, SOCKET_SUCCESS);
return;
@@ -1253,20 +1253,20 @@ fail:
log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
- socket_enter_stop_post(s, false);
+ socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
else
- socket_enter_dead(s, false);
+ socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
if (pid_set)
set_free(pid_set);
}
-static void socket_enter_stop_pre(Socket *s, bool success) {
+static void socket_enter_stop_pre(Socket *s, SocketResult f) {
int r;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SOCKET_SUCCESS)
+ s->result = f;
socket_unwatch_control_pid(s);
@@ -1278,20 +1278,21 @@ static void socket_enter_stop_pre(Socket *s, bool success) {
socket_set_state(s, SOCKET_STOP_PRE);
} else
- socket_enter_stop_post(s, true);
+ socket_enter_stop_post(s, SOCKET_SUCCESS);
return;
fail:
log_warning("%s failed to run 'stop-pre' task: %s", UNIT(s)->id, strerror(-r));
- socket_enter_stop_post(s, false);
+ socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
}
static void socket_enter_listening(Socket *s) {
int r;
assert(s);
- if ((r = socket_watch_fds(s)) < 0) {
+ r = socket_watch_fds(s);
+ if (r < 0) {
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
goto fail;
}
@@ -1300,14 +1301,15 @@ static void socket_enter_listening(Socket *s) {
return;
fail:
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
}
static void socket_enter_start_post(Socket *s) {
int r;
assert(s);
- if ((r = socket_open_fds(s)) < 0) {
+ r = socket_open_fds(s);
+ if (r < 0) {
log_warning("%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r));
goto fail;
}
@@ -1317,7 +1319,8 @@ static void socket_enter_start_post(Socket *s) {
s->control_command_id = SOCKET_EXEC_START_POST;
if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
- if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
+ r = socket_spawn(s, s->control_command, &s->control_pid);
+ if (r < 0) {
log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
goto fail;
}
@@ -1329,7 +1332,7 @@ static void socket_enter_start_post(Socket *s) {
return;
fail:
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
}
static void socket_enter_start_pre(Socket *s) {
@@ -1352,7 +1355,7 @@ static void socket_enter_start_pre(Socket *s) {
fail:
log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
- socket_enter_dead(s, false);
+ socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
}
static void socket_enter_running(Socket *s, int cfd) {
@@ -1376,7 +1379,7 @@ static void socket_enter_running(Socket *s, int cfd) {
r = socket_watch_fds(s);
if (r < 0) {
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
}
}
@@ -1478,7 +1481,7 @@ static void socket_enter_running(Socket *s, int cfd) {
fail:
log_warning("%s failed to queue socket startup job: %s", UNIT(s)->id, bus_error(&error, r));
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
if (cfd >= 0)
close_nointr_nofail(cfd);
@@ -1486,16 +1489,13 @@ fail:
dbus_error_free(&error);
}
-static void socket_run_next(Socket *s, bool success) {
+static void socket_run_next(Socket *s) {
int r;
assert(s);
assert(s->control_command);
assert(s->control_command->command_next);
- if (!success)
- s->failure = true;
-
socket_unwatch_control_pid(s);
s->control_command = s->control_command->command_next;
@@ -1509,11 +1509,11 @@ fail:
log_warning("%s failed to run next task: %s", UNIT(s)->id, strerror(-r));
if (s->state == SOCKET_START_POST)
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
else if (s->state == SOCKET_STOP_POST)
- socket_enter_dead(s, false);
+ socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
else
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_RESOURCES);
}
static int socket_start(Unit *u) {
@@ -1565,7 +1565,7 @@ static int socket_start(Unit *u) {
assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
- s->failure = false;
+ s->result = SOCKET_SUCCESS;
socket_enter_start_pre(s);
return 0;
}
@@ -1588,13 +1588,13 @@ static int socket_stop(Unit *u) {
* kill mode. */
if (s->state == SOCKET_START_PRE ||
s->state == SOCKET_START_POST) {
- socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
+ socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, SOCKET_SUCCESS);
return -EAGAIN;
}
assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
- socket_enter_stop_pre(s, true);
+ socket_enter_stop_pre(s, SOCKET_SUCCESS);
return 0;
}
@@ -1608,7 +1608,7 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
- unit_serialize_item(u, f, "failure", yes_no(s->failure));
+ unit_serialize_item(u, f, "result", socket_result_to_string(s->result));
unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
if (s->control_pid > 0)
@@ -1663,13 +1663,14 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
log_debug("Failed to parse state value %s", value);
else
s->deserialized_state = state;
- } else if (streq(key, "failure")) {
- int b;
+ } else if (streq(key, "result")) {
+ SocketResult f;
- if ((b = parse_boolean(value)) < 0)
- log_debug("Failed to parse failure value %s", value);
- else
- s->failure = b || s->failure;
+ f = socket_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != SOCKET_SUCCESS)
+ s->result = f;
} else if (streq(key, "n-accepted")) {
unsigned k;
@@ -1842,12 +1843,12 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
return;
fail:
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
}
static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
Socket *s = SOCKET(u);
- bool success;
+ SocketResult f;
assert(s);
assert(pid >= 0);
@@ -1857,22 +1858,36 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
s->control_pid = 0;
- success = is_clean_exit(code, status);
+ if (is_clean_exit(code, status))
+ f = SOCKET_SUCCESS;
+ else if (code == CLD_EXITED)
+ f = SOCKET_FAILURE_EXIT_CODE;
+ else if (code == CLD_KILLED)
+ f = SOCKET_FAILURE_SIGNAL;
+ else if (code == CLD_DUMPED)
+ f = SOCKET_FAILURE_CORE_DUMP;
+ else
+ assert_not_reached("Unknown code");
if (s->control_command) {
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
if (s->control_command->ignore)
- success = true;
+ f = SOCKET_SUCCESS;
}
- log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ log_full(f == SOCKET_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
"%s control process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
- s->failure = s->failure || !success;
- if (s->control_command && s->control_command->command_next && success) {
+ if (f != SOCKET_SUCCESS)
+ s->result = f;
+
+ if (s->control_command &&
+ s->control_command->command_next &&
+ f == SOCKET_SUCCESS) {
+
log_debug("%s running next command for state %s", u->id, socket_state_to_string(s->state));
- socket_run_next(s, success);
+ socket_run_next(s);
} else {
s->control_command = NULL;
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
@@ -1885,29 +1900,29 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
switch (s->state) {
case SOCKET_START_PRE:
- if (success)
+ if (f == SOCKET_SUCCESS)
socket_enter_start_post(s);
else
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, f);
break;
case SOCKET_START_POST:
- if (success)
+ if (f == SOCKET_SUCCESS)
socket_enter_listening(s);
else
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, f);
break;
case SOCKET_STOP_PRE:
case SOCKET_STOP_PRE_SIGTERM:
case SOCKET_STOP_PRE_SIGKILL:
- socket_enter_stop_post(s, success);
+ socket_enter_stop_post(s, f);
break;
case SOCKET_STOP_POST:
case SOCKET_FINAL_SIGTERM:
case SOCKET_FINAL_SIGKILL:
- socket_enter_dead(s, success);
+ socket_enter_dead(s, f);
break;
default:
@@ -1930,52 +1945,52 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
case SOCKET_START_PRE:
log_warning("%s starting timed out. Terminating.", u->id);
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_TIMEOUT);
break;
case SOCKET_START_POST:
log_warning("%s starting timed out. Stopping.", u->id);
- socket_enter_stop_pre(s, false);
+ socket_enter_stop_pre(s, SOCKET_FAILURE_TIMEOUT);
break;
case SOCKET_STOP_PRE:
log_warning("%s stopping timed out. Terminating.", u->id);
- socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, SOCKET_FAILURE_TIMEOUT);
break;
case SOCKET_STOP_PRE_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s stopping timed out. Killing.", u->id);
- socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, false);
+ socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, SOCKET_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->id);
- socket_enter_stop_post(s, false);
+ socket_enter_stop_post(s, SOCKET_FAILURE_TIMEOUT);
}
break;
case SOCKET_STOP_PRE_SIGKILL:
log_warning("%s still around after SIGKILL. Ignoring.", u->id);
- socket_enter_stop_post(s, false);
+ socket_enter_stop_post(s, SOCKET_FAILURE_TIMEOUT);
break;
case SOCKET_STOP_POST:
log_warning("%s stopping timed out (2). Terminating.", u->id);
- socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_TIMEOUT);
break;
case SOCKET_FINAL_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s stopping timed out (2). Killing.", u->id);
- socket_enter_signal(s, SOCKET_FINAL_SIGKILL, false);
+ socket_enter_signal(s, SOCKET_FINAL_SIGKILL, SOCKET_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->id);
- socket_enter_dead(s, false);
+ socket_enter_dead(s, SOCKET_FAILURE_TIMEOUT);
}
break;
case SOCKET_FINAL_SIGKILL:
log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->id);
- socket_enter_dead(s, false);
+ socket_enter_dead(s, SOCKET_FAILURE_TIMEOUT);
break;
default:
@@ -2057,7 +2072,7 @@ static void socket_reset_failed(Unit *u) {
if (s->state == SOCKET_FAILED)
socket_set_state(s, SOCKET_DEAD);
- s->failure = false;
+ s->result = SOCKET_SUCCESS;
}
static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
@@ -2133,6 +2148,17 @@ static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
+static const char* const socket_result_table[_SOCKET_RESULT_MAX] = {
+ [SOCKET_SUCCESS] = "success",
+ [SOCKET_FAILURE_RESOURCES] = "resources",
+ [SOCKET_FAILURE_TIMEOUT] = "timeout",
+ [SOCKET_FAILURE_EXIT_CODE] = "exit-code",
+ [SOCKET_FAILURE_SIGNAL] = "signal",
+ [SOCKET_FAILURE_CORE_DUMP] = "core-dump"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
+
const UnitVTable socket_vtable = {
.suffix = ".socket",
.object_size = sizeof(Socket),
diff --git a/src/socket.h b/src/socket.h
index b6df83a..d242796 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -65,6 +65,17 @@ typedef enum SocketType {
_SOCKET_FIFO_INVALID = -1
} SocketType;
+typedef enum SocketResult {
+ SOCKET_SUCCESS,
+ SOCKET_FAILURE_RESOURCES,
+ SOCKET_FAILURE_TIMEOUT,
+ SOCKET_FAILURE_EXIT_CODE,
+ SOCKET_FAILURE_SIGNAL,
+ SOCKET_FAILURE_CORE_DUMP,
+ _SOCKET_RESULT_MAX,
+ _SOCKET_RESULT_INVALID = -1
+} SocketResult;
+
typedef struct SocketPort {
SocketType type;
int fd;
@@ -107,7 +118,7 @@ struct Socket {
mode_t directory_mode;
mode_t socket_mode;
- bool failure;
+ SocketResult result;
bool accept;
@@ -154,4 +165,7 @@ SocketState socket_state_from_string(const char *s);
const char* socket_exec_command_to_string(SocketExecCommand i);
SocketExecCommand socket_exec_command_from_string(const char *s);
+const char* socket_result_to_string(SocketResult i);
+SocketResult socket_result_from_string(const char *s);
+
#endif
commit f42806df7de0f4669c1296ab66a7f8d8784dd0f2
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Feb 3 02:01:35 2012 +0100
service: replace "failure" boolean by enum, and export it
This should give admins more useful hints why a service failed.
diff --git a/src/dbus-service.c b/src/dbus-service.c
index 5d95b37..738dc7b 100644
--- a/src/dbus-service.c
+++ b/src/dbus-service.c
@@ -61,7 +61,8 @@
" <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"FsckPassNo\" type=\"i\" access=\"read\"/>\n" \
- BUS_SERVICE_SYSV_INTERFACE_FRAGMENT \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
+ BUS_SERVICE_SYSV_INTERFACE_FRAGMENT \
" </interface>\n"
#define INTROSPECTION \
@@ -92,11 +93,13 @@ const char bus_service_invalidating_properties[] =
"WatchdogTimestampMonotonic\0"
"MainPID\0"
"ControlPID\0"
- "StatusText\0";
+ "StatusText\0"
+ "Result\0";
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_notify_access, notify_access, NotifyAccess);
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_service_result, service_result, ServiceResult);
static const BusProperty bus_exec_main_status_properties[] = {
{ "ExecMainStartTimestamp", bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.realtime) },
@@ -138,6 +141,7 @@ static const BusProperty bus_service_properties[] = {
{ "SysVPath", bus_property_append_string, "s", offsetof(Service, sysv_path), true },
#endif
{ "FsckPassNo", bus_property_append_int, "i", offsetof(Service, fsck_passno) },
+ { "Result", bus_service_append_service_result,"s", offsetof(Service, result) },
{ NULL, }
};
diff --git a/src/service.c b/src/service.c
index d2a2dfc..25ebca0 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1228,6 +1228,8 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sService State: %s\n"
+ "%sResult: %s\n"
+ "%sReload Result: %s\n"
"%sPermissionsStartOnly: %s\n"
"%sRootDirectoryStartOnly: %s\n"
"%sRemainAfterExit: %s\n"
@@ -1236,6 +1238,8 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
"%sRestart: %s\n"
"%sNotifyAccess: %s\n",
prefix, service_state_to_string(s->state),
+ prefix, service_result_to_string(s->result),
+ prefix, service_result_to_string(s->reload_result),
prefix, yes_no(s->permissions_start_only),
prefix, yes_no(s->root_directory_start_only),
prefix, yes_no(s->remain_after_exit),
@@ -1500,8 +1504,8 @@ static void service_set_state(Service *s, ServiceState state) {
if (old_state != state)
log_debug("%s changed %s -> %s", UNIT(s)->id, service_state_to_string(old_state), service_state_to_string(state));
- unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], !s->reload_failure);
- s->reload_failure = false;
+ unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], s->reload_result == SERVICE_SUCCESS);
+ s->reload_result = SERVICE_SUCCESS;
}
static int service_coldplug(Unit *u) {
@@ -1790,28 +1794,28 @@ static int cgroup_good(Service *s) {
return !r;
}
-static void service_enter_dead(Service *s, bool success, bool allow_restart) {
+static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) {
int r;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
if (allow_restart &&
!s->forbid_restart &&
(s->restart == SERVICE_RESTART_ALWAYS ||
- (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure) ||
- (s->restart == SERVICE_RESTART_ON_FAILURE && s->failure) ||
- (s->restart == SERVICE_RESTART_ON_ABORT && s->failure &&
- (s->main_exec_status.code == CLD_KILLED ||
- s->main_exec_status.code == CLD_DUMPED)))) {
+ (s->restart == SERVICE_RESTART_ON_SUCCESS && s->result == SERVICE_SUCCESS) ||
+ (s->restart == SERVICE_RESTART_ON_FAILURE && s->result != SERVICE_SUCCESS) ||
+ (s->restart == SERVICE_RESTART_ON_ABORT && (s->result == SERVICE_FAILURE_SIGNAL ||
+ s->result == SERVICE_FAILURE_CORE_DUMP)))) {
- if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
+ r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch);
+ if (r < 0)
goto fail;
service_set_state(s, SERVICE_AUTO_RESTART);
} else
- service_set_state(s, s->failure ? SERVICE_FAILED : SERVICE_DEAD);
+ service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD);
s->forbid_restart = false;
@@ -1819,17 +1823,17 @@ static void service_enter_dead(Service *s, bool success, bool allow_restart) {
fail:
log_warning("%s failed to run install restart timer: %s", UNIT(s)->id, strerror(-r));
- service_enter_dead(s, false, false);
+ service_enter_dead(s, SERVICE_FAILURE_RESOURCES, false);
}
-static void service_enter_signal(Service *s, ServiceState state, bool success);
+static void service_enter_signal(Service *s, ServiceState state, ServiceResult f);
-static void service_enter_stop_post(Service *s, bool success) {
+static void service_enter_stop_post(Service *s, ServiceResult f) {
int r;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
service_unwatch_control_pid(s);
@@ -1850,24 +1854,24 @@ static void service_enter_stop_post(Service *s, bool success) {
service_set_state(s, SERVICE_STOP_POST);
} else
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, true);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_SUCCESS);
return;
fail:
log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->id, strerror(-r));
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
}
-static void service_enter_signal(Service *s, ServiceState state, bool success) {
+static void service_enter_signal(Service *s, ServiceState state, ServiceResult f) {
int r;
Set *pid_set = NULL;
bool wait_for_exit = false;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
if (s->exec_context.kill_mode != KILL_NONE) {
int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
@@ -1920,9 +1924,9 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) {
service_set_state(s, state);
} else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
- service_enter_stop_post(s, true);
+ service_enter_stop_post(s, SERVICE_SUCCESS);
else
- service_enter_dead(s, true, true);
+ service_enter_dead(s, SERVICE_SUCCESS, true);
return;
@@ -1930,21 +1934,21 @@ fail:
log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
- service_enter_stop_post(s, false);
+ service_enter_stop_post(s, SERVICE_FAILURE_RESOURCES);
else
- service_enter_dead(s, false, true);
+ service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
if (pid_set)
set_free(pid_set);
}
-static void service_enter_stop(Service *s, bool success) {
+static void service_enter_stop(Service *s, ServiceResult f) {
int r;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
service_unwatch_control_pid(s);
@@ -1964,21 +1968,21 @@ static void service_enter_stop(Service *s, bool success) {
service_set_state(s, SERVICE_STOP);
} else
- service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_SUCCESS);
return;
fail:
log_warning("%s failed to run 'stop' task: %s", UNIT(s)->id, strerror(-r));
- service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
}
-static void service_enter_running(Service *s, bool success) {
+static void service_enter_running(Service *s, ServiceResult f) {
int main_pid_ok, cgroup_ok;
assert(s);
- if (!success)
- s->failure = true;
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
main_pid_ok = main_pid_good(s);
cgroup_ok = cgroup_good(s);
@@ -1989,7 +1993,7 @@ static void service_enter_running(Service *s, bool success) {
else if (s->remain_after_exit)
service_set_state(s, SERVICE_EXITED);
else
- service_enter_stop(s, true);
+ service_enter_stop(s, SERVICE_SUCCESS);
}
static void service_enter_start_post(Service *s) {
@@ -2014,13 +2018,13 @@ static void service_enter_start_post(Service *s) {
service_set_state(s, SERVICE_START_POST);
} else
- service_enter_running(s, true);
+ service_enter_running(s, SERVICE_SUCCESS);
return;
fail:
log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_RESOURCES);
}
static void service_enter_start(Service *s) {
@@ -2101,7 +2105,7 @@ static void service_enter_start(Service *s) {
fail:
log_warning("%s failed to run 'start' task: %s", UNIT(s)->id, strerror(-r));
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
}
static void service_enter_start_pre(Service *s) {
@@ -2138,7 +2142,7 @@ static void service_enter_start_pre(Service *s) {
fail:
log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
- service_enter_dead(s, false, true);
+ service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
}
static void service_enter_restart(Service *s) {
@@ -2155,7 +2159,7 @@ static void service_enter_restart(Service *s) {
goto fail;
}
- service_enter_dead(s, true, false);
+ service_enter_dead(s, SERVICE_SUCCESS, false);
if ((r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(s), JOB_FAIL, false, &error, NULL)) < 0)
goto fail;
@@ -2165,7 +2169,7 @@ static void service_enter_restart(Service *s) {
fail:
log_warning("%s failed to schedule restart job: %s", UNIT(s)->id, bus_error(&error, -r));
- service_enter_dead(s, false, false);
+ service_enter_dead(s, SERVICE_FAILURE_RESOURCES, false);
dbus_error_free(&error);
}
@@ -2193,26 +2197,23 @@ static void service_enter_reload(Service *s) {
service_set_state(s, SERVICE_RELOAD);
} else
- service_enter_running(s, true);
+ service_enter_running(s, SERVICE_SUCCESS);
return;
fail:
log_warning("%s failed to run 'reload' task: %s", UNIT(s)->id, strerror(-r));
- s->reload_failure = true;
- service_enter_running(s, true);
+ s->reload_result = SERVICE_FAILURE_RESOURCES;
+ service_enter_running(s, SERVICE_SUCCESS);
}
-static void service_run_next_control(Service *s, bool success) {
+static void service_run_next_control(Service *s) {
int r;
assert(s);
assert(s->control_command);
assert(s->control_command->command_next);
- if (!success)
- s->failure = true;
-
assert(s->control_command_id != SERVICE_EXEC_START);
s->control_command = s->control_command->command_next;
@@ -2236,19 +2237,19 @@ fail:
log_warning("%s failed to run next control task: %s", UNIT(s)->id, strerror(-r));
if (s->state == SERVICE_START_PRE)
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
else if (s->state == SERVICE_STOP)
- service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
else if (s->state == SERVICE_STOP_POST)
- service_enter_dead(s, false, true);
+ service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
else if (s->state == SERVICE_RELOAD) {
- s->reload_failure = true;
- service_enter_running(s, true);
+ s->reload_result = SERVICE_FAILURE_RESOURCES;
+ service_enter_running(s, SERVICE_SUCCESS);
} else
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_RESOURCES);
}
-static void service_run_next_main(Service *s, bool success) {
+static void service_run_next_main(Service *s) {
pid_t pid;
int r;
@@ -2257,9 +2258,6 @@ static void service_run_next_main(Service *s, bool success) {
assert(s->main_command->command_next);
assert(s->type == SERVICE_ONESHOT);
- if (!success)
- s->failure = true;
-
s->main_command = s->main_command->command_next;
service_unwatch_main_pid(s);
@@ -2280,7 +2278,7 @@ static void service_run_next_main(Service *s, bool success) {
fail:
log_warning("%s failed to run next main task: %s", UNIT(s)->id, strerror(-r));
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_RESOURCES);
}
static int service_start(Unit *u) {
@@ -2312,7 +2310,8 @@ static int service_start(Unit *u) {
return -ECANCELED;
}
- s->failure = false;
+ s->result = SERVICE_SUCCESS;
+ s->reload_result = SERVICE_SUCCESS;
s->main_pid_known = false;
s->main_pid_alien = false;
s->forbid_restart = false;
@@ -2351,14 +2350,14 @@ static int service_stop(Unit *u) {
s->state == SERVICE_START ||
s->state == SERVICE_START_POST ||
s->state == SERVICE_RELOAD) {
- service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_SUCCESS);
return 0;
}
assert(s->state == SERVICE_RUNNING ||
s->state == SERVICE_EXITED);
- service_enter_stop(s, true);
+ service_enter_stop(s, SERVICE_SUCCESS);
return 0;
}
@@ -2389,7 +2388,8 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", service_state_to_string(s->state));
- unit_serialize_item(u, f, "failure", yes_no(s->failure));
+ unit_serialize_item(u, f, "result", service_result_to_string(s->result));
+ unit_serialize_item(u, f, "reload-result", service_result_to_string(s->reload_result));
if (s->control_pid > 0)
unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
@@ -2448,13 +2448,24 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
log_debug("Failed to parse state value %s", value);
else
s->deserialized_state = state;
- } else if (streq(key, "failure")) {
- int b;
+ } else if (streq(key, "result")) {
+ ServiceResult f;
+
+ f = service_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != SERVICE_SUCCESS)
+ s->result = f;
+
+ } else if (streq(key, "reload-result")) {
+ ServiceResult f;
+
+ f = service_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse reload result value %s", value);
+ else if (f != SERVICE_SUCCESS)
+ s->reload_result = f;
- if ((b = parse_boolean(value)) < 0)
- log_debug("Failed to parse failure value %s", value);
- else
- s->failure = b || s->failure;
} else if (streq(key, "control-pid")) {
pid_t pid;
@@ -2589,7 +2600,7 @@ static int service_retry_pid_file(Service *s) {
service_unwatch_pid_file(s);
- service_enter_running(s, true);
+ service_enter_running(s, SERVICE_SUCCESS);
return 0;
}
@@ -2663,20 +2674,26 @@ static void service_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
return;
fail:
service_unwatch_pid_file(s);
- service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
}
static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
Service *s = SERVICE(u);
- bool success;
+ ServiceResult f;
assert(s);
assert(pid >= 0);
- if (!UNIT(s)->fragment_path)
- success = is_clean_exit_lsb(code, status);
+ if (UNIT(s)->fragment_path ? is_clean_exit(code, status) : is_clean_exit_lsb(code, status))
+ f = SERVICE_SUCCESS;
+ else if (code == CLD_EXITED)
+ f = SERVICE_FAILURE_EXIT_CODE;
+ else if (code == CLD_KILLED)
+ f = SERVICE_FAILURE_SIGNAL;
+ else if (code == CLD_DUMPED)
+ f = SERVICE_FAILURE_CORE_DUMP;
else
- success = is_clean_exit(code, status);
+ f = SERVICE_FAILURE_RESOURCES;
if (s->main_pid == pid) {
/* Forking services may occasionally move to a new PID.
@@ -2696,22 +2713,24 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
s->main_command->exec_status = s->main_exec_status;
if (s->main_command->ignore)
- success = true;
+ f = SERVICE_SUCCESS;
}
- log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ log_full(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
"%s: main process exited, code=%s, status=%i", u->id, sigchld_code_to_string(code), status);
- s->failure = s->failure || !success;
+
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
if (s->main_command &&
s->main_command->command_next &&
- success) {
+ f == SERVICE_SUCCESS) {
/* There is another command to *
* execute, so let's do that. */
log_debug("%s running next main command for state %s", u->id, service_state_to_string(s->state));
- service_run_next_main(s, success);
+ service_run_next_main(s);
} else {
@@ -2731,10 +2750,10 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case SERVICE_START:
if (s->type == SERVICE_ONESHOT) {
/* This was our main goal, so let's go on */
- if (success)
+ if (f == SERVICE_SUCCESS)
service_enter_start_post(s);
else
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
break;
} else {
assert(s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY);
@@ -2743,14 +2762,14 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
}
case SERVICE_RUNNING:
- service_enter_running(s, success);
+ service_enter_running(s, f);
break;
case SERVICE_STOP_SIGTERM:
case SERVICE_STOP_SIGKILL:
if (!control_pid_good(s))
- service_enter_stop_post(s, success);
+ service_enter_stop_post(s, f);
/* If there is still a control process, wait for that first */
break;
@@ -2768,22 +2787,24 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
if (s->control_command->ignore)
- success = true;
+ f = SERVICE_SUCCESS;
}
- log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ log_full(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
"%s: control process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
- s->failure = s->failure || !success;
+
+ if (f != SERVICE_SUCCESS)
+ s->result = f;
if (s->control_command &&
s->control_command->command_next &&
- success) {
+ f == SERVICE_SUCCESS) {
/* There is another command to *
* execute, so let's do that. */
log_debug("%s running next control command for state %s", u->id, service_state_to_string(s->state));
- service_run_next_control(s, success);
+ service_run_next_control(s);
} else {
/* No further commands for this step, so let's
@@ -2797,30 +2818,34 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
switch (s->state) {
case SERVICE_START_PRE:
- if (success)
+ if (f == SERVICE_SUCCESS)
service_enter_start(s);
else
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
break;
case SERVICE_START:
assert(s->type == SERVICE_FORKING);
- if (!success) {
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ if (f != SERVICE_SUCCESS) {
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
break;
}
if (s->pid_file) {
+ bool has_start_post;
+ int r;
+
/* Let's try to load the pid file here if we can.
* The PID file might actually be created by a START_POST
* script. In that case don't worry if the loading fails. */
- bool has_start_post = !!s->exec_command[SERVICE_EXEC_START_POST];
- int r = service_load_pid_file(s, !has_start_post);
+
+ has_start_post = !!s->exec_command[SERVICE_EXEC_START_POST];
+ r = service_load_pid_file(s, !has_start_post);
if (!has_start_post && r < 0) {
r = service_demand_pid_file(s);
if (r < 0 || !cgroup_good(s))
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
break;
}
} else
@@ -2830,43 +2855,45 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
break;
case SERVICE_START_POST:
- if (!success) {
- service_enter_stop(s, false);
+ if (f != SERVICE_SUCCESS) {
+ service_enter_stop(s, f);
break;
}
if (s->pid_file) {
- int r = service_load_pid_file(s, true);
+ int r;
+
+ r = service_load_pid_file(s, true);
if (r < 0) {
r = service_demand_pid_file(s);
if (r < 0 || !cgroup_good(s))
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_RESOURCES);
break;
}
} else
service_search_main_pid(s);
- service_enter_running(s, true);
+ service_enter_running(s, SERVICE_SUCCESS);
break;
case SERVICE_RELOAD:
- if (success) {
+ if (f == SERVICE_SUCCESS) {
service_load_pid_file(s, true);
service_search_main_pid(s);
}
- s->reload_failure = !success;
- service_enter_running(s, true);
+ s->reload_result = f;
+ service_enter_running(s, SERVICE_SUCCESS);
break;
case SERVICE_STOP:
- service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
break;
case SERVICE_STOP_SIGTERM:
case SERVICE_STOP_SIGKILL:
if (main_pid_good(s) <= 0)
- service_enter_stop_post(s, success);
+ service_enter_stop_post(s, f);
/* If there is still a service
* process around, wait until
@@ -2876,7 +2903,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case SERVICE_STOP_POST:
case SERVICE_FINAL_SIGTERM:
case SERVICE_FINAL_SIGKILL:
- service_enter_dead(s, success, true);
+ service_enter_dead(s, f, true);
break;
default:
@@ -2902,32 +2929,32 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
case SERVICE_START_PRE:
case SERVICE_START:
log_warning("%s operation timed out. Terminating.", u->id);
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_TIMEOUT);
break;
case SERVICE_START_POST:
log_warning("%s operation timed out. Stopping.", u->id);
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_TIMEOUT);
break;
case SERVICE_RELOAD:
log_warning("%s operation timed out. Stopping.", u->id);
- s->reload_failure = true;
- service_enter_running(s, true);
+ s->reload_result = SERVICE_FAILURE_TIMEOUT;
+ service_enter_running(s, SERVICE_SUCCESS);
break;
case SERVICE_STOP:
log_warning("%s stopping timed out. Terminating.", u->id);
- service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_TIMEOUT);
break;
case SERVICE_STOP_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s stopping timed out. Killing.", u->id);
- service_enter_signal(s, SERVICE_STOP_SIGKILL, false);
+ service_enter_signal(s, SERVICE_STOP_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out. Skipping SIGKILL.", u->id);
- service_enter_stop_post(s, false);
+ service_enter_stop_post(s, SERVICE_FAILURE_TIMEOUT);
}
break;
@@ -2938,28 +2965,28 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
* weirded out and continue */
log_warning("%s still around after SIGKILL. Ignoring.", u->id);
- service_enter_stop_post(s, false);
+ service_enter_stop_post(s, SERVICE_FAILURE_TIMEOUT);
break;
case SERVICE_STOP_POST:
log_warning("%s stopping timed out (2). Terminating.", u->id);
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_TIMEOUT);
break;
case SERVICE_FINAL_SIGTERM:
if (s->exec_context.send_sigkill) {
log_warning("%s stopping timed out (2). Killing.", u->id);
- service_enter_signal(s, SERVICE_FINAL_SIGKILL, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out (2). Skipping SIGKILL. Entering failed mode.", u->id);
- service_enter_dead(s, false, true);
+ service_enter_dead(s, SERVICE_FAILURE_TIMEOUT, false);
}
break;
case SERVICE_FINAL_SIGKILL:
log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->id);
- service_enter_dead(s, false, true);
+ service_enter_dead(s, SERVICE_FAILURE_TIMEOUT, true);
break;
case SERVICE_AUTO_RESTART:
@@ -2995,28 +3022,29 @@ static void service_cgroup_notify_event(Unit *u) {
log_warning("%s never wrote its PID file. Failing.", UNIT(s)->id);
service_unwatch_pid_file(s);
if (s->state == SERVICE_START)
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
else
- service_enter_stop(s, false);
+ service_enter_stop(s, SERVICE_FAILURE_RESOURCES);
}
break;
case SERVICE_RUNNING:
- service_enter_running(s, true);
+ /* service_enter_running() will figure out what to do */
+ service_enter_running(s, SERVICE_SUCCESS);
break;
case SERVICE_STOP_SIGTERM:
case SERVICE_STOP_SIGKILL:
if (main_pid_good(s) <= 0 && !control_pid_good(s))
- service_enter_stop_post(s, true);
+ service_enter_stop_post(s, SERVICE_SUCCESS);
break;
case SERVICE_FINAL_SIGTERM:
case SERVICE_FINAL_SIGKILL:
if (main_pid_good(s) <= 0 && !control_pid_good(s))
- service_enter_dead(s, true, true);
+ service_enter_dead(s, SERVICE_SUCCESS, SERVICE_SUCCESS);
break;
@@ -3361,7 +3389,7 @@ static void service_bus_name_owner_change(
/* service_enter_running() will figure out what to
* do */
if (s->state == SERVICE_RUNNING)
- service_enter_running(s, true);
+ service_enter_running(s, SERVICE_SUCCESS);
else if (s->state == SERVICE_START && new_owner)
service_enter_start_post(s);
@@ -3433,7 +3461,8 @@ static void service_reset_failed(Unit *u) {
if (s->state == SERVICE_FAILED)
service_set_state(s, SERVICE_DEAD);
- s->failure = false;
+ s->result = SERVICE_SUCCESS;
+ s->reload_result = SERVICE_SUCCESS;
}
static bool service_need_daemon_reload(Unit *u) {
@@ -3576,6 +3605,17 @@ static const char* const notify_access_table[_NOTIFY_ACCESS_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);
+static const char* const service_result_table[_SERVICE_RESULT_MAX] = {
+ [SERVICE_SUCCESS] = "success",
+ [SERVICE_FAILURE_RESOURCES] = "resources",
+ [SERVICE_FAILURE_TIMEOUT] = "timeout",
+ [SERVICE_FAILURE_EXIT_CODE] = "exit-code",
+ [SERVICE_FAILURE_SIGNAL] = "signal",
+ [SERVICE_FAILURE_CORE_DUMP] = "core-dump"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(service_result, ServiceResult);
+
const UnitVTable service_vtable = {
.suffix = ".service",
.object_size = sizeof(Service),
diff --git a/src/service.h b/src/service.h
index dbae68b..b1e8b90 100644
--- a/src/service.h
+++ b/src/service.h
@@ -88,6 +88,17 @@ typedef enum NotifyAccess {
_NOTIFY_ACCESS_INVALID = -1
} NotifyAccess;
+typedef enum ServiceResult {
+ SERVICE_SUCCESS,
+ SERVICE_FAILURE_RESOURCES,
+ SERVICE_FAILURE_TIMEOUT,
+ SERVICE_FAILURE_EXIT_CODE,
+ SERVICE_FAILURE_SIGNAL,
+ SERVICE_FAILURE_CORE_DUMP,
+ _SERVICE_RESULT_MAX,
+ _SERVICE_RESULT_INVALID = -1
+} ServiceResult;
+
struct Service {
Unit meta;
@@ -132,8 +143,8 @@ struct Service {
bool guess_main_pid;
/* If we shut down, remember why */
- bool failure:1;
- bool reload_failure:1;
+ ServiceResult result;
+ ServiceResult reload_result;
bool main_pid_known:1;
bool main_pid_alien:1;
@@ -186,4 +197,7 @@ ServiceExecCommand service_exec_command_from_string(const char *s);
const char* notify_access_to_string(NotifyAccess i);
NotifyAccess notify_access_from_string(const char *s);
+const char* service_result_to_string(ServiceResult i);
+ServiceResult service_result_from_string(const char *s);
+
#endif
diff --git a/src/systemctl.c b/src/systemctl.c
index 5ad81fd..12264f8 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -1437,9 +1437,9 @@ static int wait_for_jobs(DBusConnection *bus, Set *s) {
else if (streq(d.result, "canceled"))
log_error("Job canceled.");
else if (streq(d.result, "dependency"))
- log_error("A dependency job failed. See system logs for details.");
+ log_error("A dependency job failed. See system journal for details.");
else if (!streq(d.result, "done") && !streq(d.result, "skipped"))
- log_error("Job failed. See system logs and 'systemctl status' for details.");
+ log_error("Job failed. See system journal and 'systemctl status' for details.");
}
if (streq_ptr(d.result, "timeout"))
@@ -2003,6 +2003,7 @@ typedef struct UnitStatusInfo {
const char *default_control_group;
const char *load_error;
+ const char *result;
usec_t inactive_exit_timestamp;
usec_t inactive_exit_timestamp_monotonic;
@@ -2106,6 +2107,9 @@ static void print_status_info(UnitStatusInfo *i) {
strna(i->active_state),
off);
+ if (!isempty(i->result) && !streq(i->result, "success"))
+ printf(" (Result: %s)", i->result);
+
timestamp = (streq_ptr(i->active_state, "active") ||
streq_ptr(i->active_state, "reloading")) ? i->active_enter_timestamp :
(streq_ptr(i->active_state, "inactive") ||
@@ -2325,6 +2329,8 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
i->following = s;
else if (streq(name, "UnitFileState"))
i->unit_file_state = s;
+ else if (streq(name, "Result"))
+ i->result = s;
}
break;
commit 680a1dbc354b2f437b4e06e27d4c43217977efdf
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Feb 2 02:21:59 2012 +0100
update TODO
diff --git a/TODO b/TODO
index a7081d8..74a36a1 100644
--- a/TODO
+++ b/TODO
@@ -21,6 +21,8 @@ Bugfixes:
Features:
+* dbus: in fedora, make the machine a symlink to /etc/machine-id
+
* journald: reuse XZ context
* logind: add equivalent to sd_pid_get_owner_uid() to the D-Bus API
More information about the systemd-commits
mailing list