Mercurial > hg > toybox
diff toys/pending/tcpsvd.c @ 1327:85f297591693 draft
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 31 May 2014 12:33:24 -0500 |
parents | 0752b2d58909 |
children | 5fac2769a159 |
line wrap: on
line diff
--- a/toys/pending/tcpsvd.c Thu May 29 08:21:48 2014 -0500 +++ b/toys/pending/tcpsvd.c Sat May 31 12:33:24 2014 -0500 @@ -14,7 +14,7 @@ default n help usage: tcpsvd [-hEv] [-c N] [-C N[:MSG]] [-b N] [-u User] [-l Name] IP Port Prog - udpsvd [-hEv] [-c N] [-u User] [-l Name] IP Port Prog + usage: udpsvd [-hEv] [-c N] [-u User] [-l Name] IP Port Prog Create TCP/UDP socket, bind to IP:PORT and listen for incoming connection. Run PROG for each connection. @@ -350,7 +350,7 @@ h[hash].head->count++; } - if (!(pid = fork())) { + if (!(pid = xfork())) { char *serv = NULL, *clie = NULL; char *client = sock_to_address((struct sockaddr*)buf, NI_NUMERICHOST | NI_NUMERICSERV); if (toys.optflags & FLAG_h) { //lookup name @@ -393,11 +393,11 @@ dup2(newfd, 0); dup2(newfd, 1); xexec_optargs(2); //skip IP PORT - } else if(pid > 0) { + } else { insert(&pids, pid, addr); xclose(newfd); //close and reopen for next client. if (TT.udp) fd = create_bind_sock(toys.optargs[0], (struct sockaddr*)&haddr); - } else error_msg(" fork failed"); + } } //while(1) }