1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "bus-internal.h"
26 #include "bus-message.h"
29 static int start_transient_service(
33 sd_bus_error *error) {
35 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
39 r = sd_bus_message_new_method_call(
41 "org.freedesktop.systemd1",
42 "/org/freedesktop/systemd1",
43 "org.freedesktop.systemd1.Manager",
44 "StartTransientUnit", &m);
48 r = sd_bus_message_append(m, "ss", name, "fail");
52 r = sd_bus_message_open_container(m, 'a', "(sv)");
56 r = sd_bus_message_open_container(m, 'r', "sv");
60 r = sd_bus_message_append(m, "s", "ExecStart");
64 r = sd_bus_message_open_container(m, 'v', "a(sasb)");
68 r = sd_bus_message_open_container(m, 'a', "(sasb)");
72 r = sd_bus_message_open_container(m, 'r', "sasb");
76 r = sd_bus_message_append(m, "s", argv[0]);
80 r = sd_bus_message_open_container(m, 'a', "s");
84 STRV_FOREACH(i, argv) {
85 r = sd_bus_message_append(m, "s", *i);
90 r = sd_bus_message_close_container(m);
94 r = sd_bus_message_append(m, "b", false);
98 r = sd_bus_message_close_container(m);
102 r = sd_bus_message_close_container(m);
106 r = sd_bus_message_close_container(m);
110 r = sd_bus_message_close_container(m);
114 r = sd_bus_message_close_container(m);
118 return sd_bus_send_with_reply_and_block(bus, m, 0, error, &reply);
121 int main(int argc, char* argv[]) {
122 sd_bus_error error = SD_BUS_ERROR_NULL;
123 _cleanup_bus_unref_ sd_bus *bus = NULL;
124 _cleanup_free_ char *name = NULL;
127 log_parse_environment();
131 log_error("Missing command line.");
136 r = sd_bus_open_user(&bus);
138 log_error("Failed to create new bus: %s", strerror(-r));
142 if (asprintf(&name, "run-%lu.service", (unsigned long) getpid()) < 0) {
147 r = start_transient_service(bus, name, argv + 1, &error);
149 log_error("Failed start transient service: %s", error.message);
150 sd_bus_error_free(&error);
155 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;