Commit Diff


commit - 3413106e67a4052b3d1bab7325bd0d5931b878d0
commit + 685f459352825cbafb23977135e4efe2f7008f6a
blob - f5c6a4fbf0fd5f48e6ee5345eb6afd37dda98051
blob + 7eca1aa5a8bd66893fc8580eae14d10b079d9c38
--- compat/Makefile.am
+++ compat/Makefile.am
@@ -50,6 +50,10 @@ if !HAVE_SIPHASH
 libopenbsd_compat_a_SOURCES += siphash.c siphash.h
 endif
 
+if !HAVE_SETPROCTITLE
+libopenbsd_compat_a_SOURCES += setproctitle.c
+endif
+
 EXTRA_DIST = \
 	$(top_srcdir)/include/got_compat.h \
 	imsg.h \
blob - 8fb5fec63f8b4d8c0162285ace7b93a93e74c436
blob + bc33cb31875dc69cb26099420531a03373eb1606
--- compat/getopt.c
+++ compat/getopt.c
@@ -29,12 +29,12 @@
 
 /* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
 
-#include "got_compat.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "got_compat.h"
+
 int	BSDopterr = 1,		/* if error message should be printed */
 	BSDoptind = 1,		/* index into parent argv vector */
 	BSDoptopt,		/* character checked for validity */
blob - 4834ccc2e643d986015bbd581d0a192499b372d9
blob + 870febb293f8fe1ec398e726dafe72acea91896c
--- compat/merge.c
+++ compat/merge.c
@@ -31,8 +31,6 @@
  */
 
 #include <sys/cdefs.h>
-
-#include "got_compat.h"
 
 /*
  * Hybrid exponential search/linear search merge sort with hybrid
@@ -53,6 +51,8 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include "got_compat.h"
 
 static void setup(unsigned char *, unsigned char *, size_t, size_t,
     int (*)(const void *, const void *));
blob - /dev/null
blob + c89aafc0375f6b23cb5efb0351a3cce83c3bdb38 (mode 644)
--- /dev/null
+++ compat/setproctitle.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Nicholas Marriott <nicholas.marriott@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stdarg.h>
+#include <string.h>
+
+#include "got_compat.h"
+
+#if defined(HAVE_PRCTL) && defined(HAVE_PR_SET_NAME)
+
+#include <sys/prctl.h>
+
+void
+setproctitle(const char *fmt, ...)
+{
+	char	title[16], name[16], *cp;
+	va_list	ap;
+	int	used;
+
+	va_start(ap, fmt);
+	vsnprintf(title, sizeof title, fmt, ap);
+	va_end(ap);
+
+	used = snprintf(name, sizeof name, "%s: %s", getprogname(), title);
+	if (used >= (int)sizeof name) {
+		cp = strrchr(name, ' ');
+		if (cp != NULL)
+			*cp = '\0';
+	}
+	prctl(PR_SET_NAME, name);
+}
+#else
+void
+setproctitle(__unused const char *fmt, ...)
+{
+}
+#endif
blob - 01a84b1cba6ca21ae4177de01aa706cc1a23c9cb
blob + c48ef7590986f0db9e80cb67f84b3a839882a18e
--- configure.ac
+++ configure.ac
@@ -108,6 +108,7 @@ AC_CHECK_FUNCS([ \
 	rmdir \
 	setlocale \
 	socket \
+	setproctitle \
 	strcasecmp \
 	strchr \
 	strcspn \
@@ -124,6 +125,8 @@ AC_CHECK_FUNCS([ \
 	wcwidth \
 ])
 
+AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
+
 # Siphash support.
 AC_CHECK_FUNCS([SipHash])
 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
blob - 96ff1be88d3005c387120e87b322b96994611bcc
blob + 8b139fc89dfdbbe5966fbb569b781ef870a47061
--- include/got_compat.h
+++ include/got_compat.h
@@ -68,6 +68,10 @@
 
 #ifndef __dead
 #define __dead __attribute__ ((__noreturn__))
+#endif
+
+#ifndef __unused
+#define __unused __attribute__ ((__unused__))
 #endif
 
 #ifndef __OpenBSD__
@@ -264,6 +268,11 @@ void		*reallocarray(void *, size_t, size_t);
 void		*recallocarray(void *, size_t, size_t, size_t);
 #endif
 
+#ifndef HAVE_SETPROCTITLE
+/* setproctitle.c */
+void 		 setproctitle(const char *, ...);
+#endif
+
 #ifndef HAVE_FMT_SCALED
 /* fmt_scaled.c */
 int fmt_scaled(long long, char *);