summaryrefslogtreecommitdiffstats
path: root/src/core/dbus-service.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-03-02 16:35:58 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-03-04 15:44:29 +0100
commita672f4fe8d41c7ab94a5b6b4056be39eb2ceb068 (patch)
tree280bdfc4846b6fb3f81cf306b6f77711fe0408d7 /src/core/dbus-service.c
parentsystemctl: show SuccessExitStatus= and friends (diff)
downloadsystemd-a672f4fe8d41c7ab94a5b6b4056be39eb2ceb068.tar.xz
systemd-a672f4fe8d41c7ab94a5b6b4056be39eb2ceb068.zip
core: fix received size of signal or status size
sd_bus_message_read_array() returns size of array in bytes, not number of elements. This also convert int to int32_t, as the dbus type 'i' is int32_t.
Diffstat (limited to 'src/core/dbus-service.c')
-rw-r--r--src/core/dbus-service.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index 0904cc09c0..0eb336cf03 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -55,7 +55,7 @@ static int property_get_exit_status_set(
return r;
SET_FOREACH(id, status_set->status, i) {
- int val = PTR_TO_INT(id);
+ int32_t val = PTR_TO_INT(id);
if (val < 0 || val > 255)
continue;
@@ -74,10 +74,10 @@ static int property_get_exit_status_set(
return r;
SET_FOREACH(id, status_set->signal, i) {
- int val = PTR_TO_INT(id);
+ int32_t val = PTR_TO_INT(id);
const char *str;
- str = signal_to_string(val);
+ str = signal_to_string((int) val);
if (!str)
continue;
@@ -151,7 +151,7 @@ static int bus_set_transient_exit_status(
UnitWriteFlags flags,
sd_bus_error *error) {
- const int *status, *signal;
+ const int32_t *status, *signal;
size_t sz_status, sz_signal, i;
int r;
@@ -171,6 +171,9 @@ static int bus_set_transient_exit_status(
if (r < 0)
return r;
+ sz_status /= sizeof(int32_t);
+ sz_signal /= sizeof(int32_t);
+
if (sz_status == 0 && sz_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) {
exit_status_set_free(status_set);
unit_write_settingf(u, flags, name, "%s=", name);
@@ -179,34 +182,34 @@ static int bus_set_transient_exit_status(
for (i = 0; i < sz_status; i++) {
if (status[i] < 0 || status[i] > 255)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %i", name, status[i]);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %"PRIi32, name, status[i]);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = set_ensure_allocated(&status_set->status, NULL);
if (r < 0)
return r;
- r = set_put(status_set->status, INT_TO_PTR(status[i]));
+ r = set_put(status_set->status, INT_TO_PTR((int) status[i]));
if (r < 0)
return r;
- unit_write_settingf(u, flags, name, "%s=%i", name, status[i]);
+ unit_write_settingf(u, flags, name, "%s=%"PRIi32, name, status[i]);
}
}
for (i = 0; i < sz_signal; i++) {
const char *str;
- str = signal_to_string(signal[i]);
+ str = signal_to_string((int) signal[i]);
if (!str)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %i", name, signal[i]);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %"PRIi32, name, signal[i]);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = set_ensure_allocated(&status_set->signal, NULL);
if (r < 0)
return r;
- r = set_put(status_set->signal, INT_TO_PTR(signal[i]));
+ r = set_put(status_set->signal, INT_TO_PTR((int) signal[i]));
if (r < 0)
return r;