From: Guus Sliepen Date: Wed, 20 May 2015 09:11:12 +0000 (+0200) Subject: Fix check for LOCALSTATEDIR accessibility for the CLI. X-Git-Tag: release-1.1pre12~137 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7f96ef081dc0dc41e3955e35c1a36a62fd47f72b;p=oweals%2Ftinc.git 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. --- diff --git a/src/invitation.c b/src/invitation.c index cc6cbd4..ed2df88 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -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); diff --git a/src/names.c b/src/names.c index 6e52886..d8935ba 100644 --- a/src/names.c +++ b/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); } } diff --git a/src/names.h b/src/names.h index 1163ff6..a2395af 100644 --- a/src/names.h +++ b/src/names.h @@ -1,7 +1,7 @@ /* names.h -- header for names.c Copyright (C) 1998-2005 Ivo Timmermans - 2000-2013 Guus Sliepen + 2000-2015 Guus Sliepen 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__ */ diff --git a/src/tincctl.c b/src/tincctl.c index fc59c58..46bf5bd 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -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); diff --git a/src/tincd.c b/src/tincd.c index 226f4f5..fb2a155 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -1,7 +1,7 @@ /* tincd.c -- the main file for tincd Copyright (C) 1998-2005 Ivo Timmermans - 2000-2014 Guus Sliepen + 2000-2015 Guus Sliepen 2008 Max Rijevski 2009 Michael Tokarev 2010 Julien Muchembled @@ -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,