ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Igor Vlasenko <vlasenko@imath.kiev.ua>
To: ALT Devel discussion list <devel@lists.altlinux.org>
Cc: "Dmitry V. Levin" <ldv@altlinux.org>
Subject: Re: [devel] systemd policy - different names for systemd and sysV.
Date: Fri, 11 May 2012 22:36:49 +0300
Message-ID: <20120511193648.GA25136@dad.imath.kiev.ua> (raw)
In-Reply-To: <20120511191906.GA24819@dad.imath.kiev.ua>

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

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.


[-- Attachment #2: chkconfig-4.patch --]
[-- Type: text/plain, Size: 1954 bytes --]

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];

  reply	other threads:[~2012-05-11 19:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 11:16 Igor Vlasenko
2012-05-11 18:31 ` Dmitry V. Levin
2012-05-11 19:19   ` Igor Vlasenko
2012-05-11 19:36     ` Igor Vlasenko [this message]
2012-05-18  9:55       ` Alexey Shabalin
2012-05-18 10:19         ` Dmitry V. Levin
2012-05-18 10:51           ` Alexey Shabalin
2012-05-18 15:07             ` Dmitry V. Levin
2012-05-18 16:05               ` Alexey Shabalin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120511193648.GA25136@dad.imath.kiev.ua \
    --to=vlasenko@imath.kiev.ua \
    --cc=devel@lists.altlinux.org \
    --cc=ldv@altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git