]> git.meshlink.io Git - meshlink/commitdiff
Move make_names() and related variables to its own source file.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 Jan 2013 15:39:02 +0000 (16:39 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 Jan 2013 15:39:02 +0000 (16:39 +0100)
23 files changed:
src/Makefile.am
src/bsd/device.c
src/conf.c
src/conf.h
src/control.c
src/cygwin/device.c
src/graph.c
src/linux/device.c
src/logger.c
src/mingw/device.c
src/names.c [new file with mode: 0644]
src/names.h [new file with mode: 0644]
src/net.c
src/net_setup.c
src/net_socket.c
src/process.c
src/solaris/device.c
src/subnet.c
src/tincctl.c
src/tincd.c
src/top.c
src/uml_device.c
src/vde_device.c

index 6a8737b65d5ab2aa69484a26a77f164bb39d3819..ea4da6df9c06611793f623d80b40fea11e1075eb 100644 (file)
@@ -9,7 +9,7 @@ tincd_SOURCES = \
        buffer.c conf.c connection.c control.c edge.c graph.c logger.c meta.c net.c net_packet.c net_setup.c \
        net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \
        protocol_key.c protocol_subnet.c route.c sptps.c subnet.c subnet_parse.c event.c tincd.c \
-       dummy_device.c raw_socket_device.c multicast_device.c
+       dummy_device.c raw_socket_device.c multicast_device.c names.c
        
 if UML
 tincd_SOURCES += uml_device.c
@@ -24,7 +24,7 @@ nodist_tincd_SOURCES = \
 
 tincctl_SOURCES = \
        utils.c getopt.c getopt1.c dropin.c \
-       info.c list.c subnet_parse.c tincctl.c top.c
+       info.c list.c subnet_parse.c tincctl.c top.c names.c
 
 nodist_tincctl_SOURCES = \
        ecdsagen.c rsagen.c
index dd351459025d8af9a0689fb335930a722c4c2bb7..fa580caca50e32c7dc6b6fe22ffa421bcc484117 100644 (file)
@@ -24,6 +24,7 @@
 #include "conf.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "route.h"
 #include "utils.h"
index b9bfbf67ace863bc09d09d05f64ec6c2aa36bd14..46fd81d57d3897cbcb1f341e00afa8a7cb8aa402 100644 (file)
@@ -28,6 +28,7 @@
 #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 */
@@ -37,11 +38,8 @@ splay_tree_t *config_tree;
 
 int pinginterval = 0;           /* seconds between pings */
 int pingtimeout = 0;            /* seconds to wait for response */
-char *confbase = NULL;          /* directory in which all config files are */
-char *netname = NULL;           /* name of the vpn network */
 list_t *cmdline_conf = NULL;    /* global/host configuration values given at the command line */
 
-
 static int config_compare(const config_t *a, const config_t *b) {
        int result;
 
index 20a78a917b8304c0d1d17297fd7b67afd3c1d229..5395322e6bee3519869bda6b87f58e507670868b 100644 (file)
@@ -39,8 +39,6 @@ extern int pinginterval;
 extern int pingtimeout;
 extern int maxtimeout;
 extern bool bypass_security;
-extern char *confbase;
-extern char *netname;
 extern list_t *cmdline_conf;
 
 extern void init_configuration(splay_tree_t **);
index 83a9d79cb054bd03e6081129b7b55891f05973d9..cc5bbb0a016db770b90b93631e1b121d3b598ed9 100644 (file)
@@ -25,6 +25,7 @@
 #include "graph.h"
 #include "logger.h"
 #include "meta.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "protocol.h"
@@ -33,7 +34,6 @@
 #include "xalloc.h"
 
 char controlcookie[65];
-extern char *pidfilename;
 
 static bool control_return(connection_t *c, int type, int error) {
        return send_request(c, "%d %d %d", CONTROL, type, error);
index 6266e87e4d270d7c0839bae782bf614d4d03fcf3..c028cbf9766864077ab3b7bf660d52bb977a0b87 100644 (file)
@@ -26,6 +26,7 @@
 #include "conf.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "route.h"
 #include "utils.h"
index 4cf30eb739dee321dd760003ff40a927f5d72a90..e5f70902f95b0ca2b4650d212665ee01ec47f103 100644 (file)
@@ -51,6 +51,7 @@
 #include "graph.h"
 #include "list.h"
 #include "logger.h"
+#include "names.h"
 #include "netutl.h"
 #include "node.h"
 #include "process.h"
index 18f1b6e574686219b432566656bc1188d2a8b0c1..45df6382352bb9c9a53b45657263ecca6e0765dd 100644 (file)
@@ -26,6 +26,7 @@
 #include "conf.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "route.h"
 #include "utils.h"
index e01980e9480a7ff86b86bef99ac224bcdba868cd..6fb972d136149674779661ba4b28fbacf2d328ac 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "conf.h"
 #include "meta.h"
+#include "names.h"
 #include "logger.h"
 #include "connection.h"
 #include "control_common.h"
@@ -30,7 +31,6 @@
 debug_t debug_level = DEBUG_NOTHING;
 static logmode_t logmode = LOGMODE_STDERR;
 static pid_t logpid;
-extern char *logfilename;
 static FILE *logfile = NULL;
 #ifdef HAVE_MINGW
 static HANDLE loghandle = NULL;
index 3b1458c6251ac3321bec154fa6d2bd94c26115a0..00644dba95a951ccc386dd373688abda4d304d99 100644 (file)
@@ -26,6 +26,7 @@
 #include "conf.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "route.h"
 #include "utils.h"
diff --git a/src/names.c b/src/names.c
new file mode 100644 (file)
index 0000000..5a5270a
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+    names.c -- generate commonly used (file)names
+    Copyright (C) 1998-2005 Ivo Timmermans
+                  2000-2013 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
+    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 */
+char *identname = NULL;         /* program name for syslog */
+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] = "";
+       long len = sizeof installdir;
+#endif
+
+       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, 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);
+
+       if(!logfilename)
+               xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
+
+       if(!pidfilename)
+               xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
+
+       if(netname) {
+               if(!confbase)
+                       xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
+               else
+                       logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
+       } else {
+               if(!confbase)
+                       xasprintf(&confbase, CONFDIR SLASH "tinc");
+       }
+}
+
+void free_names(void) {
+       free(identname);
+       free(netname);
+       free(pidfilename);
+       free(logfilename);
+       free(confbase);
+       free(confdir);
+}
diff --git a/src/names.h b/src/names.h
new file mode 100644 (file)
index 0000000..aef8b45
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+    names.h -- header for names.c
+    Copyright (C) 1998-2005 Ivo Timmermans
+                  2000-2013 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
+    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 char *netname;
+extern char *identname;
+extern char *logfilename;
+extern char *pidfilename;
+extern char *program_name;
+
+extern void make_names(void);
+extern void free_names(void);
+
+#endif /* __TINC_NAMES_H__ */
index 343ac71767040cdc9083aedabe7a102d4b59c5a6..f34c8c632d207fcf34728d9706d1f18610f536fa 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -29,6 +29,7 @@
 #include "graph.h"
 #include "logger.h"
 #include "meta.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "process.h"
index c5c83e7b0295de546482628498d6daf1a71f8f47..0e424eef5594dc0db10148c68f8c158b6e3c9be3 100644 (file)
@@ -31,6 +31,7 @@
 #include "ecdsa.h"
 #include "graph.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "process.h"
index 212649ba67f94c7013f0e65a302038caea6066ab..051955bf4401a4f79ceb1cd76649bb5e242a38f3 100644 (file)
@@ -27,6 +27,7 @@
 #include "list.h"
 #include "logger.h"
 #include "meta.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "protocol.h"
index 2fd3d936da6757aaa9a22e43926d1717c887dfa5..04c19ed9ee3164989dc4fb6284d9c9b1ca5100e3 100644 (file)
@@ -27,6 +27,7 @@
 #include "edge.h"
 #include "event.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "node.h"
 #include "process.h"
 bool do_detach = true;
 bool sigalrm = false;
 
-extern char *identname;
 extern char **g_argv;
 extern bool use_logfile;
 
 /* Some functions the less gifted operating systems might lack... */
 
 #ifdef HAVE_MINGW
-extern char *identname;
-extern char *program_name;
-extern char **g_argv;
-
 static SC_HANDLE manager = NULL;
 static SC_HANDLE service = NULL;
 static SERVICE_STATUS status = {0};
index cb2ece799891c8fd62a6f1b0b7c872dd817e96e6..03f7fe9e62398b486b648e65f45a50dd0cfe33be 100644 (file)
@@ -28,6 +28,7 @@
 #include "conf.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "utils.h"
 #include "xalloc.h"
index 4b6c068688ff787a125cfb15c9cfce86d5bd0add..06fee32f5a217861ad6a943bc66f66152a573868 100644 (file)
@@ -25,6 +25,7 @@
 #include "device.h"
 #include "hash.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "node.h"
index 6b36aa740f241f4e9a2db3106cd66d1a3d61d774..1576ba86a3c6de6cb9bf70bc3929f527cccdf4d1 100644 (file)
@@ -31,6 +31,7 @@
 #include "control_common.h"
 #include "ecdsagen.h"
 #include "info.h"
+#include "names.h"
 #include "rsagen.h"
 #include "utils.h"
 #include "tincctl.h"
 #define mkdir(a, b) mkdir(a)
 #endif
 
-
-/* The name this program was run with. */
-static char *program_name = NULL;
-
 static char **orig_argv;
 static int orig_argc;
 
@@ -54,12 +51,7 @@ static bool show_help = false;
 static bool show_version = false;
 
 static char *name = NULL;
-static char *identname = NULL;          /* program name for syslog */
-static char *pidfilename = NULL;        /* pid file location */
-static char *confdir = NULL;
 static char controlcookie[1025];
-char *netname = NULL;
-char *confbase = NULL;
 static char *tinc_conf = NULL;
 static char *hosts_dir = NULL;
 struct timeval now;
@@ -107,10 +99,9 @@ static void version(void) {
 }
 
 static void usage(bool status) {
-       if(status)
-               fprintf(stderr, "Try `%s --help\' for more information.\n",
-                               program_name);
-       else {
+       if(status) {
+               fprintf(stderr, "Try `%s --help\' for more information.\n", program_name);
+       } else {
                printf("Usage: %s [options] command\n\n", program_name);
                printf("Valid options are:\n"
                                "  -c, --config=DIR        Read configuration options from DIR.\n"
@@ -455,62 +446,6 @@ static bool rsa_keygen(int bits, bool ask) {
        return true;
 }
 
-/*
-  Set all files and paths according to netname
-*/
-static void make_names(void) {
-#ifdef HAVE_MINGW
-       HKEY key;
-       char installdir[1024] = "";
-       long len = sizeof installdir;
-#endif
-
-       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, installdir, &len)) {
-                       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);
-       }
-
-       if(!*installdir) {
-#endif
-       confdir = xstrdup(CONFDIR);
-
-       if(!pidfilename)
-               xasprintf(&pidfilename, "%s" SLASH "run" SLASH "%s.pid", LOCALSTATEDIR, identname);
-
-       if(netname) {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
-               else
-                       fprintf(stderr, "Both netname and configuration directory given, using the latter...\n");
-       } else {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc");
-       }
-
-#ifdef HAVE_MINGW
-       } else
-               confdir = xstrdup(installdir);
-#endif
-
-       xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
-       xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
-}
-
 static char buffer[4096];
 static size_t blen = 0;
 
@@ -2285,6 +2220,8 @@ int main(int argc, char *argv[]) {
                return 1;
 
        make_names();
+       xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
+       xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
 
        if(show_version) {
                version();
index 5d7158916cd3ae30a94e907c6a3ff194c3fc55ca..cd49400b6d5c718a63be13c4a6127bb177ae2f3d 100644 (file)
@@ -56,6 +56,7 @@
 #include "crypto.h"
 #include "device.h"
 #include "logger.h"
+#include "names.h"
 #include "net.h"
 #include "netutl.h"
 #include "process.h"
@@ -63,9 +64,6 @@
 #include "utils.h"
 #include "xalloc.h"
 
-/* The name this program was run with. */
-char *program_name = NULL;
-
 /* If nonzero, display usage information and exit. */
 static bool show_help = false;
 
@@ -87,9 +85,6 @@ static const char *switchuser = NULL;
 /* If nonzero, write log entries to a separate file. */
 bool use_logfile = false;
 
-char *identname = NULL;         /* program name for syslog */
-char *logfilename = NULL;       /* log file location */
-char *pidfilename = NULL;
 char **g_argv;                  /* a copy of the cmdline arguments */
 
 static int status = 1;
@@ -256,66 +251,6 @@ static bool parse_options(int argc, char **argv) {
        return true;
 }
 
-/*
-  Set all files and paths according to netname
-*/
-static void make_names(void) {
-#ifdef HAVE_MINGW
-       HKEY key;
-       char installdir[1024] = "";
-       long len = sizeof installdir;
-#endif
-
-       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, installdir, &len)) {
-                       if(!logfilename)
-                               xasprintf(&logfilename, "%s" SLASH "log" SLASH "%s.log", 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);
-               if(*installdir)
-                       return;
-       }
-#endif
-
-       if(!logfilename)
-               xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
-
-       if(!pidfilename)
-               xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
-
-       if(netname) {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
-               else
-                       logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
-       } else {
-               if(!confbase)
-                       xasprintf(&confbase, CONFDIR SLASH "tinc");
-       }
-}
-
-static void free_names(void) {
-       if (identname) free(identname);
-       if (netname) free(netname);
-       if (pidfilename) free(pidfilename);
-       if (logfilename) free(logfilename);
-       if (confbase) free(confbase);
-}
-
 static bool drop_privs(void) {
 #ifdef HAVE_MINGW
        return false;
index 28ab56f486fe7d71c2b86e6130ef395bfa13dc2b..aafc2a4418702b134ce2d48b2d7c8861450baaf2 100644 (file)
--- a/src/top.c
+++ b/src/top.c
@@ -25,6 +25,7 @@
 
 #include "control_common.h"
 #include "list.h"
+#include "names.h"
 #include "tincctl.h"
 #include "top.h"
 #include "xalloc.h"
index afdded5ebf83a2b47aa397a4bbb7ba27549d4f65..b5f9c12bdf167507addb1ac6cfd21c83e71100cf 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "conf.h"
 #include "device.h"
+#include "names.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"
@@ -37,7 +38,6 @@ static int write_fd = -1;
 static int state = 0;
 static char *device_info;
 
-extern char *identname;
 extern volatile bool running;
 
 static uint64_t device_total_in = 0;
index 815b956fbeae12f417fde3633f3f870196a484be..64394af97b75e1ee8c7424135d23a7f2ae2ff558 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "conf.h"
 #include "device.h"
+#include "names.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"
@@ -35,7 +36,6 @@ static int port = 0;
 static char *group = NULL;
 static char *device_info;
 
-extern char *identname;
 extern volatile bool running;
 
 static uint64_t device_total_in = 0;