Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
1326:78a3eaf5555f | 1327:85f297591693 |
---|---|
12 config TCPSVD | 12 config TCPSVD |
13 bool "tcpsvd" | 13 bool "tcpsvd" |
14 default n | 14 default n |
15 help | 15 help |
16 usage: tcpsvd [-hEv] [-c N] [-C N[:MSG]] [-b N] [-u User] [-l Name] IP Port Prog | 16 usage: tcpsvd [-hEv] [-c N] [-C N[:MSG]] [-b N] [-u User] [-l Name] IP Port Prog |
17 udpsvd [-hEv] [-c N] [-u User] [-l Name] IP Port Prog | 17 usage: udpsvd [-hEv] [-c N] [-u User] [-l Name] IP Port Prog |
18 | 18 |
19 Create TCP/UDP socket, bind to IP:PORT and listen for incoming connection. | 19 Create TCP/UDP socket, bind to IP:PORT and listen for incoming connection. |
20 Run PROG for each connection. | 20 Run PROG for each connection. |
21 | 21 |
22 IP IP to listen on, 0 = all | 22 IP IP to listen on, 0 = all |
348 newnode->next = h[hash].head; | 348 newnode->next = h[hash].head; |
349 h[hash].head = newnode; | 349 h[hash].head = newnode; |
350 h[hash].head->count++; | 350 h[hash].head->count++; |
351 } | 351 } |
352 | 352 |
353 if (!(pid = fork())) { | 353 if (!(pid = xfork())) { |
354 char *serv = NULL, *clie = NULL; | 354 char *serv = NULL, *clie = NULL; |
355 char *client = sock_to_address((struct sockaddr*)buf, NI_NUMERICHOST | NI_NUMERICSERV); | 355 char *client = sock_to_address((struct sockaddr*)buf, NI_NUMERICHOST | NI_NUMERICSERV); |
356 if (toys.optflags & FLAG_h) { //lookup name | 356 if (toys.optflags & FLAG_h) { //lookup name |
357 if (toys.optflags & FLAG_l) serv = xstrdup(TT.name); | 357 if (toys.optflags & FLAG_l) serv = xstrdup(TT.name); |
358 else serv = sock_to_address((struct sockaddr*)&haddr, 0); | 358 else serv = sock_to_address((struct sockaddr*)&haddr, 0); |
391 close(0); | 391 close(0); |
392 close(1); | 392 close(1); |
393 dup2(newfd, 0); | 393 dup2(newfd, 0); |
394 dup2(newfd, 1); | 394 dup2(newfd, 1); |
395 xexec_optargs(2); //skip IP PORT | 395 xexec_optargs(2); //skip IP PORT |
396 } else if(pid > 0) { | 396 } else { |
397 insert(&pids, pid, addr); | 397 insert(&pids, pid, addr); |
398 xclose(newfd); //close and reopen for next client. | 398 xclose(newfd); //close and reopen for next client. |
399 if (TT.udp) fd = create_bind_sock(toys.optargs[0], | 399 if (TT.udp) fd = create_bind_sock(toys.optargs[0], |
400 (struct sockaddr*)&haddr); | 400 (struct sockaddr*)&haddr); |
401 } else error_msg(" fork failed"); | 401 } |
402 } //while(1) | 402 } //while(1) |
403 } | 403 } |