-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "bus-wait-for-jobs.h"
typedef struct BusWaitForJobs {
sd_bus *bus;
+
+ /* The set of jobs to wait for, as bus object paths */
Set *jobs;
+ /* The unit name and job result of the last Job message */
char *name;
char *result;
free(found);
(void) free_and_strdup(&d->result, empty_to_null(result));
+
(void) free_and_strdup(&d->name, empty_to_null(unit));
return 0;
}
-void bus_wait_for_jobs_free(BusWaitForJobs *d) {
+BusWaitForJobs* bus_wait_for_jobs_free(BusWaitForJobs *d) {
if (!d)
- return;
+ return NULL;
- set_free_free(d->jobs);
+ set_free(d->jobs);
sd_bus_slot_unref(d->slot_disconnected);
sd_bus_slot_unref(d->slot_job_removed);
free(d->name);
free(d->result);
- free(d);
+ return mfree(d);
}
int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) {
if (r > 0)
return 0;
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0)
return r;
}
if (i < ELEMENTSOF(explanations)) {
log_error("Job for %s failed because %s.\n"
- "See \"%s status %s\" and \"%s -xe\" for details.\n",
+ "See \"%s status %s\" and \"%s -xeu %s\" for details.\n",
service,
explanations[i].explanation,
systemctl,
service_shell_quoted ?: "<service>",
- journalctl);
+ journalctl,
+ service_shell_quoted ?: "<service>");
goto finish;
}
}
log_error("Job for %s failed.\n"
- "See \"%s status %s\" and \"%s -xe\" for details.\n",
+ "See \"%s status %s\" and \"%s -xeu %s\" for details.\n",
service,
systemctl,
service_shell_quoted ?: "<service>",
- journalctl);
+ journalctl,
+ service_shell_quoted ?: "<service>");
finish:
/* For some results maybe additional explanation is required */
}
int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path) {
- int r;
-
assert(d);
- r = set_ensure_allocated(&d->jobs, &string_hash_ops);
- if (r < 0)
- return r;
-
- return set_put_strdup(d->jobs, path);
+ return set_put_strdup(&d->jobs, path);
}
int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet) {