changeset 4223:467600defbe4 draft

Add support for setproctitle(3).
author Roy Marples <roy@marples.name>
date Tue, 13 Feb 2018 10:22:31 +0000
parents ab6e6fae5e3e
children 595761ecbde0
files configure src/dhcpcd.c
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Sat Feb 10 20:52:31 2018 +0000
+++ b/configure	Tue Feb 13 10:22:31 2018 +0000
@@ -799,6 +799,27 @@
 	fi
 fi
 
+if [ -z "$SETPROCTITLE" ]; then
+	printf "Testing for setproctitle ... "
+	cat << EOF >_setproctitle.c
+#include <stdlib.h>
+int main(void) {
+	setproctitle("foo");
+	return 0;
+}
+EOF
+	if $XCC _setproctitle.c -o _setproctitle 2>&3; then
+		SETPROCTITLE=yes
+	else
+		SETPROCTITLE=no
+	fi
+	echo "$SETPROCTITLE"
+	rm -f _setproctitle.c _setproctitle
+fi
+if [ "$SETPROCTITLE" = yes ]; then
+	echo "#define	HAVE_SETPROCTITLE" >>$CONFIG_H
+fi
+
 if [ -z "$STRTOI" ]; then
 	printf "Testing for strtoi ... "
 	cat <<EOF >_strtoi.c
--- a/src/dhcpcd.c	Sat Feb 10 20:52:31 2018 +0000
+++ b/src/dhcpcd.c	Tue Feb 13 10:22:31 2018 +0000
@@ -1809,6 +1809,13 @@
 	logdebugx(PACKAGE "-" VERSION " starting");
 	ctx.options |= DHCPCD_STARTED;
 
+#ifdef HAVE_SETPROCTITLE
+	setproctitle("%s%s%s",
+	    ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],
+	    ctx.options & DHCPCD_IPV4 ? " [ip4]" : "",
+	    ctx.options & DHCPCD_IPV6 ? " [ip6]" : "");
+#endif
+
 	if (if_opensockets(&ctx) == -1) {
 		logerr("%s: if_opensockets", __func__);
 		goto exit_failure;