Add "list" as an alias for "dump" in the CLI.
[tinc] / src / names.c
index cc72a11..6e52886 100644 (file)
@@ -1,7 +1,7 @@
 /*
     names.c -- generate commonly used (file)names
     Copyright (C) 1998-2005 Ivo Timmermans
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2015 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 char *netname = NULL;
 char *confdir = NULL;           /* base configuration directory */
 char *confbase = NULL;          /* base configuration directory for this instance of tinc */
+bool confbase_given;
 char *identname = NULL;         /* program name for syslog */
 char *unixsocketname = NULL;    /* UNIX socket location */
 char *logfilename = NULL;       /* log file location */
@@ -41,6 +42,10 @@ void make_names(void) {
        char installdir[1024] = "";
        DWORD len = sizeof installdir;
 #endif
+       confbase_given = confbase;
+
+       if(netname && confbase)
+               logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
 
        if(netname)
                xasprintf(&identname, "tinc.%s", netname);
@@ -59,8 +64,6 @@ void make_names(void) {
                                else
                                        xasprintf(&confbase, "%s", installdir);
                        }
-                       if(!pidfilename)
-                               xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
                }
                RegCloseKey(key);
        }
@@ -68,11 +71,36 @@ void make_names(void) {
        if(!confdir)
                confdir = xstrdup(CONFDIR SLASH "tinc");
 
+       if(!confbase) {
+               if(netname)
+                       xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
+               else
+                       xasprintf(&confbase, CONFDIR SLASH "tinc");
+       }
+
+#ifdef HAVE_MINGW
        if(!logfilename)
-               xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
+               xasprintf(&logfilename, "%s" SLASH "log", confbase);
 
        if(!pidfilename)
-               xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
+               xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
+#else
+       if(!access(LOCALSTATEDIR, R_OK | W_OK | X_OK)) {
+               if(!logfilename)
+                       xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
+
+               if(!pidfilename)
+                       xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
+       } else {
+               if(!logfilename)
+                       xasprintf(&logfilename, "%s" SLASH "log", confbase);
+
+               if(!pidfilename) {
+                       logger(DEBUG_ALWAYS, LOG_WARNING, "Could not access " LOCALSTATEDIR SLASH " (%s), storing pid and socket files in %s" SLASH, strerror(errno), confbase);
+                       xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
+               }
+       }
+#endif
 
        if(!unixsocketname) {
                int len = strlen(pidfilename);
@@ -83,16 +111,6 @@ void make_names(void) {
                else
                        strcpy(unixsocketname + len, ".socket");
        }
-
-       if(netname) {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
-               else
-                       logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
-       } else {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc");
-       }
 }
 
 void free_names(void) {