[prev in list] [next in list] [prev in thread] [next in thread]
List: systemd-commits
Subject: [systemd-commits] src/systemctl.c
From: lennart () kemper ! freedesktop ! org (Lennart Poettering)
Date: 2010-11-21 21:21:22
Message-ID: 20101121212123.0AAE110057 () kemper ! freedesktop ! org
[Download RAW message or body]
src/systemctl.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
New commits:
commit c8b2e52cf6a3b15b610f7efb31b8fff31cc9115c
Author: Lennart Poettering <lennart at poettering.net>
Date: Sun Nov 21 22:17:04 2010 +0100
systemctl: redirect enable/disable to chkconfig if applicable
diff --git a/src/systemctl.c b/src/systemctl.c
index 9d6e012..0948e61 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -3886,6 +3886,68 @@ static int install_info_apply(const char *verb, LookupPaths \
*paths, InstallInfo }
if (!f) {
+#if defined(TARGET_FEDORA) && defined (HAVE_SYSV_COMPAT)
+
+ if (endswith(i->name, ".service")) {
+ char *sysv;
+ bool exists;
+
+ if (asprintf(&sysv, SYSTEM_SYSVINIT_PATH "/%s", i->name) < \
0) { + log_error("Out of memory");
+ return -ENOMEM;
+ }
+
+ sysv[strlen(sysv) - sizeof(".service") + 1] = 0;
+ exists = access(sysv, F_OK) >= 0;
+
+ if (exists) {
+ pid_t pid;
+ siginfo_t status;
+
+ const char *argv[] = {
+ "/sbin/chkconfig",
+ NULL,
+ NULL,
+ NULL
+ };
+
+ log_info("%s is not a native service, redirecting to \
/sbin/chkconfig.", i->name); +
+ argv[1] = file_name_from_path(sysv);
+ argv[2] =
+ streq(verb, "enable") ? "on" :
+ streq(verb, "disable") ? "off" : NULL;
+
+ log_info("Executing %s %s %s", argv[0], argv[1], \
strempty(argv[2])); +
+ if ((pid = fork()) < 0) {
+ log_error("Failed to fork: %m");
+ free(sysv);
+ return -errno;
+ } else if (pid == 0) {
+ execv(argv[0], (char**) argv);
+ _exit(EXIT_FAILURE);
+ }
+
+ free(sysv);
+
+ if ((r = wait_for_terminate(pid, &status)) < 0)
+ return r;
+
+ if (status.si_code == CLD_EXITED) {
+ if (status.si_status == 0 && (streq(verb, \
"enable") || streq(verb, "disable"))) + \
n_symlinks ++; +
+ return status.si_status == 0 ? 0 : -EINVAL;
+ } else
+ return -EPROTO;
+ }
+
+ free(sysv);
+ }
+
+#endif
+
log_error("Couldn't find %s.", i->name);
return -ENOENT;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic