Browse Source

Added zombie reap code to door32.

Steve Thielemann 2 years ago
parent
commit
9610e261ef
2 changed files with 18 additions and 4 deletions
  1. 1 0
      Makefile
  2. 17 4
      door32.c

+ 1 - 0
Makefile

@@ -8,6 +8,7 @@ font-out: font-out.go
 
 
 door32: door32.c
+	gcc -g -o door32d door32.c
 	gcc -o door32 door32.c
 
 testdoor/fonts.go: font-out

+ 17 - 4
door32.c

@@ -6,6 +6,11 @@
 #include <termios.h>
 #include <unistd.h>
 
+// auto zombie reaping
+#include <errno.h>
+#include <signal.h>
+#include <sys/wait.h>
+
 void doprocessing(int sock);
 char *cmds[10];
 
@@ -23,7 +28,7 @@ int drain(int fd) {
   char buffer[21];
   int total = 0;
 
-   printf("draining... \n");
+  printf("draining... \n");
 
   do {
     FD_ZERO(&set);
@@ -47,6 +52,12 @@ int main(int argc, char *argv[]) {
   struct sockaddr_in serv_addr, cli_addr;
   int n, pid;
 
+  // Automatically reap zombies.
+  if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
+    perror(0);
+    exit(1);
+  }
+
   /* First call to socket() function */
   sockfd = socket(AF_INET, SOCK_STREAM, 0);
 
@@ -62,8 +73,10 @@ int main(int argc, char *argv[]) {
 
   int listen_port = atoi(argv[1]);
   char *command = strdup(argv[2]);
+  printf("Port %d Cmd [%s]\n", listen_port, command);
+
   char *cp;
-  int cmd_count;
+  int cmd_count = 0;
   cp = command;
   cmds[cmd_count] = cp;
   cmd_count++;
@@ -171,7 +184,7 @@ void doprocessing(int sock) {
   https://stackoverflow.com/questions/10413963/telnet-iac-command-answering
   http://ryobbs.com/doku.php/terminal_iac
   https://www.omnisecu.com/tcpip/telnet-commands-and-options.php
-  
+
    */
   write(sock, "\xff\xfb\x01", 3);
   // drain(sock);
@@ -181,7 +194,7 @@ void doprocessing(int sock) {
   // write(sock, "\xff\xfc\x22", 3);
 
   // syncterm is slow.  It needs time to drain.  :()
-  
+
   drain(sock);
   // drain(sock);
   /*