chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: unescape connection name when reading it from credentials
[elogind.git]
/
src
/
run
/
run.c
diff --git
a/src/run/run.c
b/src/run/run.c
index f4c70050894c9fd4cbeff60a554b9bcca6eabfe2..1b14e40e4d2e7ed6dd38f545ed19042150e34df6 100644
(file)
--- a/
src/run/run.c
+++ b/
src/run/run.c
@@
-178,6
+178,10
@@
static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
int r;
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
int r;
+ assert(bus);
+ assert(name);
+ assert(ret);
+
log_info("Running as unit %s.", name);
r = sd_bus_message_new_method_call(
log_info("Running as unit %s.", name);
r = sd_bus_message_new_method_call(
@@
-204,7
+208,7
@@
static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
if (!isempty(arg_slice)) {
_cleanup_free_ char *slice;
if (!isempty(arg_slice)) {
_cleanup_free_ char *slice;
- slice = unit_name_mangle_with_suffix(arg_slice, ".slice");
+ slice = unit_name_mangle_with_suffix(arg_slice,
MANGLE_NOGLOB,
".slice");
if (!slice)
return -ENOMEM;
if (!slice)
return -ENOMEM;
@@
-226,11
+230,18
@@
static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
int r;
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
int r;
+ assert(bus);
+ assert(m);
+
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
- return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+ r = sd_bus_message_append(m, "a(sa(sv))", 0);
+ if (r < 0)
+ return r;
+
+ return sd_bus_call(bus, m, 0, error, reply);
}
static int start_transient_service(
}
static int start_transient_service(
@@
-238,13
+249,13
@@
static int start_transient_service(
char **argv,
sd_bus_error *error) {
char **argv,
sd_bus_error *error) {
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL
, *reply = NULL
;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_free_ char *name = NULL;
char **i;
int r;
if (arg_unit)
_cleanup_free_ char *name = NULL;
char **i;
int r;
if (arg_unit)
- name = unit_name_mangle_with_suffix(arg_unit, ".service");
+ name = unit_name_mangle_with_suffix(arg_unit,
MANGLE_NOGLOB,
".service");
else
asprintf(&name, "run-%lu.service", (unsigned long) getpid());
if (!name)
else
asprintf(&name, "run-%lu.service", (unsigned long) getpid());
if (!name)
@@
-316,7
+327,7
@@
static int start_transient_service(
if (r < 0)
return r;
if (r < 0)
return r;
- return
message_start_transient_unit_send(bus, m, error, &reply
);
+ return
message_start_transient_unit_send(bus, m, error, NULL
);
}
static int start_transient_scope(
}
static int start_transient_scope(
@@
-324,12
+335,14
@@
static int start_transient_scope(
char **argv,
sd_bus_error *error) {
char **argv,
sd_bus_error *error) {
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL
, *reply = NULL
;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_free_ char *name = NULL;
int r;
_cleanup_free_ char *name = NULL;
int r;
+ assert(bus);
+
if (arg_unit)
if (arg_unit)
- name = unit_name_mangle_with_suffix(arg_unit, ".scope");
+ name = unit_name_mangle_with_suffix(arg_unit,
MANGLE_NOGLOB,
".scope");
else
asprintf(&name, "run-%lu.scope", (unsigned long) getpid());
if (!name)
else
asprintf(&name, "run-%lu.scope", (unsigned long) getpid());
if (!name)
@@
-343,7
+356,7
@@
static int start_transient_scope(
if (r < 0)
return r;
if (r < 0)
return r;
- r = message_start_transient_unit_send(bus, m, error,
&reply
);
+ r = message_start_transient_unit_send(bus, m, error,
NULL
);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-353,7
+366,7
@@
static int start_transient_scope(
}
int main(int argc, char* argv[]) {
}
int main(int argc, char* argv[]) {
- sd_bus_error error = SD_BUS_ERROR_NULL;
+
_cleanup_bus_error_free_
sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *description = NULL, *command = NULL;
int r;
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *description = NULL, *command = NULL;
int r;
@@
-392,11
+405,8
@@
int main(int argc, char* argv[]) {
r = start_transient_scope(bus, argv + optind, &error);
else
r = start_transient_service(bus, argv + optind, &error);
r = start_transient_scope(bus, argv + optind, &error);
else
r = start_transient_service(bus, argv + optind, &error);
- if (r < 0) {
- log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r));
- sd_bus_error_free(&error);
- goto finish;
- }
+ if (r < 0)
+ log_error("Failed start transient unit: %s", bus_error_message(&error, r));
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;