/*
Set all files and paths according to netname
*/
-void make_names(void) {
+void make_names(bool daemon) {
#ifdef HAVE_MINGW
HKEY key;
char installdir[1024] = "";
if(!pidfilename)
xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
#else
- if(!access(LOCALSTATEDIR, R_OK | W_OK | X_OK)) {
+ bool fallback = false;
+ if(daemon) {
+ if(access(LOCALSTATEDIR, R_OK | W_OK | X_OK))
+ fallback = true;
+ } else {
+ char fname[PATH_MAX];
+ snprintf(fname, sizeof fname, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
+ if(access(fname, R_OK)) {
+ snprintf(fname, sizeof fname, "%s" SLASH "pid", confbase);
+ if(!access(fname, R_OK))
+ fallback = true;
+ }
+ }
+
+ if(!fallback) {
if(!logfilename)
xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
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);
+ if(daemon)
+ 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);
}
}
/*
names.h -- header for names.c
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
extern char *pidfilename;
extern char *program_name;
-extern void make_names(void);
+extern void make_names(bool daemon);
extern void free_names(void);
#endif /* __TINC_NAMES_H__ */
if(!parse_options(argc, argv))
return 1;
- make_names();
+ make_names(false);
xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
/*
tincd.c -- the main file for tincd
Copyright (C) 1998-2005 Ivo Timmermans
- 2000-2014 Guus Sliepen <guus@tinc-vpn.org>
+ 2000-2015 Guus Sliepen <guus@tinc-vpn.org>
2008 Max Rijevski <maksuf@gmail.com>
2009 Michael Tokarev <mjt@tls.msk.ru>
2010 Julien Muchembled <jm@jmuchemb.eu>
if(!parse_options(argc, argv))
return 1;
- make_names();
+ make_names(true);
if(show_version) {
printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,