gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18338 - in gnunet: . src/util


From: gnunet
Subject: [GNUnet-SVN] r18338 - in gnunet: . src/util
Date: Sat, 26 Nov 2011 15:52:20 +0100

Author: grothoff
Date: 2011-11-26 15:52:20 +0100 (Sat, 26 Nov 2011)
New Revision: 18338

Modified:
   gnunet/configure.ac
   gnunet/src/util/os_priority.c
   gnunet/src/util/scheduler.c
Log:
Implementing Thomas Bushnell's suggestion to work around the signal race 
without needing special vfork semantics

Modified: gnunet/configure.ac
===================================================================
--- gnunet/configure.ac 2011-11-26 13:55:29 UTC (rev 18337)
+++ gnunet/configure.ac 2011-11-26 14:52:20 UTC (rev 18338)
@@ -613,7 +613,6 @@
 # Checks for library functions.
 AC_FUNC_CLOSEDIR_VOID
 AC_FUNC_FORK
-AC_FUNC_VFORK
 AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MEMCMP
 AC_FUNC_SELECT_ARGTYPES

Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c       2011-11-26 13:55:29 UTC (rev 18337)
+++ gnunet/src/util/os_priority.c       2011-11-26 14:52:20 UTC (rev 18338)
@@ -595,11 +595,7 @@
                                        &fd_stdin_write, sizeof (int));
   }
 
-#if HAVE_WORKING_VFORK
-  ret = vfork ();
-#else
   ret = fork ();
-#endif
   if (ret != 0)
   {
     if (ret == -1)
@@ -611,22 +607,6 @@
     }
     else
     {
-
-#if HAVE_WORKING_VFORK
-      /* let's hope vfork actually works; for some extreme cases (including
-       * a testcase) we need 'execvp' to have run before we return, since
-       * we may send a signal to the process next and we don't want it
-       * to be caught by OUR signal handler (but either by the default
-       * handler or the actual handler as installed by the process itself). */
-#else
-      /* let's give the child process a chance to run execvp, 1s should
-       * be plenty in practice */
-      if (pipe_stdout != NULL)
-        GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
-      if (pipe_stdin != NULL)
-        GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ);
-      sleep (1);
-#endif
       gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
       gnunet_proc->pid = ret;
 #if ENABLE_WINDOWS_WORKAROUNDS
@@ -906,11 +886,7 @@
       GNUNET_array_append (lscp, ls, k);
     GNUNET_array_append (lscp, ls, -1);
   }
-#if HAVE_WORKING_VFORK
-  ret = vfork ();
-#else
   ret = fork ();
-#endif
   if (ret != 0)
   {
     if (ret == -1)
@@ -922,17 +898,6 @@
     }
     else
     {
-#if HAVE_WORKING_VFORK
-      /* let's hope vfork actually works; for some extreme cases (including
-       * a testcase) we need 'execvp' to have run before we return, since
-       * we may send a signal to the process next and we don't want it
-       * to be caught by OUR signal handler (but either by the default
-       * handler or the actual handler as installed by the process itself). */
-#else
-      /* let's give the child process a chance to run execvp, 1s should
-       * be plenty in practice */
-      sleep (1);
-#endif
       gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
       gnunet_proc->pid = ret;
 #if ENABLE_WINDOWS_WORKAROUNDS

Modified: gnunet/src/util/scheduler.c
===================================================================
--- gnunet/src/util/scheduler.c 2011-11-26 13:55:29 UTC (rev 18337)
+++ gnunet/src/util/scheduler.c 2011-11-26 14:52:20 UTC (rev 18338)
@@ -702,6 +702,12 @@
 static struct GNUNET_DISK_PipeHandle *shutdown_pipe_handle;
 
 /**
+ * Process ID of this process at the time we installed the various
+ * signal handlers.
+ */
+static pid_t my_pid;
+
+/**
  * Signal handler called for SIGPIPE.
  */
 #ifndef MINGW
@@ -720,6 +726,9 @@
   static char c;
   int old_errno = errno;        /* backup errno */
 
+  if (getpid() != my_pid)
+    exit(1); /* we have fork'ed since the signal handler was created,
+               ignore the signal, see https://gnunet.org/vfork discussion */
   GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
                           (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
                           &c, sizeof (c));
@@ -799,6 +808,7 @@
   pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
                                 GNUNET_DISK_PIPE_END_READ);
   GNUNET_assert (pr != NULL);
+  my_pid = getpid ();
   shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
   shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
 #ifndef MINGW




reply via email to

[Prev in Thread] Current Thread [Next in Thread]