X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnames.c;h=37708f81169cc77d4c093cbee10c04c44b8b8d4f;hb=e11daa264615f6eb5782f1f349b23f47518577dd;hp=c42b95348944c35caf87b261e0216e25ca2ff265;hpb=76dbcf89895e87144e1bcb3b5cb98ffce03c383b;p=tinc diff --git a/src/names.c b/src/names.c index c42b9534..37708f81 100644 --- a/src/names.c +++ b/src/names.c @@ -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 */ @@ -39,8 +40,12 @@ void make_names(void) { #ifdef HAVE_MINGW HKEY key; char installdir[1024] = ""; - long len = sizeof installdir; + 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); @@ -49,7 +54,7 @@ void make_names(void) { #ifdef HAVE_MINGW if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) { - if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) { + if(!RegQueryValueEx(key, NULL, 0, 0, (LPBYTE)installdir, &len)) { confdir = xstrdup(installdir); if(!logfilename) xasprintf(&logfilename, "%s" SLASH "log" SLASH "%s.log", installdir, identname); @@ -74,16 +79,20 @@ 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) + if(!confbase) { + if(netname) 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"); } }