[master] feac030 Don't use SIGHUP, it fails if varnishtest is run under nohup(1)

Poul-Henning Kamp phk at FreeBSD.org
Thu Nov 17 23:17:05 CET 2016


commit feac030170411d2fb33c4c4a33c4c6cbf52099b9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Nov 17 22:07:36 2016 +0000

    Don't use SIGHUP, it fails if varnishtest is run under nohup(1)
    
    We recognize only the most famous signals by name SIGTERM, SIGINT
    and SIGKILL, if you want a special signal you will have to use "-15"
    or whatever.
    
    The primary reason for this is that there is still no portable API
    for translating "SIGXXX" to an integer.
    
    It used to be that bin/kill.c contained an array:
    
    	const char *const sys_signame[NSIG] = {
    		[0] =           "Signal 0",
    		[SIGHUP] =      "HUP",
    		[SIGINT] =      "INT",
    		[SIGQUIT] =     "QUIT",
    		[SIGILL] =      "ILL",
    		[...]
    
    BSD unix sensibly moved this into libc, to avoid duplicating
    this all over the place, but Linux has not done that.
    
    The right way to do this, would have been to have <signal.h>
    contain a table:
    
    	#ifdef SIGNAL_DOC(n,s,l)
    	SIGNAL_DOC(1, "HUP", "Hangup")
    	SIGNAL_DOC(2, "INT", "Interrupt")
    	...
    	#endif
    
    That way nobody would ever need another #ifdef SIGFOO.
    
    Anyway...
    
    Rather than pointlessly add a semi-complete list of signals no
    sensible person should ever use in a varnishtest (SIGWINCH anybody
    ?) we support the famous three by name, and the rest by number.

diff --git a/bin/varnishtest/tests/u00000.vtc b/bin/varnishtest/tests/u00000.vtc
index abe5f0e..1f3bb59 100644
--- a/bin/varnishtest/tests/u00000.vtc
+++ b/bin/varnishtest/tests/u00000.vtc
@@ -16,7 +16,7 @@ delay 0.5
 # stop
 process p1 -stop
 process p2 -close
-process p3 -kill "HUP"
+process p3 -kill "INT"
 
 # wait
 process p1 -wait
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index dd553c9..f2fb1c8 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -247,7 +247,7 @@ process_run(struct process *p)
 static void
 process_kill(const struct process *p, const char *sig)
 {
-	int j;
+	int j = 0;
 
 	CHECK_OBJ_NOTNULL(p, PROCESS_MAGIC);
 	AN(sig);
@@ -257,12 +257,14 @@ process_kill(const struct process *p, const char *sig)
 
 	if (!strcmp(sig, "TERM"))
 		j = SIGTERM;
-	else if (!strcmp(sig, "HUP"))
-		j = SIGHUP;
+	else if (!strcmp(sig, "INT"))
+		j = SIGINT;
 	else if (!strcmp(sig, "KILL"))
 		j = SIGKILL;
+	else if (*sig == '-')
+		j = strtoul(sig + 1, NULL, 10);
 	else
-		j = strtoul(sig, NULL, 10);
+		vtc_log(p->vl, 0, "Could not grok signal (%s)", sig);
 
 	if (kill(p->pid, j) < 0)
 		vtc_log(p->vl, 0, "Failed to send signal %d (%s)", j, strerror(errno));



More information about the varnish-commit mailing list