comparison nnchat.c @ 233:6b1c67274f6c

Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Mar 2011 11:21:41 +0200
parents 3140ea43d4a3
children 71fa0364c058 b7e7ed741a18
comparison
equal deleted inserted replaced
232:3140ea43d4a3 233:6b1c67274f6c
716 printMsg("Could not launch default web browser: %d\n", status); 716 printMsg("Could not launch default web browser: %d\n", status);
717 } 717 }
718 #else 718 #else
719 { 719 {
720 int status; 720 int status;
721 int fds[2];
721 pid_t pid; 722 pid_t pid;
722 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr); 723 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr);
723 th_free(tmpStr); 724 th_free(tmpStr);
724 725
726 if (pipe(fds) == -1) {
727 int ret = errno;
728 printMsg("Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret));
729 return 0;
730 }
731
725 if ((pid = fork()) < 0) { 732 if ((pid = fork()) < 0) {
726 printMsg("Could not create sub-process!\n"); 733 printMsg("Could not create sub-process!\n");
727 } else if (pid == 0) { 734 } else if (pid == 0) {
735 dup2(fds[1], STDOUT_FILENO);
736 dup2(fds[0], STDERR_FILENO);
728 execlp(setBrowser, setBrowser, "-remote", tmpBuf, (void *)NULL); 737 execlp(setBrowser, setBrowser, "-remote", tmpBuf, (void *)NULL);
729 _exit(errno); 738 _exit(errno);
730 } 739 }
731 740
732 wait(&status); 741 wait(&status);