[systemd-devel] [PATCH 1/2] Allow disable of SysV init/rcN.d support at compile time
Fabiano Fidencio
fidencio at profusion.mobi
Thu Sep 16 14:51:18 PDT 2010
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 at profusion.mobi).
---
configure.ac | 17 ++++++--
src/build.h | 8 +++-
src/dbus-manager.c | 49 ++++++++++++++++++------
src/dbus-service.c | 31 +++++++++++++++
src/load-fragment.c | 6 +++
src/main.c | 22 ++++++++++-
src/manager.c | 2 +
src/manager.h | 2 +
src/path-lookup.c | 102 +++++++++++++++++++++++++++-----------------------
src/path-lookup.h | 2 +
src/service.c | 45 +++++++++++++++++-----
src/service.h | 6 ++-
src/systemctl.c | 19 ++++++++-
13 files changed, 229 insertions(+), 82 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2ff0c1f..1505673 100644
--- a/configure.ac
+++ b/configure.ac
@@ -310,7 +310,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
@@ -322,10 +323,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])])
;;
@@ -357,6 +354,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="enabled"
+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="disabled"
+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)
@@ -416,6 +422,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}
diff --git a/src/build.h b/src/build.h
index 5cb69be..b7f647a 100644
--- a/src/build.h
+++ b/src/build.h
@@ -46,6 +46,12 @@
#define _SELINUX_FEATURE_ "-SELINUX"
#endif
-#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_
+#ifdef HAVE_SYSV
+#define _SYSVINIT_FEATURE_ "+SYSVINIT"
+#else
+#define _SYSVINIT_FEATURE_ "-SYSVINIT"
+#endif
+
+#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_ " " _SYSVINIT_FEATURE_
#endif
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index cffa547..3b79415 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -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" \
@@ -135,16 +142,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" \
@@ -248,14 +271,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 }
};
diff --git a/src/dbus-service.c b/src/dbus-service.c
index 86c18dd..ad3264c 100644
--- a/src/dbus-service.c
+++ b/src/dbus-service.c
@@ -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 }
};
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 1190ef4..8bc0607 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -959,6 +959,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 +985,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 +1448,9 @@ 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" },
+#endif
{ config_parse_kill_mode, "KILLMODE" },
{ config_parse_kill_signal, "SIGNAL" },
{ config_parse_listen, "SOCKET [...]" },
@@ -1597,7 +1601,9 @@ 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" },
+#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" },
diff --git a/src/main.c b/src/main.c
index 671f2bb..e09acca 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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"
@@ -1015,7 +1029,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;
@@ -1160,10 +1176,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);
diff --git a/src/manager.c b/src/manager.c
index 27c8aa4..f640b8d 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1960,6 +1960,7 @@ static int manager_process_signal_fd(Manager *m) {
sigchld = true;
break;
+#ifdef HAVE_SYSV_COMPAT
case SIGTERM:
if (m->running_as == MANAGER_SYSTEM) {
/* This is for compatibility with the
@@ -1967,6 +1968,7 @@ static int manager_process_signal_fd(Manager *m) {
m->exit_code = MANAGER_REEXECUTE;
break;
}
+#endif
/* Fall through */
diff --git a/src/manager.h b/src/manager.h
index 4455372..dc4cd7b 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -202,7 +202,9 @@ struct Manager {
bool show_status;
bool confirm_spawn;
+#ifdef HAVE_SYSV_COMPAT
bool sysv_console;
+#endif
bool mount_auto;
bool swap_auto;
diff --git a/src/path-lookup.c b/src/path-lookup.c
index 28336eb..258252a 100644
--- a/src/path-lookup.c
+++ b/src/path-lookup.c
@@ -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
}
diff --git a/src/path-lookup.h b/src/path-lookup.h
index f53aa21..dca8b55 100644
--- a/src/path-lookup.h
+++ b/src/path-lookup.h
@@ -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"
diff --git a/src/service.c b/src/service.c
index df0d400..6e8ed3e 100644
--- a/src/service.c
+++ b/src/service.c
@@ -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;
@@ -826,6 +833,7 @@ static int service_load_sysv(Service *s) {
return 0;
}
+#endif
static int service_verify(Service *s) {
assert(s);
@@ -891,10 +899,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)
@@ -913,8 +923,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)
@@ -998,6 +1010,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"
@@ -1015,6 +1028,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",
@@ -2257,6 +2271,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);
@@ -2264,6 +2279,7 @@ static bool service_check_gc(Unit *u) {
return !!s->sysv_path;
}
+#endif
static bool service_check_snapshot(Unit *u) {
Service *s = SERVICE(u);
@@ -2649,20 +2665,21 @@ 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;
DIR *d = NULL;
char *path = NULL, *fpath = NULL, *name = NULL;
- Set *runlevel_services[ELEMENTSOF(rcnd_table)], *shutdown_services = NULL;
- Unit *service;
- Iterator j;
int r;
assert(m);
- zero(runlevel_services);
+ Set *runlevel_services[ELEMENTSOF(rcnd_table)], *shutdown_services = NULL;
+ Unit *service;
+ Iterator j;
+ unsigned i;
+ char **p;
+ zero(runlevel_services);
STRV_FOREACH(p, m->lookup_paths.sysvrcnd_path)
for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
struct dirent *de;
@@ -2795,19 +2812,19 @@ static int service_enumerate(Manager *m) {
r = 0;
finish:
- free(path);
- free(fpath);
- free(name);
-
for (i = 0; i < ELEMENTSOF(rcnd_table); i++)
set_free(runlevel_services[i]);
set_free(shutdown_services);
+ free(path);
+ free(fpath);
+ free(name);
if (d)
closedir(d);
return r;
}
+#endif
static void service_bus_name_owner_change(
Unit *u,
@@ -2991,7 +3008,11 @@ const UnitVTable service_vtable = {
.active_state = service_active_state,
.sub_state_to_string = service_sub_state_to_string,
+#ifdef HAVE_SYSV_COMPAT
.check_gc = service_check_gc,
+#else
+ .check_gc = NULL,
+#endif
.check_snapshot = service_check_snapshot,
.sigchld_event = service_sigchld_event,
@@ -3009,5 +3030,9 @@ const UnitVTable service_vtable = {
.bus_message_handler = bus_service_message_handler,
.bus_invalidating_properties = bus_service_invalidating_properties,
+#ifdef HAVE_SYSV_COMPAT
.enumerate = service_enumerate
+#else
+ .enumerate = NULL
+#endif
};
diff --git a/src/service.h b/src/service.h
index f01906c..7259746 100644
--- a/src/service.h
+++ b/src/service.h
@@ -117,19 +117,21 @@ struct Service {
bool bus_name_good:1;
bool forbid_restart:1;
bool got_socket_fd:1;
+#ifdef HAVE_SYSV_COMPAT
bool sysv_has_lsb:1;
bool sysv_enabled:1;
-
- int socket_fd;
int sysv_start_priority;
char *sysv_path;
char *sysv_runlevels;
+#endif
char *bus_name;
char *status_text;
+ int socket_fd;
+
RateLimit ratelimit;
struct Socket *socket;
diff --git a/src/systemctl.c b/src/systemctl.c
index 8e538d6..1755f0b 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -1581,7 +1581,9 @@ typedef struct UnitStatusInfo {
pid_t control_pid;
const char *status_text;
bool running:1;
+#ifdef HAVE_SYSV_COMPAT
bool is_sysv:1;
+#endif
usec_t start_timestamp;
usec_t exit_timestamp;
@@ -1701,7 +1703,11 @@ static void print_status_info(UnitStatusInfo *i) {
printf("status=%i", p->status);
- if ((c = exit_status_to_string(p->status, i->is_sysv ? EXIT_STATUS_LSB : EXIT_STATUS_SYSTEMD)))
+#ifdef HAVE_SYSV_COMPAT
+ if ((c = exit_status_to_string(p->status, EXIT_STATUS_LSB)))
+#else
+ if ((c = exit_status_to_string(p->status, EXIT_STATUS_SYSTEMD)))
+#endif
printf("/%s", c);
} else
@@ -1739,7 +1745,11 @@ static void print_status_info(UnitStatusInfo *i) {
printf("status=%i", i->exit_status);
- if ((c = exit_status_to_string(i->exit_status, i->is_sysv ? EXIT_STATUS_LSB : EXIT_STATUS_SYSTEMD)))
+#ifdef HAVE_SYSV_COMPAT
+ if ((c = exit_status_to_string(i->exit_status, EXIT_STATUS_LSB)))
+#else
+ if ((c = exit_status_to_string(i->exit_status, EXIT_STATUS_SYSTEMD)))
+#endif
printf("/%s", c);
} else
@@ -1811,10 +1821,13 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
i->description = s;
else if (streq(name, "FragmentPath"))
i->path = s;
+#ifdef HAVE_SYSV_COMPAT
else if (streq(name, "SysVPath")) {
i->is_sysv = true;
i->path = s;
- } else if (streq(name, "DefaultControlGroup"))
+ }
+#endif
+ else if (streq(name, "DefaultControlGroup"))
i->default_control_group = s;
else if (streq(name, "StatusText"))
i->status_text = s;
--
1.7.2.3
More information about the systemd-devel
mailing list