commit c4e2e0d08cd12c6197fc87034fe559fc4d6b3ef5 from: Thomas Adam date: Sat Jul 16 12:31:04 2022 UTC portable: add setproctitle This is needed for gotwebd. commit - ba107e8082f60fe7570c72c8c6caf9183d944caf commit + c4e2e0d08cd12c6197fc87034fe559fc4d6b3ef5 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 #include #include +#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 - -#include "got_compat.h" /* * Hybrid exponential search/linear search merge sort with hybrid @@ -53,6 +51,8 @@ #include #include #include + +#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 + * + * 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 + +#include +#include + +#include "got_compat.h" + +#if defined(HAVE_PRCTL) && defined(HAVE_PR_SET_NAME) + +#include + +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 - 03501ce38887afd397bcab1b6f5328de34a01db0 blob + 2c9426d06a1fc29e13aa4557bd43b089517fbfb0 --- configure.ac +++ configure.ac @@ -109,6 +109,7 @@ AC_CHECK_FUNCS([ \ rmdir \ setlocale \ socket \ + setproctitle \ strcasecmp \ strchr \ strcspn \ @@ -125,6 +126,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 - ccf0d44325b821f153ca83ea5c36276c6957fbae blob + b8914eb75bc7cd4463424b4ee909c88e2edc2262 --- 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__ @@ -267,6 +271,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 *);