Author: philip
Date: Mon Mar 20 01:27:41 2023
New Revision: 1908547

URL: http://svn.apache.org/viewvc?rev=1908547&view=rev
Log:
Add SIGTERM/SIGINT handling to svnserve, this allows it to exit more
gracefully which allows tools like valgrind to monitor whether the
program exits cleanly and do things like leak detection.

* subversion/svnserve/svnserve.c
  (sigtermint_handler): New handler.
  (accept_connection): Check for signal.
  (sub_main): Install handler, check for signal, add return.

Modified:
    subversion/trunk/subversion/svnserve/svnserve.c

Modified: subversion/trunk/subversion/svnserve/svnserve.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnserve/svnserve.c?rev=1908547&r1=1908546&r2=1908547&view=diff
==============================================================================
--- subversion/trunk/subversion/svnserve/svnserve.c (original)
+++ subversion/trunk/subversion/svnserve/svnserve.c Mon Mar 20 01:27:41 2023
@@ -492,6 +492,15 @@ static void sigchld_handler(int signo)
 }
 #endif
 
+#ifdef APR_HAVE_SIGACTION
+static svn_atomic_t sigtermint_seen = 0;
+static void
+sigtermint_handler(int signo)
+{
+    svn_atomic_set(&sigtermint_seen, 1);
+}
+#endif /* APR_HAVE_SIGACTION */
+
 /* Redirect stdout to stderr.  ARG is the pool.
  *
  * In tunnel or inetd mode, we don't want hook scripts corrupting the
@@ -547,6 +556,10 @@ accept_connection(connection_t **connect
 
       status = apr_socket_accept(&(*connection)->usock, sock,
                                  connection_pool);
+#if APR_HAVE_SIGACTION
+      if (sigtermint_seen)
+          break;
+#endif
       if (handling_mode == connection_mode_fork)
         {
           apr_proc_t proc;
@@ -1330,11 +1343,20 @@ sub_main(int *exit_code, int argc, const
     }
 #endif
 
+#if APR_HAVE_SIGACTION
+  apr_signal(SIGTERM, sigtermint_handler);
+  apr_signal(SIGINT, sigtermint_handler);
+#endif
+
   while (1)
     {
       connection_t *connection = NULL;
       SVN_ERR(accept_connection(&connection, sock, &params, handling_mode,
                                 pool));
+#if APR_HAVE_SIGACTION
+      if (sigtermint_seen)
+          break;
+#endif
       if (run_mode == run_mode_listen_once)
         {
           err = serve_socket(connection, connection->pool);
@@ -1391,7 +1413,7 @@ sub_main(int *exit_code, int argc, const
       close_connection(connection);
     }
 
-  /* NOTREACHED */
+  return SVN_NO_ERROR;
 }
 
 int


Reply via email to