X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnames.c;h=8218216ece0aacd1a504f02932380140bd8c92ff;hb=c46bdbde18629f0a0613c776c13a79fea0ec6093;hp=5a5270a9d7761d16aedd73219f1cd073c8253c13;hpb=f5bb64b36ae0807cdd3f241f81a8e933065437f6;p=tinc diff --git a/src/names.c b/src/names.c index 5a5270a9..8218216e 100644 --- a/src/names.c +++ b/src/names.c @@ -26,7 +26,9 @@ 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 */ char *pidfilename = NULL; char *program_name = NULL; @@ -38,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); @@ -48,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); @@ -58,35 +64,49 @@ void make_names(void) { else xasprintf(&confbase, "%s", installdir); } - if(!pidfilename) - xasprintf(&pidfilename, "%s" SLASH "pid", confbase); } RegCloseKey(key); } #endif if(!confdir) - confdir = xstrdup(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, "%s" SLASH "log", confbase); + + if(!pidfilename) + xasprintf(&pidfilename, "%s" SLASH "pid", confbase); +#else if(!logfilename) xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname); if(!pidfilename) xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname); +#endif - if(netname) { - if(!confbase) - xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname); + 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 - logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter..."); - } else { - if(!confbase) - xasprintf(&confbase, CONFDIR SLASH "tinc"); + strcpy(unixsocketname + len, ".socket"); } } void free_names(void) { free(identname); free(netname); + free(unixsocketname); free(pidfilename); free(logfilename); free(confbase);