]> err.no Git - systemd/commitdiff
unit: serialize jobs in addition to units
authorLennart Poettering <lennart@poettering.net>
Thu, 3 Jun 2010 12:26:50 +0000 (14:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Jun 2010 12:27:02 +0000 (14:27 +0200)
src/manager.c
src/unit.c
src/unit.h

index a71150d0a93e46ec4695d3afbc3a540beb2c0d6b..28bc4c3b7001ce6d71488214934d3522c0442764 100644 (file)
@@ -625,9 +625,8 @@ int manager_coldplug(Manager *m) {
                 if (u->meta.id != k)
                         continue;
 
-                if (UNIT_VTABLE(u)->coldplug)
-                        if ((q = UNIT_VTABLE(u)->coldplug(u)) < 0)
-                                r = q;
+                if ((q = unit_coldplug(u)) < 0)
+                        r = q;
         }
 
         return r;
index 57b3b77954adc8456d60ff3e8a8a9257221a7b5f..bb2b8c2fe010cb917b2f1df95b622528b332cf81 100644 (file)
@@ -67,6 +67,7 @@ Unit *unit_new(Manager *m) {
 
         u->meta.manager = m;
         u->meta.type = _UNIT_TYPE_INVALID;
+        u->meta.deserialized_job = _JOB_TYPE_INVALID;
 
         return u;
 }
@@ -1794,6 +1795,9 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds) {
         if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0)
                 return r;
 
+        if (u->meta.job)
+                unit_serialize_item(u, f, "job", job_type_to_string(u->meta.job->type));
+
         /* End marker */
         fputc('\n', f);
         return 0;
@@ -1860,6 +1864,17 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
                 } else
                         v = l+k;
 
+                if (streq(l, "job")) {
+                        JobType type;
+
+                        if ((type = job_type_from_string(v)) < 0)
+                                log_debug("Failed to parse job type value %s", v);
+                        else
+                                u->meta.deserialized_job = type;
+
+                        continue;
+                }
+
                 if ((r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds)) < 0)
                         return r;
         }
@@ -1902,6 +1917,25 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) {
         return 0;
 }
 
+int unit_coldplug(Unit *u) {
+        int r;
+
+        assert(u);
+
+        if (UNIT_VTABLE(u)->coldplug)
+                if ((r = UNIT_VTABLE(u)->coldplug(u)) < 0)
+                        return r;
+
+        if (u->meta.deserialized_job >= 0) {
+                if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL)) < 0)
+                        return r;
+
+                u->meta.deserialized_job = _JOB_TYPE_INVALID;
+        }
+
+        return 0;
+}
+
 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
         [UNIT_SERVICE] = "service",
         [UNIT_TIMER] = "timer",
index d3e6e8902dffff15be0fec254735576e592a8218..fdf1b3691404d8bbfe97fa8dfabd1ae0cafa795c 100644 (file)
@@ -185,6 +185,10 @@ struct Meta {
         /* Garbage collect us we nobody wants or requires us anymore */
         bool stop_when_unneeded;
 
+        /* When deserializing, temporarily store the job type for this
+         * unit here, if there was a job scheduled */
+        JobType deserialized_job;
+
         bool in_load_queue:1;
         bool in_dbus_queue:1;
         bool in_cleanup_queue:1;
@@ -437,6 +441,8 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds);
 
 int unit_add_node_link(Unit *u, const char *what, bool wants);
 
+int unit_coldplug(Unit *u);
+
 const char *unit_type_to_string(UnitType i);
 UnitType unit_type_from_string(const char *s);