[devel] systemd policy - different names for systemd and sysV.

Igor Vlasenko vlasenko на imath.kiev.ua
Пт Май 11 23:36:49 MSK 2012


On Fri, May 11, 2012 at 10:19:06PM +0300, Igor Vlasenko wrote:
> Спасибо, поправил, patch3 в аттачменте.

Извиняюсь,
еще поправил, потерял слеш когда выделял SYSTEMD_UNITDIR,
patch4 в аттачменте.

-- 

Dr. Igor Vlasenko
--------------------
Topology Department
Institute of Math
Kiev, Ukraine


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

----------- следующая часть -----------
diff --git a/chkconfig.c b/chkconfig.c
index 63ddd73..cfb4f05 100644
--- a/chkconfig.c
+++ b/chkconfig.c
@@ -622,15 +622,44 @@ int setService(char * name, int type, int where, int state) {
     return 0;
 }
 
+#ifndef SYSTEMD_UNITDIR
+# define SYSTEMD_UNITDIR "/lib/systemd/system"
+#endif
+
+static char* systemdServiceName (const char* name) {
+    char *p;
+    char *serviceFile;
+    struct stat statbuf;
+    xasprintf(&serviceFile, SYSTEMD_UNITDIR "/%s.service", name);
+    lstat(serviceFile,&statbuf);
+    if (!S_ISLNK(statbuf.st_mode)) {
+	xasprintf(&p, "%s.service", name);
+    } else {
+	char *realFile = realpath(serviceFile,NULL);
+	char *realName = basename(realFile);
+	off_t suffixOffset = strlen(realName)-sizeof(".service");
+	/* wheather the end of realName ends with .service */
+	if (suffixOffset <= 0 || strncmp (realName + suffixOffset,
+		     ".service", sizeof(".service")) != 0) {
+	    fprintf(stderr, _("Symlink %s does not point to a *.service file. Falling back to %s as systemd service name.\n"), realFile, name);
+	    xasprintf(&p, "%s.service", name);
+	} else {
+	    p = strdup (realName);
+	}
+	free(realFile);
+    }
+    free(serviceFile);
+    return p;
+}
+
+
 void forwardSystemd(const char *name, int type, const char *verb) {
 
     if (type == TYPE_XINETD)
         return;
 
     if (systemdActive() && isOverriddenBySystemd(name)) {
-        char *p;
-
-        xasprintf(&p, "%s.service", name);
+	char *p = systemdServiceName(name);
 
         fprintf(stderr, _("Note: Forwarding request to 'systemctl %s %s'.\n"),
                 verb, p);
@@ -648,8 +677,10 @@ static int systemd_loaded_type(const char *name) {
 	char *cmd;
 	FILE *p;
 	int rc = 0;
+	char *systemdName = systemdServiceName(name);
 
-        xasprintf(&cmd, "systemctl status %s.service", name);
+        xasprintf(&cmd, "systemctl status %s", systemdName);
+	free(systemdName);
 	p = popen(cmd, "r");
 	if (p) {
 		char buf[1024];


Подробная информация о списке рассылки Devel