run.c revision 66b1e746055b9c56fd72c0451a4cfb2b06cf3f20
/*-*- 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-util.h"
#include "strv.h"
#include "build.h"
#include "unit-name.h"
#include "path-util.h"
static bool arg_scope = false;
static bool arg_remain_after_exit = false;
static const char *arg_description = NULL;
static bool arg_send_sighup = false;
static bool arg_user = false;
static int help(void) {
printf("%s [OPTIONS...] COMMAND [ARGS...]\n\n"
"Run the specified command in a transient scope or service unit.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --user Run as user unit\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" -M --machine=CONTAINER Operate on local container\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"
" --slice=SLICE Run in the specified slice\n"
" -r --remain-after-exit Leave service around until explicitly stopped\n"
" --send-sighup Send SIGHUP when terminating\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_SYSTEM:
arg_user = false;
break;
case ARG_SCOPE:
arg_scope = true;
break;
case ARG_UNIT:
break;
case ARG_DESCRIPTION:
break;
case ARG_SLICE:
break;
case ARG_SEND_SIGHUP:
arg_send_sighup = true;
break;
case 'r':
arg_remain_after_exit = true;
break;
case 'H':
break;
case 'M':
break;
case '?':
return -EINVAL;
default:
log_error("Unknown option code %c", c);
return -EINVAL;
}
}
log_error("Command line to execute required.");
return -EINVAL;
}
log_error("Execution in user context is not supported on non-local systems.");
return -EINVAL;
}
log_error("Scope execution is not supported on non-local systems.");
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;
_cleanup_free_ char *slice;
if (!slice)
return -ENOMEM;
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;
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 finish;
if (r < 0) {
goto finish;
}
if (!arg_description) {
if (!description) {
r = log_oom();
goto finish;
}
}
if (r < 0) {
goto finish;
}
if (arg_scope)
else
if (r < 0) {
goto finish;
}
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}