summaryrefslogtreecommitdiff
path: root/src/core/service.c
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2014-03-25 14:15:45 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-21 09:58:53 -0400
commitefe6e7d33a9feb0b647c77862016284457895fa6 (patch)
tree1f68e82474c08a7510b25f0d8226ec11143edaca /src/core/service.c
parentc5220a940d00fc2520c702104939d0a4cf637254 (diff)
service: add support for reboot argument when triggered by StartLimitAction=
When rebooting with systemctl, an optional argument can be passed to the reboot system call. This makes it possible the specify the argument in a service file and use it when the service triggers a restart. This is useful to distinguish between manual reboots and reboots caused by failing services.
Diffstat (limited to 'src/core/service.c')
-rw-r--r--src/core/service.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/service.c b/src/core/service.c
index ae3695aff2..4ebce6aa95 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -24,6 +24,8 @@
#include <dirent.h>
#include <unistd.h>
#include <sys/reboot.h>
+#include <linux/reboot.h>
+#include <sys/syscall.h>
#include "manager.h"
#include "unit.h"
@@ -300,6 +302,9 @@ static void service_done(Unit *u) {
free(s->status_text);
s->status_text = NULL;
+ free(s->reboot_arg);
+ s->reboot_arg = NULL;
+
s->exec_runtime = exec_runtime_unref(s->exec_runtime);
exec_command_free_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX);
s->control_command = NULL;
@@ -2372,6 +2377,10 @@ static int service_start_limit_test(Service *s) {
if (ratelimit_test(&s->start_limit))
return 0;
+ if (s->start_limit_action == SERVICE_START_LIMIT_REBOOT ||
+ s->start_limit_action == SERVICE_START_LIMIT_REBOOT_FORCE)
+ update_reboot_param_file(s->reboot_arg);
+
switch (s->start_limit_action) {
case SERVICE_START_LIMIT_NONE:
@@ -2407,6 +2416,13 @@ static int service_start_limit_test(Service *s) {
log_warning_unit(UNIT(s)->id,
"%s start request repeated too quickly, rebooting immediately.", UNIT(s)->id);
sync();
+ if (s->reboot_arg) {
+ log_info("Rebooting with argument '%s'.", s->reboot_arg);
+ syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
+ LINUX_REBOOT_CMD_RESTART2, s->reboot_arg);
+ }
+
+ log_info("Rebooting.");
reboot(RB_AUTOBOOT);
break;