Commit 07459bb6 authored by Fabiano Fidencio's avatar Fabiano Fidencio Committed by Lennart Poettering

sysv: optionally disable of SysV init/rcN.d support at compile time

This patch adds a cpp definition HAVE_SYSV_COMPAT that is used to
isolate code dealing with /etc/init.d and /etc/rcN.d for systems where
it does not make sense (one that does not use sysv or one that is fully
systemd native).

The patch tries to be as little intrusive as possible, however in
order to minimize the number of #ifdef'ed regions I've reordered some
code in path-lookup.c:lookup_paths_init() where all code dealing with
sysv is now isolated under running_as == MANAGER_SYSTEM as well.

Moreover, In struct Service, some fields were rearranged to reduce
the number of ifdefs.

Lennart's suggestions were fixed and squashed with the original patch,
that was sent by Gustavo Sverzut Barbieri (barbieri@profusion.mobi).
parent 66d9b3b5
......@@ -311,7 +311,8 @@ case $with_distro in
M4_DISTRO_FLAG=-DTARGET_ARCH=1
;;
gentoo)
SYSTEM_SYSVRCND_PATH=/etc
SYSTEM_SYSVINIT_PATH=
SYSTEM_SYSVRCND_PATH=
SPECIAL_SYSLOG_SERVICE=syslog-ng.service
AC_DEFINE(TARGET_GENTOO, [], [Target is Gentoo])
M4_DISTRO_FLAG=-DTARGET_GENTOO=1
......@@ -323,10 +324,6 @@ case $with_distro in
M4_DISTRO_FLAG=-DTARGET_SLACKWARE=1
;;
other)
AS_IF([test "x$with_sysvinit_path" = "x"],
[AC_MSG_ERROR([With --distro=other, you must pass --with-sysvinit-path= to configure])])
AS_IF([test "x$with_sysvrcd_path" = "x"],
[AC_MSG_ERROR([With --distro=other, you must pass --with-sysvrcd-path= to configure])])
AS_IF([test "x$with_syslog_service" = "x"],
[AC_MSG_ERROR([With --distro=other, you must pass --with-syslog-service= to configure])])
;;
......@@ -358,6 +355,15 @@ AC_SUBST(SYSTEM_SYSVRCND_PATH)
AC_SUBST(SPECIAL_SYSLOG_SERVICE)
AC_SUBST(M4_DISTRO_FLAG)
if test "x${SYSTEM_SYSVINIT_PATH}" != "x" -a "x${SYSTEM_SYSVRCND_PATH}" != "x"; then
AC_DEFINE(HAVE_SYSV_COMPAT, [], [SysV init scripts and rcN.d links are supported.])
SYSTEM_SYSV_COMPAT="yes"
elif test "x${SYSTEM_SYSVINIT_PATH}" != "x" -o "x${SYSTEM_SYSVRCND_PATH}" != "x"; then
AC_MSG_ERROR([*** You need both --with-sysvinit-path=PATH and --with-sysvrcd-path=PATH to enable SysV compatibility support, or both empty to disable it.])
else
SYSTEM_SYSV_COMPAT="no"
fi
AM_CONDITIONAL(TARGET_FEDORA, test x"$with_distro" = xfedora)
AM_CONDITIONAL(TARGET_SUSE, test x"$with_distro" = xsuse)
AM_CONDITIONAL(TARGET_DEBIAN, test x"$with_distro" = xdebian)
......@@ -417,6 +423,7 @@ echo "
$PACKAGE_NAME $VERSION
Distribution: ${with_distro}
SysV compatibility: ${SYSTEM_SYSV_COMPAT}
SysV init scripts: ${SYSTEM_SYSVINIT_PATH}
SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH}
Syslog service: ${SPECIAL_SYSLOG_SERVICE}
......
......@@ -46,6 +46,12 @@
#define _SELINUX_FEATURE_ "-SELINUX"
#endif
#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_
#ifdef HAVE_SYSV_COMPAT
#define _SYSVINIT_FEATURE_ "+SYSVINIT"
#else
#define _SYSVINIT_FEATURE_ "-SYSVINIT"
#endif
#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_ " " _SYSVINIT_FEATURE_
#endif
......@@ -27,14 +27,16 @@
#include "strv.h"
#include "bus-errors.h"
#define BUS_MANAGER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
#define BUS_MANAGER_INTERFACE_BEGIN \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n"
#define BUS_MANAGER_INTERFACE_METHODS \
" <method name=\"GetUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetUnitByPID\">\n" \
" <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"LoadUnit\">\n" \
......@@ -107,7 +109,9 @@
" </method>\n" \
" <method name=\"UnsetEnvironment\">\n" \
" <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
" </method>\n" \
" </method>\n"
#define BUS_MANAGER_INTERFACE_SIGNALS \
" <signal name=\"UnitNew\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"unit\" type=\"o\"/>\n" \
......@@ -124,7 +128,10 @@
" <arg name=\"id\" type=\"u\"/>\n" \
" <arg name=\"job\" type=\"o\"/>\n" \
" <arg name=\"success\" type=\"b\"/>\n" \
" </signal>" \
" </signal>"
#define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
" <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RunningAs\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"StartupTimestamp\" type=\"t\" access=\"read\"/>\n" \
......@@ -138,16 +145,32 @@
" <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n"
#ifdef HAVE_SYSV_COMPAT
#define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
" <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n"
#else
#define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV
#endif
#define BUS_MANAGER_INTERFACE_END \
" </interface>\n"
#define BUS_MANAGER_INTERFACE \
BUS_MANAGER_INTERFACE_BEGIN \
BUS_MANAGER_INTERFACE_METHODS \
BUS_MANAGER_INTERFACE_SIGNALS \
BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
BUS_MANAGER_INTERFACE_END
#define INTROSPECTION_BEGIN \
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
"<node>\n" \
......@@ -273,14 +296,16 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
{ "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
{ "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
{ "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
{ "org.freedesktop.systemd1.Manager", "SysVConsole", bus_property_append_bool, "b", &m->sysv_console },
{ "org.freedesktop.systemd1.Manager", "UnitPath", bus_property_append_strv, "as", m->lookup_paths.unit_path },
{ "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },
{ "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path },
{ "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string, "s", m->notify_socket },
{ "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
{ "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto },
{ "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto },
#ifdef HAVE_SYSV_COMPAT
{ "org.freedesktop.systemd1.Manager", "SysVConsole", bus_property_append_bool, "b", &m->sysv_console },
{ "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },
{ "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path },
#endif
{ NULL, NULL, NULL, NULL, NULL }
};
......
......@@ -25,6 +25,7 @@
#include "dbus-execute.h"
#include "dbus-service.h"
#ifdef HAVE_SYSV_COMPAT
#define BUS_SERVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Service\">\n" \
" <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
......@@ -52,6 +53,32 @@
" <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#else
#define BUS_SERVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Service\">\n" \
" <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Restart\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"PIDFile\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"NotifyAccess\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
BUS_EXEC_COMMAND_INTERFACE("ExecStart") \
BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
BUS_EXEC_COMMAND_INTERFACE("ExecReload") \
BUS_EXEC_COMMAND_INTERFACE("ExecStop") \
BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
BUS_EXEC_CONTEXT_INTERFACE \
" <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
BUS_EXEC_STATUS_INTERFACE("ExecMain") \
" <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#endif
#define INTROSPECTION \
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
......@@ -104,11 +131,15 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connectio
BUS_EXEC_STATUS_PROPERTIES("org.freedesktop.systemd1.Service", u->service.main_exec_status, "ExecMain"),
{ "org.freedesktop.systemd1.Service", "MainPID", bus_property_append_pid, "u", &u->service.main_pid },
{ "org.freedesktop.systemd1.Service", "ControlPID", bus_property_append_pid, "u", &u->service.control_pid },
#ifdef HAVE_SYSV_COMPAT
{ "org.freedesktop.systemd1.Service", "SysVPath", bus_property_append_string, "s", u->service.sysv_path },
#endif
{ "org.freedesktop.systemd1.Service", "BusName", bus_property_append_string, "s", u->service.bus_name },
{ "org.freedesktop.systemd1.Service", "StatusText", bus_property_append_string, "s", u->service.status_text },
#ifdef HAVE_SYSV_COMPAT
{ "org.freedesktop.systemd1.Service", "SysVRunLevels", bus_property_append_string, "s", u->service.sysv_runlevels },
{ "org.freedesktop.systemd1.Service", "SysVStartPriority", bus_property_append_int, "i", &u->service.sysv_start_priority },
#endif
{ NULL, NULL, NULL, NULL, NULL }
};
......
......@@ -42,6 +42,21 @@
#include "unit-name.h"
#include "bus-errors.h"
#ifndef HAVE_SYSV_COMPAT
static int config_parse_warn_compat(
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
const char *rvalue,
void *data,
void *userdata) {
log_debug("[%s:%u] Support for option %s= has been disabled at compile time and is ignored", filename, line, lvalue);
return 0;
}
#endif
static int config_parse_deps(
const char *filename,
unsigned line,
......@@ -959,6 +974,7 @@ static int config_parse_cgroup(
return 0;
}
#ifdef HAVE_SYSV_COMPAT
static int config_parse_sysv_priority(
const char *filename,
unsigned line,
......@@ -984,6 +1000,7 @@ static int config_parse_sysv_priority(
*priority = (int) i;
return 0;
}
#endif
static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
......@@ -1446,7 +1463,11 @@ static void dump_items(FILE *f, const ConfigItem *items) {
{ config_parse_exec, "PATH [ARGUMENT [...]]" },
{ config_parse_service_type, "SERVICETYPE" },
{ config_parse_service_restart, "SERVICERESTART" },
#ifdef HAVE_SYSV_COMPAT
{ config_parse_sysv_priority, "SYSVPRIORITY" },
#else
{ config_parse_warn_compat, "NOTSUPPORTED" },
#endif
{ config_parse_kill_mode, "KILLMODE" },
{ config_parse_kill_signal, "SIGNAL" },
{ config_parse_listen, "SOCKET [...]" },
......@@ -1597,7 +1618,11 @@ static int load_from_path(Unit *u, const char *path) {
{ "PermissionsStartOnly", config_parse_bool, &u->service.permissions_start_only, "Service" },
{ "RootDirectoryStartOnly", config_parse_bool, &u->service.root_directory_start_only, "Service" },
{ "RemainAfterExit", config_parse_bool, &u->service.remain_after_exit, "Service" },
#ifdef HAVE_SYSV_COMPAT
{ "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" },
#else
{ "SysVStartPriority", config_parse_warn_compat, NULL, "Service" },
#endif
{ "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" },
{ "BusName", config_parse_string_printf, &u->service.bus_name, "Service" },
{ "NotifyAccess", config_parse_notify_access, &u->service.notify_access, "Service" },
......
......@@ -64,7 +64,9 @@ static bool arg_crash_shell = false;
static int arg_crash_chvt = -1;
static bool arg_confirm_spawn = false;
static bool arg_show_status = true;
#ifdef HAVE_SYSV_COMPAT
static bool arg_sysv_console = true;
#endif
static bool arg_mount_auto = true;
static bool arg_swap_auto = true;
static char *arg_console = NULL;
......@@ -312,7 +314,7 @@ static int parse_proc_cmdline_word(const char *word) {
log_warning("Failed to parse show status switch %s, Ignoring.", word + 20);
else
arg_show_status = r;
#ifdef HAVE_SYSV_COMPAT
} else if (startswith(word, "systemd.sysv_console=")) {
int r;
......@@ -320,6 +322,7 @@ static int parse_proc_cmdline_word(const char *word) {
log_warning("Failed to parse SysV console switch %s, Ignoring.", word + 20);
else
arg_sysv_console = r;
#endif
} else if (startswith(word, "systemd.")) {
......@@ -332,7 +335,9 @@ static int parse_proc_cmdline_word(const char *word) {
"systemd.crash_chvt=N Change to VT #N on crash\n"
"systemd.confirm_spawn=0|1 Confirm every process spawn\n"
"systemd.show_status=0|1 Show status updates on the console during bootup\n"
#ifdef HAVE_SYSV_COMPAT
"systemd.sysv_console=0|1 Connect output of SysV scripts to console\n"
#endif
"systemd.log_target=console|kmsg|syslog|syslog-org-kmsg|null\n"
" Log target\n"
"systemd.log_level=LEVEL Log level\n"
......@@ -361,7 +366,9 @@ static int parse_proc_cmdline_word(const char *word) {
} else if (streq(word, "quiet")) {
arg_show_status = false;
#ifdef HAVE_SYSV_COMPAT
arg_sysv_console = false;
#endif
} else {
unsigned i;
......@@ -505,7 +512,9 @@ static int parse_config_file(void) {
{ "DumpCore", config_parse_bool, &arg_dump_core, "Manager" },
{ "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" },
{ "ShowStatus", config_parse_bool, &arg_show_status, "Manager" },
#ifdef HAVE_SYSV_COMPAT
{ "SysVConsole", config_parse_bool, &arg_sysv_console, "Manager" },
#endif
{ "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" },
{ "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" },
{ "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" },
......@@ -610,7 +619,9 @@ static int parse_argv(int argc, char *argv[]) {
{ "crash-shell", no_argument, NULL, ARG_CRASH_SHELL },
{ "confirm-spawn", no_argument, NULL, ARG_CONFIRM_SPAWN },
{ "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
#ifdef HAVE_SYSV_COMPAT
{ "sysv-console", optional_argument, NULL, ARG_SYSV_CONSOLE },
#endif
{ "deserialize", required_argument, NULL, ARG_DESERIALIZE },
{ "introspect", optional_argument, NULL, ARG_INTROSPECT },
{ NULL, 0, NULL, 0 }
......@@ -714,7 +725,7 @@ static int parse_argv(int argc, char *argv[]) {
} else
arg_show_status = true;
break;
#ifdef HAVE_SYSV_COMPAT
case ARG_SYSV_CONSOLE:
if (optarg) {
......@@ -726,6 +737,7 @@ static int parse_argv(int argc, char *argv[]) {
} else
arg_sysv_console = true;
break;
#endif
case ARG_DESERIALIZE: {
int fd;
......@@ -813,7 +825,9 @@ static int help(void) {
" --crash-shell Run shell on crash\n"
" --confirm-spawn Ask for confirmation when spawning processes\n"
" --show-status[=0|1] Show status updates on the console during bootup\n"
#ifdef HAVE_SYSV_COMPAT
" --sysv-console[=0|1] Connect output of SysV scripts to console\n"
#endif
" --log-target=TARGET Set log target (console, syslog, kmsg, syslog-or-kmsg, null)\n"
" --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
" --log-color[=0|1] Highlight important log messages\n"
......@@ -1017,7 +1031,9 @@ int main(int argc, char *argv[]) {
m->confirm_spawn = arg_confirm_spawn;
m->show_status = arg_show_status;
#ifdef HAVE_SYSV_COMPAT
m->sysv_console = arg_sysv_console;
#endif
m->mount_auto = arg_mount_auto;
m->swap_auto = arg_swap_auto;
......@@ -1162,10 +1178,12 @@ finish:
else
args[i++] = "--show-status=0";
#ifdef HAVE_SYSV_COMPAT
if (arg_sysv_console)
args[i++] = "--sysv-console=1";
else
args[i++] = "--sysv-console=0";
#endif
snprintf(sfd, sizeof(sfd), "%i", fileno(serialization));
char_array_0(sfd);
......
......@@ -203,7 +203,9 @@ struct Manager {
bool show_status;
bool confirm_spawn;
#ifdef HAVE_SYSV_COMPAT
bool sysv_console;
#endif
bool mount_auto;
bool swap_auto;
......
......@@ -191,7 +191,26 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
return -ENOMEM;
}
if (p->unit_path)
if (!strv_path_canonicalize(p->unit_path))
return -ENOMEM;
strv_uniq(p->unit_path);
if (!strv_isempty(p->unit_path)) {
if (!(t = strv_join(p->unit_path, "\n\t")))
return -ENOMEM;
log_debug("Looking for unit files in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring unit files.");
strv_free(p->unit_path);
p->unit_path = NULL;
}
if (running_as == MANAGER_SYSTEM) {
#ifdef HAVE_SYSV_COMPAT
/* /etc/init.d/ compatibility does not matter to users */
if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))
......@@ -219,60 +238,46 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
NULL)))
return -ENOMEM;
}
}
if (p->unit_path)
if (!strv_path_canonicalize(p->unit_path))
return -ENOMEM;
if (p->sysvinit_path)
if (!strv_path_canonicalize(p->sysvinit_path))
return -ENOMEM;
if (p->sysvrcnd_path)
if (!strv_path_canonicalize(p->sysvrcnd_path))
return -ENOMEM;
strv_uniq(p->unit_path);
strv_uniq(p->sysvinit_path);
strv_uniq(p->sysvrcnd_path);
if (p->sysvinit_path)
if (!strv_path_canonicalize(p->sysvinit_path))
return -ENOMEM;
if (!strv_isempty(p->unit_path)) {
if (p->sysvrcnd_path)
if (!strv_path_canonicalize(p->sysvrcnd_path))
return -ENOMEM;
if (!(t = strv_join(p->unit_path, "\n\t")))
return -ENOMEM;
log_debug("Looking for unit files in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring unit files.");
strv_free(p->unit_path);
p->unit_path = NULL;
}
strv_uniq(p->sysvinit_path);
strv_uniq(p->sysvrcnd_path);
if (!strv_isempty(p->sysvinit_path)) {
if (!strv_isempty(p->sysvinit_path)) {
if (!(t = strv_join(p->sysvinit_path, "\n\t")))
return -ENOMEM;
if (!(t = strv_join(p->sysvinit_path, "\n\t")))
return -ENOMEM;
log_debug("Looking for SysV init scripts in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring SysV init scripts.");
strv_free(p->sysvinit_path);
p->sysvinit_path = NULL;
}
log_debug("Looking for SysV init scripts in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring SysV init scripts.");
strv_free(p->sysvinit_path);
p->sysvinit_path = NULL;
}
if (!strv_isempty(p->sysvrcnd_path)) {
if (!strv_isempty(p->sysvrcnd_path)) {
if (!(t = strv_join(p->sysvrcnd_path, "\n\t")))
return -ENOMEM;
if (!(t = strv_join(p->sysvrcnd_path, "\n\t")))
return -ENOMEM;
log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring SysV rcN.d links.");
strv_free(p->sysvrcnd_path);
p->sysvrcnd_path = NULL;
log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
free(t);
} else {
log_debug("Ignoring SysV rcN.d links.");
strv_free(p->sysvrcnd_path);
p->sysvrcnd_path = NULL;
}
#else
log_debug("Disabled SysV init scripts and rcN.d links support");
#endif
}
return 0;
......@@ -282,8 +287,11 @@ void lookup_paths_free(LookupPaths *p) {
assert(p);
strv_free(p->unit_path);
p->unit_path = NULL;
#ifdef HAVE_SYSV_COMPAT
strv_free(p->sysvinit_path);
strv_free(p->sysvrcnd_path);
p->unit_path = p->sysvinit_path = p->sysvrcnd_path = NULL;
p->sysvinit_path = p->sysvrcnd_path = NULL;
#endif
}
......@@ -24,8 +24,10 @@
typedef struct LookupPaths {
char **unit_path;
#ifdef HAVE_SYSV_COMPAT
char **sysvinit_path;
char **sysvrcnd_path;
#endif
} LookupPaths;
#include "manager.h"
......
......@@ -38,6 +38,7 @@
#define COMMENTS "#;\n"
#define NEWLINES "\n\r"
#ifdef HAVE_SYSV_COMPAT
typedef enum RunlevelType {
RUNLEVEL_UP,
RUNLEVEL_DOWN,
......@@ -80,6 +81,7 @@ static const struct {
#define RUNLEVELS_UP "12345"
/* #define RUNLEVELS_DOWN "06" */
/* #define RUNLEVELS_BOOT "bBsS" */
#endif
static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
[SERVICE_DEAD] = UNIT_INACTIVE,
......@@ -108,7 +110,9 @@ static void service_init(Unit *u) {
s->timeout_usec = DEFAULT_TIMEOUT_USEC;
s->restart_usec = DEFAULT_RESTART_USEC;
s->timer_watch.type = WATCH_INVALID;
#ifdef HAVE_SYSV_COMPAT
s->sysv_start_priority = -1;
#endif
s->socket_fd = -1;
exec_context_init(&s->exec_context);
......@@ -189,11 +193,13 @@ static void service_done(Unit *u) {
free(s->pid_file);
s->pid_file = NULL;
#ifdef HAVE_SYSV_COMPAT
free(s->sysv_path);
s->sysv_path = NULL;
free(s->sysv_runlevels);
s->sysv_runlevels = NULL;
#endif
free(s->status_text);
s->status_text = NULL;
......@@ -219,6 +225,7 @@ static void service_done(Unit *u) {
unit_unwatch_timer(u, &s->timer_watch);
}
#ifdef HAVE_SYSV_COMPAT
static char *sysv_translate_name(const char *name) {
char *r;
......@@ -831,6 +838,7 @@ static int service_load_sysv(Service *s) {
return 0;
}
#endif
static int service_verify(Service *s) {
assert(s);
......@@ -896,10 +904,12 @@ static int service_load(Unit *u) {
if ((r = unit_load_fragment(u)) < 0)
return r;
#ifdef HAVE_SYSV_COMPAT
/* Load a classic init script as a fallback, if we couldn't find anything */
if (u->meta.load_state == UNIT_STUB)
if ((r = service_load_sysv(s)) < 0)
return r;
#endif
/* Still nothing found? Then let's give up */
if (u->meta.load_state == UNIT_STUB)
......@@ -918,8 +928,10 @@ static int service_load(Unit *u) {
if ((r = unit_add_default_cgroup(u)) < 0)
return r;
#ifdef HAVE_SYSV_COMPAT
if ((r = sysv_fix_order(s)) < 0)
return r;
#endif
if (s->bus_name)
if ((r = unit_watch_bus_name(u, s->bus_name)) < 0)
......@@ -1003,6 +1015,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
exec_command_dump_list(s->exec_command[c], f, prefix2);
}
#ifdef HAVE_SYSV_COMPAT
if (s->sysv_path)
fprintf(f,
"%sSysV Init Script Path: %s\n"
......@@ -1020,6 +1033,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
if (s->sysv_runlevels)
fprintf(f, "%sSysVRunLevels: %s\n",
prefix, s->sysv_runlevels);
#endif
if (s->status_text)
fprintf(f, "%sStatus Text: %s\n",
......@@ -2262,6 +2276,7 @@ static const char *service_sub_state_to_string(Unit *u) {
return service_state_to_string(SERVICE(u)->state);
}
#ifdef HAVE_SYSV_COMPAT
static bool service_check_gc(Unit *u) {
Service *s = SERVICE(u);
......@@ -2269,6 +2284,7 @@ static bool service_check_gc(Unit *u) {
return !!s->sysv_path;
}
#endif
static bool service_check_snapshot(Unit *u) {
Service *s = SERVICE(u);
......@@ -2654,6 +2670,7 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
unit_add_to_dbus_queue(u);
}
#ifdef HAVE_SYSV_COMPAT
static int service_enumerate(Manager *m) {
char **p;
unsigned i;
......@@ -2874,6 +2891,7 @@ finish:
return r;
}
#endif
static void service_bus_name_owner_change(
Unit *u,
......@@ -3057,7 +3075,9 @@ const UnitVTable service_vtable = {
.active_state = service_active_state,
.sub_state_to_string = service_sub_state_to_string,
#ifdef HAVE_SYSV_COMPAT