Derive UNIX socket filename from PID filename.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 7 Feb 2013 14:26:56 +0000 (15:26 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 7 Feb 2013 14:26:56 +0000 (15:26 +0100)
src/names.c

index c42b953..688e96d 100644 (file)
@@ -74,8 +74,15 @@ void make_names(void) {
        if(!pidfilename)
                xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
 
-       if(!unixsocketname)
-               xasprintf(&unixsocketname, LOCALSTATEDIR SLASH "run" SLASH "%s.socket", identname);
+       if(!unixsocketname) {
+               int len = strlen(pidfilename);
+               unixsocketname = xmalloc(len + 8);
+               strcpy(unixsocketname, pidfilename);
+               if(len > 4 && !strcmp(pidfilename + len - 4, ".pid"))
+                       strcpy(unixsocketname + len - 4, ".socket");
+               else
+                       strcpy(unixsocketname + len, ".socket");
+       }
 
        if(netname) {
                if(!confbase)