From 3a6200c1e39b61b249db3d1f9bcffa77351863bd Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 20 Nov 2000 22:13:14 +0000 Subject: [PATCH] - Various small fixes. --- lib/list.c | 5 +++-- src/connection.c | 10 +++++++--- src/connection.h | 4 ++-- src/net.c | 10 +++++++--- src/process.c | 40 +++++++++++++++++++++++++--------------- src/process.h | 3 ++- src/subnet.c | 3 ++- src/tincd.c | 4 +++- 8 files changed, 51 insertions(+), 28 deletions(-) diff --git a/lib/list.c b/lib/list.c index a09cbea..6ade9e8 100644 --- a/lib/list.c +++ b/lib/list.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: list.c,v 1.1.2.2 2000/11/16 22:13:08 zarq Exp $ + $Id: list.c,v 1.1.2.3 2000/11/20 22:13:00 guus Exp $ */ #include "config.h" @@ -143,6 +143,7 @@ void list_append(list_t *list, void *data) n = xmalloc_and_zero(sizeof(list_node_t)); n->data = data; n->prev = list->tail; - list->tail->next = n; + if(list->tail) + list->tail->next = n; list->tail = n; } diff --git a/src/connection.c b/src/connection.c index 46d82d2..772b3c3 100644 --- a/src/connection.c +++ b/src/connection.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.c,v 1.1.2.2 2000/11/20 19:41:10 guus Exp $ + $Id: connection.c,v 1.1.2.3 2000/11/20 22:13:03 guus Exp $ */ #include "config.h" @@ -138,10 +138,14 @@ cp connection_t *lookup_id(char *name) { - connection_t cl; + connection_t cl, *p; cp cl.name = name; - return rbl_search(connection_tree, &cl); + p = rbl_search(connection_tree, &cl); + if(p && p->status.active) + return p; + else + return NULL; cp } diff --git a/src/connection.h b/src/connection.h index 0597299..6039894 100644 --- a/src/connection.h +++ b/src/connection.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.h,v 1.1.2.1 2000/11/20 19:12:11 guus Exp $ + $Id: connection.h,v 1.1.2.2 2000/11/20 22:13:03 guus Exp $ */ #ifndef __TINC_CONNECTION_H__ @@ -116,7 +116,7 @@ extern void connection_del(connection_t *); extern connection_t *lookup_id(char *); extern void dump_connection_list(void); extern int read_host_config(connection_t *); -extern void destroy_connection(void); +extern void destroy_connection_tree(void); extern void prune_connection_tree(void); #endif /* __TINC_CONNECTION_H__ */ diff --git a/src/net.c b/src/net.c index 86223b9..f1593b6 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.78 2000/11/20 19:41:10 guus Exp $ + $Id: net.c,v 1.35.4.79 2000/11/20 22:13:03 guus Exp $ */ #include "config.h" @@ -1113,7 +1113,7 @@ cp void terminate_connection(connection_t *cl) { connection_t *p; - subnet_t *s; + subnet_t *subnet; rbl_t *rbl; cp @@ -1155,7 +1155,11 @@ cp /* Remove the associated subnets */ - rbl_delete_rbltree(cl->subnet_tree); + RBL_FOREACH(cl->subnet_tree, rbl) + { + subnet = (subnet_t *)rbl->data; + subnet_del(subnet); + } /* Check if this was our outgoing connection */ diff --git a/src/process.c b/src/process.c index 6491bfc..ca992dc 100644 --- a/src/process.c +++ b/src/process.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c,v 1.1.2.5 2000/11/20 19:12:13 guus Exp $ + $Id: process.c,v 1.1.2.6 2000/11/20 22:13:12 guus Exp $ */ #include "config.h" @@ -44,7 +44,7 @@ #include "system.h" /* A list containing all our children */ -list_t *child_pids; +list_t *child_pids = NULL; /* If zero, don't detach from the terminal. */ int do_detach = 1; @@ -55,6 +55,13 @@ extern char *identname; extern char *pidfilename; extern char **g_argv; +void init_processes(void) +{ +cp + child_pids = list_new(); +cp +} + void memory_full(int size) { syslog(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exiting."), size); @@ -67,6 +74,7 @@ void memory_full(int size) */ void cleanup_and_exit(int c) { +cp close_network_connections(); if(debug_lvl > DEBUG_NOTHING) @@ -84,7 +92,7 @@ void cleanup_and_exit(int c) int write_pidfile(void) { int pid; - +cp if((pid = check_pid(pidfilename))) { if(netname) @@ -98,7 +106,7 @@ int write_pidfile(void) /* if it's locked, write-protected, or whatever */ if(!write_pid(pidfilename)) return 1; - +cp return 0; } @@ -108,7 +116,7 @@ int write_pidfile(void) int kill_other(void) { int pid; - +cp if(!(pid = read_pid(pidfilename))) { if(netname) @@ -123,7 +131,7 @@ int kill_other(void) if(kill(pid, SIGTERM) && errno == ESRCH) fprintf(stderr, _("Removing stale lock file.\n")); remove_pid(pidfilename); - +cp return 0; } @@ -134,7 +142,7 @@ int detach(void) { int fd; pid_t pid; - +cp setup_signals(); if(write_pidfile()) @@ -152,7 +160,7 @@ int detach(void) syslog(LOG_NOTICE, _("tincd %s starting"), VERSION); xalloc_fail_func = memory_full; - +cp return 0; } @@ -166,7 +174,7 @@ void _execute_script(const char *name) int error = 0; char *scriptname; char *s; - +cp if(netname) { asprintf(&s, "NETNAME=%s", netname); @@ -237,20 +245,22 @@ void _execute_script(const char *name) int execute_script(const char *name) { pid_t pid; - +cp if((pid = fork()) < 0) { syslog(LOG_ERR, _("System call `%s' failed: %m"), "fork"); return -1; } - +cp if(pid) { - list_append(child_pids, (void*)(int)pid); + syslog(LOG_DEBUG, "%p, %d (%p)", child_pids, pid, &pid); + list_append(child_pids, &pid); +cp return 0; } - +cp /* Child here */ _execute_script(name); } @@ -264,7 +274,7 @@ int check_child(void *data) { pid_t pid; int status; - +cp pid = (pid_t) data; pid = waitpid(pid, &status, WNOHANG); if(WIFEXITED(status)) @@ -282,7 +292,7 @@ int check_child(void *data) } return -1; } - +cp /* Child is still running */ return 0; } diff --git a/src/process.h b/src/process.h index 4f501b2..ce35761 100644 --- a/src/process.h +++ b/src/process.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.h,v 1.1.2.2 2000/11/16 22:12:23 zarq Exp $ + $Id: process.h,v 1.1.2.3 2000/11/20 22:13:13 guus Exp $ */ #ifndef __TINC_PROCESS_H__ @@ -29,6 +29,7 @@ extern list_t *child_pids; extern RETSIGTYPE parent_exit(int a); +extern void init_processes(void); extern void setup_signals(void); extern int execute_script(const char *); extern void check_children(void); diff --git a/src/subnet.c b/src/subnet.c index fcbc45a..8e50646 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: subnet.c,v 1.1.2.13 2000/11/20 19:41:13 guus Exp $ + $Id: subnet.c,v 1.1.2.14 2000/11/20 22:13:13 guus Exp $ */ #include "config.h" @@ -130,6 +130,7 @@ cp void subnet_add(connection_t *cl, subnet_t *subnet) { cp + subnet->owner = cl; rbl_insert(subnet_tree, subnet); rbl_insert(cl->subnet_tree, subnet); cp diff --git a/src/tincd.c b/src/tincd.c index 224a9f9..7118d1f 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10.4.31 2000/11/20 18:06:17 zarq Exp $ + $Id: tincd.c,v 1.10.4.32 2000/11/20 22:13:14 guus Exp $ */ #include "config.h" @@ -321,6 +321,8 @@ main(int argc, char **argv, char **envp) if(read_server_config()) return 1; + init_processes(); + if(detach()) exit(0); -- 2.25.1