run.c revision 9f2e86af0600e99cff00d1c92f9bb8d38f29896a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <getopt.h>
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "strv.h"
#include "build.h"
#include "unit-name.h"
static bool arg_scope = false;
static bool arg_user = false;
static const char *arg_description = NULL;
static int help(void) {
printf("%s [OPTIONS...] [COMMAND LINE...]\n\n"
"Notify the init system about service status updates.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --user Run as user unit\n"
" --scope Run this as scope rather than service\n"
" --unit=UNIT Run under the specified unit name\n"
" --description=TEXT Description for unit\n",
return 0;
}
enum {
ARG_VERSION = 0x100,
};
};
int c;
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
return 0;
case ARG_USER:
arg_user = true;
break;
case ARG_SCOPE:
arg_scope = true;
break;
case ARG_UNIT:
break;
case ARG_DESCRIPTION:
break;
case '?':
return -EINVAL;
default:
log_error("Unknown option code %c", c);
return -EINVAL;
}
}
log_error("Command line to execute required.");
return -EINVAL;
}
return 1;
}
int r;
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartTransientUnit", &m);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
*ret = m;
m = NULL;
return 0;
}
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
int r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
}
static int start_transient_service(
char **argv,
sd_bus_error *error) {
char **i;
int r;
if (arg_unit)
else
if (!name)
return -ENOMEM;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
STRV_FOREACH(i, argv) {
r = sd_bus_message_append(m, "s", *i);
if (r < 0)
return r;
}
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_append(m, "b", false);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
}
static int start_transient_scope(
char **argv,
sd_bus_error *error) {
int r;
if (arg_unit)
else
if (!name)
return -ENOMEM;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
log_error("Failed to execute: %m");
return -errno;
}
int r;
log_open();
if (r <= 0)
goto fail;
if (!arg_description) {
if (!description) {
r = log_oom();
goto fail;
}
}
if (arg_user)
r = sd_bus_open_user(&bus);
else
r = sd_bus_open_system(&bus);
if (r < 0) {
goto fail;
}
if (arg_scope)
else
if (r < 0) {
goto fail;
}
fail:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}