summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArvind Samptur <arvind.samputur@wipro.com>2002-11-12 08:51:15 +0000
committerArvind Samptur <arvind@src.gnome.org>2002-11-12 08:51:15 +0000
commitf136d5befbe7be952bbaec604cafeff4c46c9a6f (patch)
treeb802a02a73965805b181d39ee4d56a1cbe3b8384
parentd87e2cdcf02e58f113f20c7718d82b18d68a6707 (diff)
poll for the pid to wrriten on to the pipe before allowing the number ofGNOME_PANEL_2_1_3
2002-11-12 Arvind Samptur <arvind.samputur@wipro.com> * remote-helper.c: (fork_new_handler) poll for the pid to wrriten on to the pipe before allowing the number of mails to be written on to the pipe. Fixes the problem of a SIGPIPE occuring causing the panel to crash and sometimes the number of mails having a junk value(which would be pid). Fixes #98001
-rw-r--r--mailcheck/ChangeLog9
-rw-r--r--mailcheck/remote-helper.c25
2 files changed, 32 insertions, 2 deletions
diff --git a/mailcheck/ChangeLog b/mailcheck/ChangeLog
index 1e62fffe8..73b2e1ce8 100644
--- a/mailcheck/ChangeLog
+++ b/mailcheck/ChangeLog
@@ -1,3 +1,12 @@
+2002-11-12 Arvind Samptur <arvind.samputur@wipro.com>
+ * remote-helper.c: (fork_new_handler) poll for the
+ pid to wrriten on to the pipe before allowing the
+ number of mails to be written on to the pipe.
+ Fixes the problem of a SIGPIPE occuring causing the
+ panel to crash and sometimes the number of mails
+ having a junk value(which would be pid).
+ Fixes #98001
+
2002-11-06 Andrew Sobala <andrew@sobala.net>
* clock.schemas.in, mailcheck.schemas.in, tasklist.c,
diff --git a/mailcheck/remote-helper.c b/mailcheck/remote-helper.c
index 8a6a51298..3dccfc116 100644
--- a/mailcheck/remote-helper.c
+++ b/mailcheck/remote-helper.c
@@ -17,11 +17,14 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <poll.h>
#include "popcheck.h"
#include "remote-helper.h"
+#define POLLTIMEOUT 5000 /* 5 milliseconds */
+
typedef struct {
pid_t pid;
int fd;
@@ -116,12 +119,30 @@ fork_new_handler (RemoteHandler handler, gpointer data,
return NULL;
} else if (pid == 0) {
/*child*/
- close (fd[0]);
pid = fork ();
if (pid != 0) {
write (fd[1], &pid, sizeof (pid));
_exit (0);
} else {
+ /* grand child */
+
+ /* Make sure that the pid is written first */
+
+ struct pollfd poll_list[1];
+
+ poll_list[0].fd = fd[0];
+ poll_list[0].events = POLLIN;
+ poll (poll_list, 1, POLLTIMEOUT);
+
+ close (fd [0]);
+
+ if (((poll_list[0].revents&POLLHUP) == POLLHUP) ||
+ ((poll_list[0].revents&POLLERR) == POLLERR) ||
+ ((poll_list[0].revents&POLLERR) == POLLNVAL)) {
+ g_free (handler_data);
+ return NULL;
+ }
+
handler_data->pid = 0;
handler_data->fd = fd[1];
return handler_data;
@@ -132,7 +153,7 @@ fork_new_handler (RemoteHandler handler, gpointer data,
while ((waitpid (pid, 0, 0) == -1) && errno == EINTR);
read (fd[0], &pid, sizeof (pid));
- if (pid < 0) {
+ if (pid <= 0) {
close (fd[0]);
g_free (handler_data);
return NULL;