comparison nnchat.c @ 128:713879a7ca10

Wait for forked processes, to prevent a zombie apocalypse.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 12:15:55 +0300
parents d03ebefb92a6
children 4235ff4ced04
comparison
equal deleted inserted replaced
127:f741718d13c5 128:713879a7ca10
9 #include <string.h> 9 #include <string.h>
10 #include <errno.h> 10 #include <errno.h>
11 #ifdef __WIN32 11 #ifdef __WIN32
12 /* Undefine because both windows.h and curses.h #define it */ 12 /* Undefine because both windows.h and curses.h #define it */
13 #undef MOUSE_MOVED 13 #undef MOUSE_MOVED
14 #else
15 #include <sys/wait.h>
14 #endif 16 #endif
15 #include <curses.h> 17 #include <curses.h>
16 18
17 19
18 #define SET_MAX_BACKBUF (1024) 20 #define SET_MAX_BACKBUF (1024)
576 return 0; 578 return 0;
577 } else if (!strncasecmp(buf, "/w ", 3)) { 579 } else if (!strncasecmp(buf, "/w ", 3)) {
578 /* Open given username's profile via firefox in a new tab */ 580 /* Open given username's profile via firefox in a new tab */
579 char *name = trimLeft(buf + 3), 581 char *name = trimLeft(buf + 3),
580 *browser = getenv("BROWSER"); 582 *browser = getenv("BROWSER");
581 pid_t pid;
582 583
583 if (browser == NULL) 584 if (browser == NULL)
584 browser = "firefox"; 585 browser = "firefox";
585 586
586 printMsg("Opening profile for: '%s'\n", name); 587 printMsg("Opening profile for: '%s'\n", name);
587 588
588 tmpStr = nn_encode_str1(name); 589 tmpStr = nn_encode_str1(name);
589 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr); 590 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr);
590 th_free(tmpStr); 591 th_free(tmpStr);
591 592
593 #ifdef __WIN32
594
595 #else
596 {
597 int status;
598 pid_t pid;
592 if ((pid = fork()) < 0) { 599 if ((pid = fork()) < 0) {
593 printMsg("Could not create sub-process!\n"); 600 printMsg("Could not create sub-process!\n");
594 } else if (pid == 0) { 601 } else if (pid == 0) {
595 execlp(browser, browser, "-remote", tmpBuf, NULL); 602 execlp(browser, browser, "-remote", tmpBuf, NULL);
596 exit(errno); 603 _exit(errno);
597 } 604 }
605
606 wait(&status);
607 }
608 #endif
598 return 0; 609 return 0;
599 } else if (!strncasecmp(buf, "/to ", 4)) { 610 } else if (!strncasecmp(buf, "/to ", 4)) {
600 /* Set private messaging target */ 611 /* Set private messaging target */
601 th_free(setTarget); 612 th_free(setTarget);
602 setTarget = th_strdup(trimLeft(buf + 4)); 613 setTarget = th_strdup(trimLeft(buf + 4));