| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "bus-error.h" |
| 6 |
#include "bus-locator.h" |
| 7 |
#include "errno-util.h" |
| 8 |
#include "log.h" |
| 9 |
#include "parse-util.h" |
| 10 |
#include "strv.h" |
| 11 |
#include "systemctl-cancel-job.h" |
| 12 |
#include "systemctl-trivial-method.h" |
| 13 |
#include "systemctl-util.h" |
| 14 |
|
| 15 |
int verb_cancel(int argc, char *argv[], uintptr_t data, void *userdata) { |
| 16 |
sd_bus *bus; |
| 17 |
int r; |
| 18 |
|
| 19 |
if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */ |
| 20 |
return verb_trivial_method(argc, argv, data, userdata); |
| 21 |
|
| 22 |
r = acquire_bus(BUS_MANAGER, &bus); |
| 23 |
if (r < 0) |
| 24 |
return r; |
| 25 |
|
| 26 |
polkit_agent_open_maybe(); |
| 27 |
|
| 28 |
r = 0; |
| 29 |
|
| 30 |
STRV_FOREACH(name, strv_skip(argv, 1)) { |
| 31 |
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
| 32 |
uint32_t id; |
| 33 |
int q; |
| 34 |
|
| 35 |
q = safe_atou32(*name, &id); |
| 36 |
if (q < 0) |
| 37 |
return log_error_errno(q, "Failed to parse job id \"%s\": %m", *name); |
| 38 |
|
| 39 |
q = bus_call_method(bus, bus_systemd_mgr, "CancelJob", &error, NULL, "u", id); |
| 40 |
if (q < 0) { |
| 41 |
log_warning_errno(q, "Failed to cancel job %"PRIu32", ignoring: %s", |
| 42 |
id, bus_error_message(&error, q)); |
| 43 |
RET_GATHER(r, q); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return r; |
| 48 |
} |