Fix check for LOCALSTATEDIR accessibility for the CLI.
The CLI does not need write access to the directory where the PID file is stored, it just needs to be able to read the PID file.
This commit is contained in:
parent
3ccdf50beb
commit
7f96ef081d
5 changed files with 25 additions and 10 deletions
|
@ -551,7 +551,7 @@ make_names:
|
|||
confbase = NULL;
|
||||
}
|
||||
|
||||
make_names();
|
||||
make_names(false);
|
||||
|
||||
free(tinc_conf);
|
||||
free(hosts_dir);
|
||||
|
@ -756,7 +756,7 @@ ask_netname:
|
|||
}
|
||||
|
||||
netname = line;
|
||||
make_names();
|
||||
make_names(false);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Configuration stored in: %s\n", confbase);
|
||||
|
|
21
src/names.c
21
src/names.c
|
@ -36,7 +36,7 @@ char *program_name = NULL;
|
|||
/*
|
||||
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] = "";
|
||||
|
@ -85,7 +85,21 @@ void make_names(void) {
|
|||
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);
|
||||
|
||||
|
@ -96,7 +110,8 @@ void make_names(void) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
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
|
||||
|
@ -31,7 +31,7 @@ extern char *logfilename;
|
|||
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__ */
|
||||
|
|
|
@ -2558,7 +2558,7 @@ int main(int argc, char *argv[]) {
|
|||
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);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
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>
|
||||
|
@ -339,7 +339,7 @@ int main(int argc, char **argv) {
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue