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"
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;
}
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"
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
}
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__
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__ */
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"
void terminate_connection(connection_t *cl)
{
connection_t *p;
- subnet_t *s;
+ subnet_t *subnet;
rbl_t *rbl;
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 */
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"
#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;
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);
*/
void cleanup_and_exit(int c)
{
+cp
close_network_connections();
if(debug_lvl > DEBUG_NOTHING)
int write_pidfile(void)
{
int pid;
-
+cp
if((pid = check_pid(pidfilename)))
{
if(netname)
/* if it's locked, write-protected, or whatever */
if(!write_pid(pidfilename))
return 1;
-
+cp
return 0;
}
int kill_other(void)
{
int pid;
-
+cp
if(!(pid = read_pid(pidfilename)))
{
if(netname)
if(kill(pid, SIGTERM) && errno == ESRCH)
fprintf(stderr, _("Removing stale lock file.\n"));
remove_pid(pidfilename);
-
+cp
return 0;
}
{
int fd;
pid_t pid;
-
+cp
setup_signals();
if(write_pidfile())
syslog(LOG_NOTICE, _("tincd %s starting"), VERSION);
xalloc_fail_func = memory_full;
-
+cp
return 0;
}
int error = 0;
char *scriptname;
char *s;
-
+cp
if(netname)
{
asprintf(&s, "NETNAME=%s", netname);
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);
}
{
pid_t pid;
int status;
-
+cp
pid = (pid_t) data;
pid = waitpid(pid, &status, WNOHANG);
if(WIFEXITED(status))
}
return -1;
}
-
+cp
/* Child is still running */
return 0;
}
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__
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);
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"
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
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"
if(read_server_config())
return 1;
+ init_processes();
+
if(detach())
exit(0);