Re: On SIGWINCH usage, switch to SIGUSR2 nowadays?

2019-02-21 Thread Yann Ylavic
On Thu, Feb 21, 2019 at 5:31 PM Yann Ylavic  wrote:
>
> May I commit this (before unblocking graceful stop in ONE_PROCESS mode)?

OK, it requires an APR change anyway because SIGUSR2 is blocked by
apr_signal_thread().
I opened a thread there, wait and see, in any case it now depends on a
minimal APR version so things get complicated..

>
> Thanks,
> Yann.


Re: On SIGWINCH usage, switch to SIGUSR2 nowadays?

2019-02-21 Thread Yann Ylavic
After some bit of research, I couldn't find a platform (besides Linux
< 2.6) where SIGUSR2 is "reserved", so possibly something like the
attached patch would be acceptable.

The patch adds --enable-graceful-stop-sigusr2 to configure(.in) which
default to "yes" (for trunk, but would default to "no" for a potential
backport to 2.4.x), and which anyway is forced to "no" for platforms
we know it won't work (linux < 2.6 for now, please add yours...).

May I commit this (before unblocking graceful stop in ONE_PROCESS mode)?

Thanks,
Yann.
Index: configure.in
===
--- configure.in	(revision 1853992)
+++ configure.in	(working copy)
@@ -915,6 +915,21 @@ AC_ARG_ENABLE(bsd-makefiles,APACHE_HELP_STRING(--e
   FORCE_BSD_MAKEFILE="auto"
 ])
 
+# For httpd 2.5 and later, SIGUSR2 is used by default if it works (opt-out per platform below)
+AC_ARG_ENABLE(graceful-stop-sigusr2,APACHE_HELP_STRING(--enable-graceful-stop-sigusr2,Use SIGUSR2 as the signal to gracefully stop httpd (default is yes, no implies legacy SIGWINCH)))
+case $host in
+*-linux-[[01]].* | *-linux-2.[[012345]]* )
+if test "$enable_graceful_stop_sigusr2" = "yes"; then
+AC_ERROR([--enable-graceful-stop-sigusr2 will not work for Linux prior to 2.6])
+fi
+enable_graceful_stop_sigusr2=no
+;;
+esac
+# For httpd 2.4 and earlier, this test should be =yes (opt-in)
+if test "$enable_graceful_stop_sigusr2" != "no"; then
+APR_ADDTO(CPPFLAGS, -DAP_USE_GRACEFUL_STOP_SIGUSR2)
+fi
+
 AC_ARG_WITH([test-suite],
 APACHE_HELP_STRING([--with-test-suite=PATH], [enable in-tree 'make check' with the given Apache::Test suite location]),
 [
Index: include/mpm_common.h
===
--- include/mpm_common.h	(revision 1853992)
+++ include/mpm_common.h	(working copy)
@@ -72,7 +72,21 @@ extern "C" {
 /* Signal used to gracefully restart (as a quoted string) */
 #define AP_SIG_GRACEFUL_STRING "SIGUSR1"
 
+/* If configured, use SIGUSR2 for graceful stop */
+#ifdef AP_USE_GRACEFUL_STOP_SIGUSR2
+
 /* Signal used to gracefully stop */
+#define AP_SIG_GRACEFUL_STOP SIGUSR2
+
+/* Signal used to gracefully stop (without SIG prefix) */
+#define AP_SIG_GRACEFUL_STOP_SHORT USR2
+
+/* Signal used to gracefully stop (as a quoted string) */
+#define AP_SIG_GRACEFUL_STOP_STRING "SIGUSR2"
+
+#else /* Fallback to SIGWINCH (legacy) */
+
+/* Signal used to gracefully stop */
 #define AP_SIG_GRACEFUL_STOP SIGWINCH
 
 /* Signal used to gracefully stop (without SIG prefix) */
@@ -80,6 +94,7 @@ extern "C" {
 
 /* Signal used to gracefully stop (as a quoted string) */
 #define AP_SIG_GRACEFUL_STOP_STRING "SIGWINCH"
+#endif
 
 /**
  * Callback function used for ap_reclaim_child_processes() and


On SIGWINCH usage, switch to SIGUSR2 nowadays?

2019-02-21 Thread Yann Ylavic
Hi,

as you probably know, SIGWINCH is used both by terminal (emulators)
for window changes/redraw, and httpd for graceful stop (hardcoded
AFAICT).

This can cause issues when httpd is run in foreground from a terminal,
and as such (I think) is ignored in -X/ONE_PROCESS mode otherwise
gdb-ing would become quite irritating.

I'd like to be able to debug/instrument graceful stop with -X /
ONE_PROCESS though, without fearing to resize my gdb terminal or
something like that.

I suppose SIGUSR2 was not used some times ago because of its internal
usage in LinuxThreads (replaced by NPTL more than 10 years ago now),
or is/was there other systems/libcs which use SIGUSR2 for their own
purpose?

So, unless somewhere SIGUSR2 is still not a USeR available signal
nowadays, I propose that we switch to SIGUSR2, WDYT?
(There may be some tooling that uses SIGWINCH directly instead of "-k
graceful-stop", should be care?)

Could be something like the attached patch to "./configure -D
AP_SIG_GRACEFUL_STOP_SHORT=USR2 ...", or an hardcoded switch like
today...

Regards,
Yann.
Index: include/mpm_common.h
===
--- include/mpm_common.h	(revision 1853992)
+++ include/mpm_common.h	(working copy)
@@ -72,6 +72,7 @@ extern "C" {
 /* Signal used to gracefully restart (as a quoted string) */
 #define AP_SIG_GRACEFUL_STRING "SIGUSR1"
 
+#ifndef AP_SIG_GRACEFUL_STOP_SHORT
 /* Signal used to gracefully stop */
 #define AP_SIG_GRACEFUL_STOP SIGWINCH
 
@@ -80,6 +81,14 @@ extern "C" {
 
 /* Signal used to gracefully stop (as a quoted string) */
 #define AP_SIG_GRACEFUL_STOP_STRING "SIGWINCH"
+#else
+#define AP__SIG_TOKENIFY_(x, y) x ## y
+#define AP__SIG_TOKENIFY(y) AP__SIG_TOKENIFY_(SIG, y)
+#define AP_SIG_GRACEFUL_STOP \
+AP__SIG_TOKENIFY(AP_SIG_GRACEFUL_STOP_SHORT)
+#define AP_SIG_GRACEFUL_STOP_STRING \
+"SIG" APR_STRINGIFY(AP_SIG_GRACEFUL_STOP_SHORT)
+#endif
 
 /**
  * Callback function used for ap_reclaim_child_processes() and