]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/job: trivial modernization
authorMike Yuan <me@yhndnzj.com>
Mon, 14 Oct 2024 21:48:42 +0000 (23:48 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 27 Oct 2024 19:02:46 +0000 (20:02 +0100)
src/core/job.c
src/core/job.h

index 468571ae71a3441171e619a38a93479c220343ec..49cda53f22f5d897c5f115d7638e9a1a00fec0ec 100644 (file)
@@ -162,6 +162,7 @@ static void job_set_state(Job *j, JobState state) {
 void job_uninstall(Job *j) {
         Job **pj;
 
+        assert(j);
         assert(j->installed);
 
         job_set_state(j, JOB_WAITING);
@@ -329,14 +330,16 @@ JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool
          * this means the 'anchor' job (i.e. the one the user
          * explicitly asked for) is the requester. */
 
-        l = new0(JobDependency, 1);
+        l = new(JobDependency, 1);
         if (!l)
                 return NULL;
 
-        l->subject = subject;
-        l->object = object;
-        l->matters = matters;
-        l->conflicts = conflicts;
+        *l = (JobDependency) {
+                .subject = subject,
+                .object = object,
+                .matters = matters,
+                .conflicts = conflicts,
+        };
 
         if (subject)
                 LIST_PREPEND(subject, subject->subject_list, l);
@@ -494,6 +497,7 @@ JobType job_type_collapse(JobType t, Unit *u) {
                 return JOB_RELOAD;
 
         default:
+                assert(t >= 0 && t < _JOB_TYPE_MAX_IN_TRANSACTION);
                 return t;
         }
 }
@@ -1243,7 +1247,7 @@ int job_deserialize(Job *j, FILE *f) {
         for (;;) {
                 _cleanup_free_ char *l = NULL;
                 size_t k;
-                char *v;
+                const char *v;
 
                 r = deserialize_read_line(f, &l);
                 if (r < 0)
index 680b4a601693a86eeb931f378367036136f4435c..7603f311f2d67fc146607b5d7a184825f4fefd40 100644 (file)
@@ -127,7 +127,7 @@ struct Job {
         LIST_HEAD(JobDependency, object_list);
 
         /* Used for graph algs as a "I have been here" marker */
-        Jobmarker;
+        Job *marker;
         unsigned generation;
 
         uint32_t id;
@@ -135,6 +135,10 @@ struct Job {
         JobType type;
         JobState state;
 
+        JobResult result;
+
+        unsigned run_queue_idx;
+
         sd_event_source *timer_event_source;
         usec_t begin_usec;
         usec_t begin_running_usec;
@@ -149,10 +153,6 @@ struct Job {
         sd_bus_track *bus_track;
         char **deserialized_clients;
 
-        JobResult result;
-
-        unsigned run_queue_idx;
-
         /* If the job had a specific trigger that needs to be advertised (eg: a path unit), store it. */
         ActivationDetails *activation_details;
 
@@ -171,9 +171,12 @@ Job* job_new(Unit *unit, JobType type);
 Job* job_new_raw(Unit *unit);
 void job_unlink(Job *job);
 Job* job_free(Job *job);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Job*, job_free);
+
 Job* job_install(Job *j, bool refuse_late_merge);
 int job_install_deserialized(Job *j);
 void job_uninstall(Job *j);
+
 void job_dump(Job *j, FILE *f, const char *prefix);
 int job_serialize(Job *j, FILE *f);
 int job_deserialize(Job *j, FILE *f);
@@ -182,8 +185,6 @@ int job_coldplug(Job *j);
 JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool conflicts);
 void job_dependency_free(JobDependency *l);
 
-int job_merge(Job *j, Job *other);
-
 JobType job_type_lookup_merge(JobType a, JobType b) _pure_;
 
 _pure_ static inline bool job_type_is_mergeable(JobType a, JobType b) {
@@ -231,8 +232,6 @@ void job_add_to_gc_queue(Job *j);
 int job_get_before(Job *j, Job*** ret);
 int job_get_after(Job *j, Job*** ret);
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(Job*, job_free);
-
 const char* job_type_to_string(JobType t) _const_;
 JobType job_type_from_string(const char *s) _pure_;