[master] 54bb1bb Append -i argument to setproctitle() if given.

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 6 12:07:05 CEST 2017


commit 54bb1bbd3ecaa790199f0a78af33886e063ba535
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 6 10:04:42 2017 +0000

    Append -i argument to setproctitle() if given.
    
    Return "varnishd" for server.identity if no -i argument is given.
    
    Wrap setproctitle() in mgt_util.c

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 5c7a7b1..ec85e64 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -679,7 +679,7 @@ VRT_r_server_identity(VRT_CTX)
 	if (heritage.identity != NULL)
 		return (heritage.identity);
 	else
-		return (heritage.name);
+		return ("varnishd");
 }
 
 const char*
diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h
index 055b240..3955690 100644
--- a/bin/varnishd/common/heritage.h
+++ b/bin/varnishd/common/heritage.h
@@ -75,7 +75,6 @@ struct heritage {
 
 	struct params			*param;
 
-	char				*name;
 	const char			*identity;
 
 	char				*panic_str;
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 5d81642..8cb2490 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -174,6 +174,7 @@ void mgt_SHM_Size_Adjust(void);
 void MCF_TcpParams(void);
 
 /* mgt_util.c */
+void mgt_ProcTitle(const char *comp);
 void mgt_DumpRstVsl(void);
 struct vsb *mgt_BuildVident(void);
 void MGT_Complain(const char *, const char *, ...) __v_printflike(2, 3);
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index ed398b7..183cc5b 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -347,10 +347,7 @@ mgt_launch_child(struct cli *cli)
 			if (close(i) == 0)
 				VFIL_null_fd(i);
 		}
-#ifdef HAVE_SETPROCTITLE
-		setproctitle("Varnish-Chld %s", heritage.name);
-#endif
-
+		mgt_ProcTitle("Child");
 		if (mgt_param.sigsegv_handler) {
 			memset(&sa, 0, sizeof sa);
 			sa.sa_sigaction = child_sigsegv_handler;
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index a9ab422..3918608 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -743,17 +743,16 @@ main(int argc, char * const *argv)
 		VJ_master(JAIL_MASTER_LOW);
 	}
 
-	if (VIN_n_Arg(n_arg, &heritage.name, &dirname) != 0)
+	if (VIN_n_Arg(n_arg, &p, &dirname) != 0)
 		ARGV_ERR("Invalid instance (-n) name: %s\n", strerror(errno));
-
-#ifdef HAVE_SETPROCTITLE
-	setproctitle("Varnish-Mgr %s", heritage.name);
-#endif
+	free(p);
 
 	if (i_arg == NULL || *i_arg == '\0')
 		i_arg = "varnishd";
 	heritage.identity = i_arg;
 
+	mgt_ProcTitle("Mgr");
+
 	openlog("varnishd", LOG_PID, LOG_LOCAL0);
 
 	if (VJ_make_workdir(dirname))
diff --git a/bin/varnishd/mgt/mgt_util.c b/bin/varnishd/mgt/mgt_util.c
index 9e63ef7..5730ae5 100644
--- a/bin/varnishd/mgt/mgt_util.c
+++ b/bin/varnishd/mgt/mgt_util.c
@@ -37,9 +37,26 @@
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include "mgt/mgt.h"
 
+#include "common/heritage.h"
+
+/*--------------------------------------------------------------------*/
+
+void
+mgt_ProcTitle(const char *comp)
+{
+#ifdef HAVE_SETPROCTITLE
+	if (strcmp(heritage.identity, "varnishd"))
+		setproctitle("Varnish-%s -i %s", comp, heritage.identity);
+	else
+		setproctitle("Varnish-%s", comp);
+#else
+	(void)comp;
+#endif
+}
 
 /*--------------------------------------------------------------------*/
 



More information about the varnish-commit mailing list