X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=8d92cc10088c305ded504ce6246648a9ba2f163e;hp=09d98f41b4fe0c2b1df170d6f91786edfefdb50d;hb=485f7a5043a4b3345bd02e5063502603550b4c76;hpb=596e248bc588323cc7ee751286dbcaf677b5c653 diff --git a/src/net.c b/src/net.c index 09d98f41..8d92cc10 100644 --- a/src/net.c +++ b/src/net.c @@ -17,17 +17,13 @@ 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.72 2000/11/15 01:28:21 zarq Exp $ + $Id: net.c,v 1.35.4.76 2000/11/16 22:11:40 zarq Exp $ */ #include "config.h" -#include #include #include -/* SunOS really wants sys/socket.h BEFORE net/if.h */ -#include -#include #include #include #include @@ -39,6 +35,11 @@ #include #include #include +/* SunOS really wants sys/socket.h BEFORE net/if.h, + and FreeBSD wants these lines below the rest. */ +#include +#include +#include #ifdef HAVE_OPENSSL_RAND_H # include @@ -67,9 +68,11 @@ #include "conf.h" #include "connlist.h" +#include "list.h" #include "meta.h" #include "net.h" #include "netutl.h" +#include "process.h" #include "protocol.h" #include "subnet.h" @@ -92,97 +95,6 @@ char *unknown = NULL; subnet_t mymac; -/* - Execute the given script. - This function doesn't really belong here. -*/ -int execute_script(const char *name) -{ - char *scriptname; - pid_t pid; - char *s; - int error; - - if((pid = fork()) < 0) - { - syslog(LOG_ERR, _("System call `%s' failed: %m"), - "fork"); - return -1; - } - - if(pid) - { - return 0; - } - - /* Child here */ - - error = 0; - - if(netname) - { - asprintf(&s, "NETNAME=%s", netname); - putenv(s); /* Don't free s! see man 3 putenv */ - } -#ifdef HAVE_UNSETENV - else - { - unsetenv("NETNAME"); - } -#endif - - if(chdir(confbase) < 0) - /* This cannot fail since we already read config files from this - directory. - Guus */ - /* Yes this can fail, somebody could have removed this directory - when we didn't pay attention. - Ivo */ - { - if(chdir("/") < 0) - /* Now if THIS fails, something wicked is going on. - Ivo */ - syslog(LOG_ERR, _("Couldn't chdir to `/': %m")); - - /* Continue anyway. */ - } - - asprintf(&scriptname, "%s/%s", confbase, name); - - /* Close all file descriptors */ - closelog(); - fcloseall(); - - /* Open standard input */ - if(open("/dev/null", O_RDONLY) < 0) - { - syslog(LOG_ERR, _("Opening `/dev/null' failed: %m")); - error = 1; - } - - if(!error) - { - /* Standard output directly goes to syslog */ - openlog(name, LOG_CONS | LOG_PID, LOG_DAEMON); - /* Standard error as well */ - if(dup2(1, 2) < 0) - { - syslog(LOG_ERR, _("System call `%s' failed: %m"), - "dup2"); - error = 1; - } - } - - if(error && debug_lvl > 1) - syslog(LOG_INFO, _("This means that any output the script generates will not be shown in syslog.")); - - execl(scriptname, NULL); - /* No return on success */ - - if(errno != ENOENT) /* Ignore if the file does not exist */ - syslog(LOG_WARNING, _("Error executing `%s': %m"), scriptname); - - /* No need to free things */ - exit(0); -} - int xsend(conn_list_t *cl, vpn_packet_t *inpkt) { vpn_packet_t outpkt; @@ -472,7 +384,6 @@ int setup_tap_fd(void) int nfd; const char *tapfname; config_t const *cfg; - struct ifreq ifr; cp if((cfg = get_config_val(config, config_tapdevice))) @@ -892,6 +803,8 @@ cp myself->status.active = 1; syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port); + + child_pids = list_new(); cp return 0; } @@ -1097,7 +1010,7 @@ conn_list_t *create_new_connection(int sfd) cp p = new_conn_list(); - if(getpeername(sfd, &ci, &len) < 0) + if(getpeername(sfd, (struct sockaddr *) &ci, (socklen_t *) &len) < 0) { syslog(LOG_ERR, _("System call `%s' failed: %m"), "getpeername"); @@ -1480,6 +1393,8 @@ cp if(FD_ISSET(tap_fd, &fset)) handle_tap_input(); } + + check_children(); } cp }