From: Guus Sliepen Date: Sat, 12 Apr 2014 13:09:35 +0000 (+0200) Subject: Remove pidfile/logfile/netname and so on. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=1564f52f7643c554ec49a3e014bc9b9a8745c856 Remove pidfile/logfile/netname and so on. Everything will be contained in a single directory specified by confbase. --- diff --git a/src/Makefile.am b/src/Makefile.am index 8cd579b4..25df72f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,7 +50,6 @@ libmeshlink_la_SOURCES = \ list.c list.h \ logger.c logger.h \ meta.c meta.h \ - names.c names.h \ net.c net.h \ net_packet.c \ net_setup.c \ diff --git a/src/conf.c b/src/conf.c index 836c00e4..16247570 100644 --- a/src/conf.c +++ b/src/conf.c @@ -29,7 +29,6 @@ #include "conf.h" #include "list.h" #include "logger.h" -#include "names.h" #include "netutl.h" /* for str2address */ #include "protocol.h" #include "utils.h" /* for cp */ diff --git a/src/graph.c b/src/graph.c index 67fe99f7..f8c906b0 100644 --- a/src/graph.c +++ b/src/graph.c @@ -49,7 +49,6 @@ #include "graph.h" #include "list.h" #include "logger.h" -#include "names.h" #include "netutl.h" #include "node.h" #include "protocol.h" diff --git a/src/invitation.c b/src/invitation.c index 3e05d8c7..b6486c84 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -24,7 +24,6 @@ #include "ecdsa.h" #include "ecdsagen.h" #include "invitation.h" -#include "names.h" #include "netutl.h" #include "rsagen.h" #include "sptps.h" @@ -546,13 +545,6 @@ static bool finalize_join(void) { char temp_netname[32]; make_names: - if(!confbasegiven) { - free(confbase); - confbase = NULL; - } - - make_names(); - free(tinc_conf); free(hosts_dir); @@ -758,7 +750,6 @@ ask_netname: free(newbase); netname = line; - make_names(); } fprintf(stderr, "Configuration stored in: %s\n", confbase); @@ -819,11 +810,6 @@ int cmd_join(int argc, char *argv[]) { } // Make sure confbase exists and is accessible. - if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) { - fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno)); - return 1; - } - if(mkdir(confbase, 0777) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno)); return 1; diff --git a/src/libmeshlink.c b/src/libmeshlink.c index d6e199fd..e88b20c4 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -380,8 +380,7 @@ int check_port(char *name) { } //tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script. bool tinc_setup(const char* confbaseapi, const char* name) { - confbase = confbaseapi; - make_names(); + confbase = xstrdup(confbaseapi); xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase); xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); if(!access(tinc_conf, F_OK)) { @@ -394,11 +393,6 @@ bool tinc_setup(const char* confbaseapi, const char* name) { return false; } - if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) { - fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno)); - return false; - } - if(mkdir(confbase, 0777) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno)); return false; @@ -437,15 +431,14 @@ return true; } bool tinc_main_thread(void * in) { + static bool status = false; -static bool status = false; - -/* If nonzero, write log entries to a separate file. */ -bool use_logfile = false; + /* If nonzero, write log entries to a separate file. */ + bool use_logfile = false; -confbase = (char*) in; + confbase = (char*) in; - openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR); + openlogger("tinc", LOGMODE_STDERR); init_configuration(&config_tree); @@ -532,7 +525,6 @@ end: exit_configuration(&config_tree); free(cmdline_conf); - free_names(); return status; diff --git a/src/libmeshlink.h b/src/libmeshlink.h index e99f8957..4c7c4a95 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -19,7 +19,6 @@ #include "system.h" #include "node.h" -#include "names.h" //#include "tincctl.h" #include "xalloc.h" #include "logger.h" diff --git a/src/logger.c b/src/logger.c index 46120293..bceccbc6 100644 --- a/src/logger.c +++ b/src/logger.c @@ -22,7 +22,6 @@ #include "conf.h" #include "meta.h" -#include "names.h" #include "logger.h" #include "connection.h" #include "sptps.h" @@ -30,7 +29,6 @@ debug_t debug_level = DEBUG_NOTHING; static logmode_t logmode = LOGMODE_STDERR; static pid_t logpid; -static FILE *logfile = NULL; #ifdef HAVE_MINGW static HANDLE loghandle = NULL; #endif @@ -53,14 +51,6 @@ static void real_logger(int level, int priority, const char *message) { fprintf(stderr, "%s\n", message); fflush(stderr); break; - case LOGMODE_FILE: - if(!now.tv_sec) - gettimeofday(&now, NULL); - time_t now_sec = now.tv_sec; - strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now_sec)); - fprintf(logfile, "%s %s[%ld]: %s\n", timestr, logident, (long)logpid, message); - fflush(logfile); - break; case LOGMODE_SYSLOG: #ifdef HAVE_MINGW { @@ -110,14 +100,6 @@ void openlogger(const char *ident, logmode_t mode) { case LOGMODE_STDERR: logpid = getpid(); break; - case LOGMODE_FILE: - logpid = getpid(); - logfile = fopen(logfilename, "a"); - if(!logfile) { - fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno)); - logmode = LOGMODE_NULL; - } - break; case LOGMODE_SYSLOG: #ifdef HAVE_MINGW loghandle = RegisterEventSource(NULL, logident); @@ -142,26 +124,8 @@ void openlogger(const char *ident, logmode_t mode) { sptps_log = sptps_log_quiet; } -void reopenlogger() { - if(logmode != LOGMODE_FILE) - return; - - fflush(logfile); - FILE *newfile = fopen(logfilename, "a"); - if(!newfile) { - logger(DEBUG_ALWAYS, LOG_ERR, "Unable to reopen log file %s: %s", logfilename, strerror(errno)); - return; - } - fclose(logfile); - logfile = newfile; -} - - void closelogger(void) { switch(logmode) { - case LOGMODE_FILE: - fclose(logfile); - break; case LOGMODE_SYSLOG: #ifdef HAVE_MINGW DeregisterEventSource(loghandle); diff --git a/src/logger.h b/src/logger.h index 637eef84..f417b783 100644 --- a/src/logger.h +++ b/src/logger.h @@ -37,7 +37,6 @@ typedef enum debug_t { typedef enum logmode_t { LOGMODE_NULL, LOGMODE_STDERR, - LOGMODE_FILE, LOGMODE_SYSLOG } logmode_t; @@ -68,7 +67,6 @@ enum { extern debug_t debug_level; extern bool logcontrol; extern void openlogger(const char *, logmode_t); -extern void reopenlogger(void); extern void logger(int, int, const char *, ...) __attribute__ ((__format__(printf, 3, 4))); extern void closelogger(void); diff --git a/src/names.c b/src/names.c deleted file mode 100644 index 138c3cc0..00000000 --- a/src/names.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - names.c -- generate commonly used (file)names - Copyright (C) 1998-2005 Ivo Timmermans - 2000-2013 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "system.h" - -#include "logger.h" -#include "xalloc.h" - -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; - -/* - Set all files and paths according to netname -*/ -void make_names(void) { -#ifdef HAVE_MINGW - HKEY key; - char installdir[1024] = ""; - 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); - else - identname = xstrdup("tinc"); - -#ifdef HAVE_MINGW - if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) { - if(!RegQueryValueEx(key, NULL, 0, 0, (LPBYTE)installdir, &len)) { - confdir = xstrdup(installdir); - if(!logfilename) - xasprintf(&logfilename, "%s" SLASH "log" SLASH "%s.log", installdir, identname); - if(!confbase) { - if(netname) - xasprintf(&confbase, "%s" SLASH "%s", installdir, netname); - else - xasprintf(&confbase, "%s", installdir); - } - if(!pidfilename) - xasprintf(&pidfilename, "%s" SLASH "pid", confbase); - } - RegCloseKey(key); - } -#endif - if(!confdir) - confdir = xstrdup(CONFDIR SLASH "tinc"); - - if(!logfilename) - xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname); - - if(!pidfilename) - xasprintf(&pidfilename, SLASH "tmp" SLASH "%s.pid", 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(!confbase) { - if(netname) - xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname); - else - xasprintf(&confbase, CONFDIR SLASH "tinc"); - } -} - -void free_names(void) { - free(identname); - free(netname); - free(unixsocketname); - free(pidfilename); - free(logfilename); - free(confbase); - free(confdir); -} diff --git a/src/names.h b/src/names.h deleted file mode 100644 index 1163ff6e..00000000 --- a/src/names.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - names.h -- header for names.c - Copyright (C) 1998-2005 Ivo Timmermans - 2000-2013 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef __TINC_NAMES_H__ -#define __TINC_NAMES_H__ - -extern char *confdir; -extern char *confbase; -extern bool confbase_given; -extern char *netname; -extern char *identname; -extern char *unixsocketname; -extern char *logfilename; -extern char *pidfilename; -extern char *program_name; - -extern void make_names(void); -extern void free_names(void); - -#endif /* __TINC_NAMES_H__ */ diff --git a/src/net.c b/src/net.c index 415b0cff..cae86298 100644 --- a/src/net.c +++ b/src/net.c @@ -28,7 +28,6 @@ #include "graph.h" #include "logger.h" #include "meta.h" -#include "names.h" #include "net.h" #include "netutl.h" #include "protocol.h" @@ -41,6 +40,9 @@ time_t last_config_check = 0; static timeout_t pingtimer; static timeout_t periodictimer; +//TODO: move this to a better place +char *confbase; + /* Purge edges of unreachable nodes. Use carefully. */ // TODO: remove @@ -288,7 +290,6 @@ static void sigterm_handler(void *data) { static void sighup_handler(void *data) { logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s signal", strsignal(((signal_t *)data)->signum)); - reopenlogger(); if(reload_configuration()) exit(1); } diff --git a/src/net.h b/src/net.h index 59e77d7d..f534efdd 100644 --- a/src/net.h +++ b/src/net.h @@ -202,4 +202,7 @@ extern void load_all_nodes(void); extern CRITICAL_SECTION mutex; #endif +//TODO: move this to a better place +extern char *confbase; + #endif /* __TINC_NET_H__ */ diff --git a/src/net_setup.c b/src/net_setup.c index 34626070..35b301d8 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -29,7 +29,6 @@ #include "ecdsa.h" #include "graph.h" #include "logger.h" -#include "names.h" #include "net.h" #include "netutl.h" #include "protocol.h" @@ -185,7 +184,7 @@ static bool read_ecdsa_private_key(void) { if(!fp) { logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno)); if(errno == ENOENT) - logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc -n %s generate-ecdsa-keys'.", netname ?: "."); + logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc generate-ecdsa-keys'."); free(fname); return false; } diff --git a/src/net_socket.c b/src/net_socket.c index 2a47a72f..b8ed76d8 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -27,7 +27,6 @@ #include "list.h" #include "logger.h" #include "meta.h" -#include "names.h" #include "net.h" #include "netutl.h" #include "protocol.h" @@ -358,8 +357,6 @@ static void do_outgoing_pipe(connection_t *c, char *command) { setenv("REMOTEPORT", port, true); setenv("NODE", c->name, true); setenv("NAME", myself->name, true); - if(netname) - setenv("NETNAME", netname, true); int result = system(command); if(result < 0) diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 21f13a13..4caaf203 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -30,7 +30,6 @@ #include "graph.h" #include "logger.h" #include "meta.h" -#include "names.h" #include "net.h" #include "netutl.h" #include "node.h" diff --git a/src/tincctl.c b/src/tincctl.c index 81e7a7a2..a706f484 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -33,7 +33,6 @@ #include "ecdsagen.h" #include "info.h" #include "invitation.h" -#include "names.h" #include "rsagen.h" #include "utils.h" #include "tincctl.h" @@ -2098,7 +2097,6 @@ static int switch_network(char *name) { free(netname); netname = strcmp(name, ".") ? xstrdup(name) : NULL; - make_names(); xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase); xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); xasprintf(&prompt, "%s> ", identname); @@ -2414,7 +2412,6 @@ int main(int argc, char *argv[]) { if(!parse_options(argc, argv)) return 1; - make_names(); 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 3d521e5c..8c4655cd 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -48,7 +48,6 @@ #include "conf.h" #include "crypto.h" #include "logger.h" -#include "names.h" #include "net.h" #include "netutl.h" #include "protocol.h" @@ -77,9 +76,6 @@ static bool do_chroot = false; static const char *switchuser = NULL; #endif -/* If nonzero, write log entries to a separate file. */ -bool use_logfile = false; - char **g_argv; /* a copy of the cmdline arguments */ static int status = 1; @@ -95,8 +91,6 @@ static struct option const long_options[] = { {"mlock", no_argument, NULL, 'L'}, {"chroot", no_argument, NULL, 'R'}, {"user", required_argument, NULL, 'U'}, - {"logfile", optional_argument, NULL, 4}, - {"pidfile", required_argument, NULL, 5}, {"option", required_argument, NULL, 'o'}, {NULL, 0, NULL, 0} }; @@ -109,10 +103,9 @@ int main2(int argc, char **argv); static void usage(bool status) { if(status) - fprintf(stderr, "Try `%s --help\' for more information.\n", - program_name); + fprintf(stderr, "Try `tincd --help\' for more information.\n"); else { - printf("Usage: %s [option]...\n\n", program_name); + printf("Usage: tincd [option]...\n\n"); printf( " -c, --config=DIR Read configuration options from DIR.\n" " -D, --no-detach Don't fork and detach.\n" " -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n" @@ -120,8 +113,6 @@ static void usage(bool status) { #ifdef HAVE_MLOCKALL " -L, --mlock Lock tinc into main memory.\n" #endif - " --logfile[=FILENAME] Write log entries to a logfile.\n" - " --pidfile=FILENAME Write PID and control socket cookie to FILENAME.\n" " --bypass-security Disables meta protocol security, for debugging.\n" " -o, --option[HOST.]KEY=VALUE Set global/host configuration value.\n" #ifndef HAVE_MINGW @@ -169,10 +160,6 @@ static bool parse_options(int argc, char **argv) { debug_level++; break; - case 'n': /* net name given */ - netname = xstrdup(optarg); - break; - case 'o': /* option */ cfg = parse_config_line(optarg, NULL, ++lineno); if (!cfg) @@ -207,18 +194,6 @@ static bool parse_options(int argc, char **argv) { bypass_security = true; break; - case 4: /* write log entries to a file */ - use_logfile = true; - if(!optarg && optind < argc && *argv[optind] != '-') - optarg = argv[optind++]; - if(optarg) - logfilename = xstrdup(optarg); - break; - - case 5: /* open control socket here */ - pidfilename = xstrdup(optarg); - break; - case '?': /* wrong options */ usage(true); return false; @@ -234,21 +209,6 @@ static bool parse_options(int argc, char **argv) { return false; } - if(!netname && (netname = getenv("NETNAME"))) - netname = xstrdup(netname); - - /* netname "." is special: a "top-level name" */ - - if(netname && (!*netname || !strcmp(netname, "."))) { - free(netname); - netname = NULL; - } - - if(netname && (strpbrk(netname, "\\/") || *netname == '.')) { - fprintf(stderr, "Invalid character in netname!\n"); - return false; - } - return true; } @@ -304,13 +264,9 @@ static bool drop_privs(void) { #endif int main(int argc, char **argv) { - program_name = argv[0]; - if(!parse_options(argc, argv)) return 1; - make_names(); - if(show_version) { printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE, VERSION, __DATE__, __TIME__, PROT_MAJOR, PROT_MINOR); @@ -335,7 +291,7 @@ int main(int argc, char **argv) { } #endif - openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR); + openlogger("tinc", LOGMODE_STDERR); g_argv = argv; @@ -424,7 +380,6 @@ end: exit_configuration(&config_tree); free(cmdline_conf); - free_names(); return status; }