Hello,

as discussed in the "get some distro patches upstream" thread, this is
the generalization for supporting different
chkconfig/update-rc.d/whatnot distro implementations of enabling
init.d scripts, as per LSB specification.

I figure at some point we might want to drop the explicit
--enable-chkconfig support and instead provide a Fedora/RedHat
chckconfig wrapper in /usr/lib/lsb/{install,remove}_initd ? Then we
can get rid of the #ifdeffery and some code.

I tested this with enabling/disabling with "only systemd unit" and
"only SysV unit", both with and with not having the LSB wrappers. If
there is both a script and a unit for the same name we need a second
patch, will post that separately as 2/2 as it's unrelated to this
change.

Thanks for considering,

Martin

-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
From 24f7c813548740fdba4d1688c77d298f052be935 Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.p...@ubuntu.com>
Date: Wed, 27 May 2015 14:45:25 +0200
Subject: [PATCH 1/2] systemctl: add support for LSB init.d script
 enabling/disabling

With --disable-chkconfig, use the LSB specified scripts
/usr/lib/lsb/{install,remove}_initd to enable/disable a SysV init script when
available. This allows distributions to call their specific tools like
update-rc.d, chkconfig etc. there without patching systemd.

See
  http://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/initsrcinstrm.html
---
 configure.ac              |  2 +-
 src/systemctl/systemctl.c | 35 +++++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 48cedb5..24164d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -492,7 +492,7 @@ fi
 
 # ------------------------------------------------------------------------------
 have_chkconfig=yes
-AC_ARG_ENABLE([chkconfig], AS_HELP_STRING([--disable-chkconfig],[Disable optional chkconfig support]),
+AC_ARG_ENABLE([chkconfig], AS_HELP_STRING([--disable-chkconfig],[Disable optional chkconfig support, use generic LSB support instead]),
                 [case "${enableval}" in
                         yes) have_chkconfig=yes ;;
                         no) have_chkconfig=no ;;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index f8e10a4..9c87045 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5098,7 +5098,7 @@ static int import_environment(sd_bus *bus, char **args) {
 static int enable_sysv_units(const char *verb, char **args) {
         int r = 0;
 
-#if defined(HAVE_SYSV_COMPAT) && defined(HAVE_CHKCONFIG)
+#if defined(HAVE_SYSV_COMPAT)
         unsigned f = 0;
         _cleanup_lookup_paths_free_ LookupPaths paths = {};
 
@@ -5106,8 +5106,12 @@ static int enable_sysv_units(const char *verb, char **args) {
                 return 0;
 
         if (!streq(verb, "enable") &&
-            !streq(verb, "disable") &&
-            !streq(verb, "is-enabled"))
+            !streq(verb, "disable")
+/* LSB has no way of checking the enablement status */
+#if defined(HAVE_CHKCONFIG)
+            && !streq(verb, "is-enabled")
+#endif
+            )
                 return 0;
 
         /* Processes all SysV units, and reshuffles the array so that
@@ -5123,7 +5127,7 @@ static int enable_sysv_units(const char *verb, char **args) {
                 _cleanup_free_ char *p = NULL, *q = NULL, *l = NULL;
                 bool found_native = false, found_sysv;
                 unsigned c = 1;
-                const char *argv[6] = { "/sbin/chkconfig", NULL, NULL, NULL, NULL };
+                const char *argv[6] = { NULL, NULL, NULL, NULL, NULL };
                 char **k;
                 int j;
                 pid_t pid;
@@ -5161,8 +5165,8 @@ static int enable_sysv_units(const char *verb, char **args) {
                 if (!found_sysv)
                         continue;
 
-                log_info("%s is not a native service, redirecting to /sbin/chkconfig.", name);
-
+#if defined(HAVE_CHKCONFIG)
+                argv[0] = "/sbin/chkconfig";
                 if (!isempty(arg_root))
                         argv[c++] = q = strappend("--root=", arg_root);
 
@@ -5170,6 +5174,25 @@ static int enable_sysv_units(const char *verb, char **args) {
                 argv[c++] =
                         streq(verb, "enable") ? "on" :
                         streq(verb, "disable") ? "off" : "--level=5";
+
+#else
+                if (!isempty(arg_root) && !streq(arg_root, "/")) {
+                        log_error("Can not %s SysV init script when a root directory other than / is specified", verb);
+                        continue;
+                }
+                if (streq(verb, "enable"))
+                        argv[0] = "/usr/lib/lsb/install_initd";
+                else
+                        argv[0] = "/usr/lib/lsb/remove_initd";
+                if (access(argv[0], X_OK) != 0) {
+                        log_error("Can not %s SysV init script, %s does not exist", verb, argv[0]);
+                        continue;
+                }
+                argv[c++] = p;
+#endif
+
+                log_info("%s is not a native service, redirecting to %s.", name, argv[0]);
+
                 argv[c] = NULL;
 
                 l = strv_join((char**)argv, " ");
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to