summaryrefslogtreecommitdiff
path: root/src/core/job.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-25 22:33:33 +0100
committerLennart Poettering <lennart@poettering.net>2013-02-09 02:20:42 +0100
commitc65eb8365344eeb72ee2c0b333ab54d925263b3f (patch)
treed401f8fb3fc9bd51af74e3a6ddfec571c85f6b5c /src/core/job.c
parent97b5f608182773d7ef9ca18913085b3a3eccd943 (diff)
shutdown: issue a sync() as soon as shutdown.target is queued
Diffstat (limited to 'src/core/job.c')
-rw-r--r--src/core/job.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core/job.c b/src/core/job.c
index 6a03d17aa8..2bafbc1589 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -34,6 +34,9 @@
#include "load-dropin.h"
#include "log.h"
#include "dbus-job.h"
+#include "special.h"
+#include "sync.h"
+#include "virt.h"
JobBusClient* job_bus_client_new(DBusConnection *connection, const char *name) {
JobBusClient *cl;
@@ -1061,6 +1064,29 @@ int job_coldplug(Job *j) {
return 0;
}
+void job_shutdown_magic(Job *j) {
+ assert(j);
+
+ /* The shutdown target gets some special treatment here: we
+ * tell the kernel to begin with flushing its disk caches, to
+ * optimize shutdown time a bit. Ideally we wouldn't hardcode
+ * this magic into PID 1. However all other processes aren't
+ * options either since they'd exit much sooner than PID 1 and
+ * asynchronous sync() would cause their exit to be
+ * delayed. */
+
+ if (!unit_has_name(j->unit, SPECIAL_SHUTDOWN_TARGET))
+ return;
+
+ if (j->type != JOB_START)
+ return;
+
+ if (detect_container(NULL) > 0)
+ return;
+
+ asynchronous_sync();
+}
+
static const char* const job_state_table[_JOB_STATE_MAX] = {
[JOB_WAITING] = "waiting",
[JOB_RUNNING] = "running"