]>
git.ipfire.org Git - people/ms/systemd.git/blob - job.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
8 Job
* job_new(Manager
*m
, JobType type
, Name
*name
) {
12 assert(type
< _JOB_TYPE_MAX
);
15 if (!(j
= new0(Job
, 1)))
19 j
->id
= m
->current_job_id
++;
23 /* We don't link it here, that's what job_dependency() is for */
28 void job_free(Job
*j
) {
31 /* Detach from next 'bigger' objects */
34 if (j
->name
->meta
.job
== j
)
35 j
->name
->meta
.job
= NULL
;
37 hashmap_remove(j
->manager
->jobs
, UINT32_TO_PTR(j
->id
));
40 manager_transaction_unlink_job(j
->manager
, j
);
45 JobDependency
* job_dependency_new(Job
*subject
, Job
*object
, bool matters
) {
50 /* Adds a new job link, which encodes that the 'subject' job
51 * needs the 'object' job in some way. If 'subject' is NULL
52 * this means the 'anchor' job (i.e. the one the user
53 * explcitily asked for) is the requester. */
55 if (!(l
= new0(JobDependency
, 1)))
63 l
->subject_next
= subject
->subject_list
;
64 subject
->subject_list
= l
;
66 l
->subject_next
= object
->manager
->transaction_anchor
;
67 object
->manager
->transaction_anchor
= l
;
71 l
->subject_next
->subject_prev
= l
;
72 l
->subject_prev
= NULL
;
74 if ((l
->object_next
= object
->object_list
))
75 l
->object_next
->object_prev
= l
;
76 l
->object_prev
= NULL
;
77 object
->object_list
= l
;
82 void job_dependency_free(JobDependency
*l
) {
86 l
->subject_prev
->subject_next
= l
->subject_next
;
88 l
->subject
->subject_list
= l
->subject_next
;
90 l
->object
->manager
->transaction_anchor
= l
->subject_next
;
93 l
->subject_next
->subject_prev
= l
->subject_prev
;
96 l
->object_prev
->object_next
= l
->object_next
;
98 l
->object
->object_list
= l
->object_next
;
101 l
->object_next
->object_prev
= l
->object_prev
;
106 void job_dependency_delete(Job
*subject
, Job
*object
, bool *matters
) {
111 for (l
= object
->object_list
; l
; l
= l
->object_next
) {
112 assert(l
->object
== object
);
114 if (l
->subject
== subject
)
125 *matters
= l
->matters
;
127 job_dependency_free(l
);
130 void job_dump(Job
*j
, FILE*f
, const char *prefix
) {
132 static const char* const job_type_table
[_JOB_TYPE_MAX
] = {
133 [JOB_START
] = "start",
135 [JOB_VERIFY_STARTED
] = "verify-started",
136 [JOB_RELOAD
] = "reload",
137 [JOB_RELOAD_OR_START
] = "reload-or-start",
138 [JOB_RESTART
] = "restart",
139 [JOB_TRY_RESTART
] = "try-restart",
142 static const char* const job_state_table
[_JOB_STATE_MAX
] = {
143 [JOB_WAITING
] = "waiting",
144 [JOB_RUNNING
] = "running",
153 "%s\tAction: %s → %s\n"
156 prefix
, name_id(j
->name
), job_type_table
[j
->type
],
157 prefix
, job_state_table
[j
->state
]);
160 bool job_is_anchor(Job
*j
) {
165 for (l
= j
->object_list
; l
; l
= l
->object_next
)