Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2022-11-10 03:35:51 +0300
committerBryan Drewery <bryan@shatow.net>2022-11-10 03:38:08 +0300
commit4ce12fb90b4ce55e9fc13ce1f8d057c6f3ee3207 (patch)
tree3d1e494a6891d5f885b13ae634bb59f91ffdc4d4
parenteffd6090e3dec2e73eee513464538bb71c4e884e (diff)
Import public domain setsid from sysutils/setsid
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am4
-rw-r--r--Makefile.in57
-rw-r--r--src/libexec/poudriere/setsid/c.h458
-rw-r--r--src/libexec/poudriere/setsid/setsid.169
-rw-r--r--src/libexec/poudriere/setsid/setsid.c120
6 files changed, 703 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 5fa1e524..1fa154df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@ libtool
/rename
/rexec
/rm
+/setsid
/sh
/timeout
/timestamp
diff --git a/Makefile.am b/Makefile.am
index 0b6fc5bb..5cb877df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -160,6 +160,7 @@ pkglibexec_PROGRAMS= \
rename \
rexec \
@USE_RM@ \
+ setsid \
timeout \
timestamp \
@SH@
@@ -190,6 +191,9 @@ nc_SOURCES= src/libexec/poudriere/nc/nc.c
pwait_SOURCES= src/libexec/poudriere/pwait/pwait.c
rename_SOURCES= src/libexec/poudriere/rename/rename.c
rm_SOURCES= src/libexec/poudriere/rm/rm.c
+setsid_SOURCES= src/libexec/poudriere/setsid/setsid.c \
+ set/libexec/poudriere/setsid/c.h
+setsid_CFLAGS= -DHAVE_ERR_H -DHAVE_NANOSLEEP
timeout_SOURCES= src/libexec/poudriere/timeout/timeout.c
timestamp_SOURCES= src/libexec/poudriere/timestamp/timestamp.c
timestamp_LDADD= -lpthread
diff --git a/Makefile.in b/Makefile.in
index bffaf318..52ca0c82 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -97,8 +97,8 @@ pkglibexec_PROGRAMS = cachec$(EXEEXT) cached$(EXEEXT) clock$(EXEEXT) \
cpdup$(EXEEXT) dirempty$(EXEEXT) dirwatch$(EXEEXT) \
jexecd$(EXEEXT) locked_mkdir$(EXEEXT) nc$(EXEEXT) \
poudriered$(EXEEXT) ptsort$(EXEEXT) pwait$(EXEEXT) \
- rename$(EXEEXT) rexec$(EXEEXT) @USE_RM@ timeout$(EXEEXT) \
- timestamp$(EXEEXT) @SH@
+ rename$(EXEEXT) rexec$(EXEEXT) @USE_RM@ setsid$(EXEEXT) \
+ timeout$(EXEEXT) timestamp$(EXEEXT) @SH@
EXTRA_PROGRAMS = rm$(EXEEXT) sh$(EXEEXT)
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -234,6 +234,13 @@ rexec_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
am_rm_OBJECTS = src/libexec/poudriere/rm/rm.$(OBJEXT)
rm_OBJECTS = $(am_rm_OBJECTS)
rm_LDADD = $(LDADD)
+am_setsid_OBJECTS = \
+ src/libexec/poudriere/setsid/setsid-setsid.$(OBJEXT)
+setsid_OBJECTS = $(am_setsid_OBJECTS)
+setsid_LDADD = $(LDADD)
+setsid_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(setsid_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
am_sh_OBJECTS = external/sh/sh-alias.$(OBJEXT) \
external/sh/sh-arith_yacc.$(OBJEXT) \
external/sh/sh-arith_yylex.$(OBJEXT) \
@@ -402,6 +409,7 @@ am__depfiles_remade = external/libnv/$(DEPDIR)/libnv_la-msgio.Plo \
src/libexec/poudriere/rexec/$(DEPDIR)/rexec-rexec.Po \
src/libexec/poudriere/rm/$(DEPDIR)/rm.Po \
src/libexec/poudriere/rm/$(DEPDIR)/sh-rm.Po \
+ src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po \
src/libexec/poudriere/timeout/$(DEPDIR)/timeout.Po \
src/libexec/poudriere/timestamp/$(DEPDIR)/timestamp.Po \
src/poudriere-sh/$(DEPDIR)/sh-builtins.Po \
@@ -444,16 +452,16 @@ SOURCES = $(libnv_la_SOURCES) $(libptsort_la_SOURCES) \
$(dirwatch_SOURCES) $(jexecd_SOURCES) $(locked_mkdir_SOURCES) \
$(nc_SOURCES) $(poudriered_SOURCES) $(ptsort_SOURCES) \
$(pwait_SOURCES) $(rename_SOURCES) $(rexec_SOURCES) \
- $(rm_SOURCES) $(sh_SOURCES) $(timeout_SOURCES) \
- $(timestamp_SOURCES)
+ $(rm_SOURCES) $(setsid_SOURCES) $(sh_SOURCES) \
+ $(timeout_SOURCES) $(timestamp_SOURCES)
DIST_SOURCES = $(libnv_la_SOURCES) $(libptsort_la_SOURCES) \
$(libucl_la_SOURCES) $(cachec_SOURCES) $(cached_SOURCES) \
$(clock_SOURCES) $(cpdup_SOURCES) $(dirempty_SOURCES) \
$(dirwatch_SOURCES) $(jexecd_SOURCES) $(locked_mkdir_SOURCES) \
$(nc_SOURCES) $(poudriered_SOURCES) $(ptsort_SOURCES) \
$(pwait_SOURCES) $(rename_SOURCES) $(rexec_SOURCES) \
- $(rm_SOURCES) $(sh_SOURCES) $(timeout_SOURCES) \
- $(timestamp_SOURCES)
+ $(rm_SOURCES) $(setsid_SOURCES) $(sh_SOURCES) \
+ $(timeout_SOURCES) $(timestamp_SOURCES)
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
ctags-recursive dvi-recursive html-recursive info-recursive \
install-data-recursive install-dvi-recursive \
@@ -847,6 +855,10 @@ nc_SOURCES = src/libexec/poudriere/nc/nc.c
pwait_SOURCES = src/libexec/poudriere/pwait/pwait.c
rename_SOURCES = src/libexec/poudriere/rename/rename.c
rm_SOURCES = src/libexec/poudriere/rm/rm.c
+setsid_SOURCES = src/libexec/poudriere/setsid/setsid.c \
+ set/libexec/poudriere/setsid/c.h
+
+setsid_CFLAGS = -DHAVE_ERR_H -DHAVE_NANOSLEEP
timeout_SOURCES = src/libexec/poudriere/timeout/timeout.c
timestamp_SOURCES = src/libexec/poudriere/timestamp/timestamp.c
timestamp_LDADD = -lpthread
@@ -1372,6 +1384,19 @@ src/libexec/poudriere/rm/rm.$(OBJEXT): \
rm$(EXEEXT): $(rm_OBJECTS) $(rm_DEPENDENCIES) $(EXTRA_rm_DEPENDENCIES)
@rm -f rm$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(rm_OBJECTS) $(rm_LDADD) $(LIBS)
+src/libexec/poudriere/setsid/$(am__dirstamp):
+ @$(MKDIR_P) src/libexec/poudriere/setsid
+ @: > src/libexec/poudriere/setsid/$(am__dirstamp)
+src/libexec/poudriere/setsid/$(DEPDIR)/$(am__dirstamp):
+ @$(MKDIR_P) src/libexec/poudriere/setsid/$(DEPDIR)
+ @: > src/libexec/poudriere/setsid/$(DEPDIR)/$(am__dirstamp)
+src/libexec/poudriere/setsid/setsid-setsid.$(OBJEXT): \
+ src/libexec/poudriere/setsid/$(am__dirstamp) \
+ src/libexec/poudriere/setsid/$(DEPDIR)/$(am__dirstamp)
+
+setsid$(EXEEXT): $(setsid_OBJECTS) $(setsid_DEPENDENCIES) $(EXTRA_setsid_DEPENDENCIES)
+ @rm -f setsid$(EXEEXT)
+ $(AM_V_CCLD)$(setsid_LINK) $(setsid_OBJECTS) $(setsid_LDADD) $(LIBS)
external/sh/$(am__dirstamp):
@$(MKDIR_P) external/sh
@: > external/sh/$(am__dirstamp)
@@ -1643,6 +1668,7 @@ mostlyclean-compile:
-rm -f src/libexec/poudriere/rename/*.$(OBJEXT)
-rm -f src/libexec/poudriere/rexec/*.$(OBJEXT)
-rm -f src/libexec/poudriere/rm/*.$(OBJEXT)
+ -rm -f src/libexec/poudriere/setsid/*.$(OBJEXT)
-rm -f src/libexec/poudriere/timeout/*.$(OBJEXT)
-rm -f src/libexec/poudriere/timestamp/*.$(OBJEXT)
-rm -f src/poudriere-sh/*.$(OBJEXT)
@@ -1719,6 +1745,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/rexec/$(DEPDIR)/rexec-rexec.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/rm/$(DEPDIR)/rm.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/rm/$(DEPDIR)/sh-rm.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/timeout/$(DEPDIR)/timeout.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/timestamp/$(DEPDIR)/timestamp.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-builtins.Po@am__quote@ # am--include-marker
@@ -1998,6 +2025,20 @@ src/libexec/poudriere/rexec/rexec-rexec.obj: src/libexec/poudriere/rexec/rexec.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rexec_CFLAGS) $(CFLAGS) -c -o src/libexec/poudriere/rexec/rexec-rexec.obj `if test -f 'src/libexec/poudriere/rexec/rexec.c'; then $(CYGPATH_W) 'src/libexec/poudriere/rexec/rexec.c'; else $(CYGPATH_W) '$(srcdir)/src/libexec/poudriere/rexec/rexec.c'; fi`
+src/libexec/poudriere/setsid/setsid-setsid.o: src/libexec/poudriere/setsid/setsid.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(setsid_CFLAGS) $(CFLAGS) -MT src/libexec/poudriere/setsid/setsid-setsid.o -MD -MP -MF src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Tpo -c -o src/libexec/poudriere/setsid/setsid-setsid.o `test -f 'src/libexec/poudriere/setsid/setsid.c' || echo '$(srcdir)/'`src/libexec/poudriere/setsid/setsid.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Tpo src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/libexec/poudriere/setsid/setsid.c' object='src/libexec/poudriere/setsid/setsid-setsid.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(setsid_CFLAGS) $(CFLAGS) -c -o src/libexec/poudriere/setsid/setsid-setsid.o `test -f 'src/libexec/poudriere/setsid/setsid.c' || echo '$(srcdir)/'`src/libexec/poudriere/setsid/setsid.c
+
+src/libexec/poudriere/setsid/setsid-setsid.obj: src/libexec/poudriere/setsid/setsid.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(setsid_CFLAGS) $(CFLAGS) -MT src/libexec/poudriere/setsid/setsid-setsid.obj -MD -MP -MF src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Tpo -c -o src/libexec/poudriere/setsid/setsid-setsid.obj `if test -f 'src/libexec/poudriere/setsid/setsid.c'; then $(CYGPATH_W) 'src/libexec/poudriere/setsid/setsid.c'; else $(CYGPATH_W) '$(srcdir)/src/libexec/poudriere/setsid/setsid.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Tpo src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/libexec/poudriere/setsid/setsid.c' object='src/libexec/poudriere/setsid/setsid-setsid.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(setsid_CFLAGS) $(CFLAGS) -c -o src/libexec/poudriere/setsid/setsid-setsid.obj `if test -f 'src/libexec/poudriere/setsid/setsid.c'; then $(CYGPATH_W) 'src/libexec/poudriere/setsid/setsid.c'; else $(CYGPATH_W) '$(srcdir)/src/libexec/poudriere/setsid/setsid.c'; fi`
+
external/sh/sh-alias.o: external/sh/alias.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh/sh-alias.o -MD -MP -MF external/sh/$(DEPDIR)/sh-alias.Tpo -c -o external/sh/sh-alias.o `test -f 'external/sh/alias.c' || echo '$(srcdir)/'`external/sh/alias.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh/$(DEPDIR)/sh-alias.Tpo external/sh/$(DEPDIR)/sh-alias.Po
@@ -3442,6 +3483,8 @@ distclean-generic:
-rm -f src/libexec/poudriere/rexec/$(am__dirstamp)
-rm -f src/libexec/poudriere/rm/$(DEPDIR)/$(am__dirstamp)
-rm -f src/libexec/poudriere/rm/$(am__dirstamp)
+ -rm -f src/libexec/poudriere/setsid/$(DEPDIR)/$(am__dirstamp)
+ -rm -f src/libexec/poudriere/setsid/$(am__dirstamp)
-rm -f src/libexec/poudriere/timeout/$(DEPDIR)/$(am__dirstamp)
-rm -f src/libexec/poudriere/timeout/$(am__dirstamp)
-rm -f src/libexec/poudriere/timestamp/$(DEPDIR)/$(am__dirstamp)
@@ -3529,6 +3572,7 @@ distclean: distclean-recursive
-rm -f src/libexec/poudriere/rexec/$(DEPDIR)/rexec-rexec.Po
-rm -f src/libexec/poudriere/rm/$(DEPDIR)/rm.Po
-rm -f src/libexec/poudriere/rm/$(DEPDIR)/sh-rm.Po
+ -rm -f src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po
-rm -f src/libexec/poudriere/timeout/$(DEPDIR)/timeout.Po
-rm -f src/libexec/poudriere/timestamp/$(DEPDIR)/timestamp.Po
-rm -f src/poudriere-sh/$(DEPDIR)/sh-builtins.Po
@@ -3668,6 +3712,7 @@ maintainer-clean: maintainer-clean-recursive
-rm -f src/libexec/poudriere/rexec/$(DEPDIR)/rexec-rexec.Po
-rm -f src/libexec/poudriere/rm/$(DEPDIR)/rm.Po
-rm -f src/libexec/poudriere/rm/$(DEPDIR)/sh-rm.Po
+ -rm -f src/libexec/poudriere/setsid/$(DEPDIR)/setsid-setsid.Po
-rm -f src/libexec/poudriere/timeout/$(DEPDIR)/timeout.Po
-rm -f src/libexec/poudriere/timestamp/$(DEPDIR)/timestamp.Po
-rm -f src/poudriere-sh/$(DEPDIR)/sh-builtins.Po
diff --git a/src/libexec/poudriere/setsid/c.h b/src/libexec/poudriere/setsid/c.h
new file mode 100644
index 00000000..17351e97
--- /dev/null
+++ b/src/libexec/poudriere/setsid/c.h
@@ -0,0 +1,458 @@
+/*
+ * Fundamental C definitions.
+ *
+ * No copyright is claimed. This code is in the public domain; do with
+ * it what you wish.
+ */
+#ifndef UTIL_LINUX_C_H
+#define UTIL_LINUX_C_H
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <assert.h>
+
+#ifdef HAVE_ERR_H
+# include <err.h>
+#endif
+
+#ifdef HAVE_SYS_SYSMACROS_H
+# include <sys/sysmacros.h> /* for major, minor */
+#endif
+
+#ifndef LOGIN_NAME_MAX
+# define LOGIN_NAME_MAX 256
+#endif
+
+#ifndef NAME_MAX
+# define NAME_MAX PATH_MAX
+#endif
+
+/*
+ * __GNUC_PREREQ is deprecated in favour of __has_attribute() and
+ * __has_feature(). The __has macros are supported by clang and gcc>=5.
+ */
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+# define __GNUC_PREREQ(maj, min) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+# define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#ifdef __GNUC__
+
+/* &a[0] degrades to a pointer: a different type from an array */
+# define __must_be_array(a) \
+ UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
+
+# define ignore_result(x) __extension__ ({ \
+ __typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
+})
+
+#else /* !__GNUC__ */
+# define __must_be_array(a) 0
+# define __attribute__(_arg_)
+# define ignore_result(x) ((void) (x))
+#endif /* !__GNUC__ */
+
+
+/* "restrict" keyword fallback */
+#if __STDC__ != 1
+# define restrict __restrict /* use implementation __ format */
+#else
+# ifndef __STDC_VERSION__
+# define restrict __restrict /* use implementation __ format */
+# else
+# if __STDC_VERSION__ < 199901L
+# define restrict __restrict /* use implementation __ format */
+# endif
+# endif
+#endif
+
+
+/*
+ * It evaluates to 1 if the attribute/feature is supported by the current
+ * compilation target. Fallback for old compilers.
+ */
+#ifndef __has_attribute
+ #define __has_attribute(x) 0
+#endif
+
+#ifndef __has_feature
+ #define __has_feature(x) 0
+#endif
+
+/*
+ * Function attributes
+ */
+#ifndef __ul_alloc_size
+# if (__has_attribute(alloc_size) && __has_attribute(warn_unused_result)) || __GNUC_PREREQ (4, 3)
+# define __ul_alloc_size(s) __attribute__((alloc_size(s), warn_unused_result))
+# else
+# define __ul_alloc_size(s)
+# endif
+#endif
+
+#ifndef __ul_calloc_size
+# if (__has_attribute(alloc_size) && __has_attribute(warn_unused_result)) || __GNUC_PREREQ (4, 3)
+# define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s), warn_unused_result))
+# else
+# define __ul_calloc_size(n, s)
+# endif
+#endif
+
+#if __has_attribute(returns_nonnull) || __GNUC_PREREQ (4, 9)
+# define __ul_returns_nonnull __attribute__((returns_nonnull))
+#else
+# define __ul_returns_nonnull
+#endif
+
+/*
+ * Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type size_t), so the expression can be used
+ * e.g. in a structure initializer (or wherever else comma expressions
+ * aren't permitted).
+ */
+#define UL_BUILD_BUG_ON_ZERO(e) __extension__ (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
+
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#endif
+
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+#ifndef min
+# define min(x, y) __extension__ ({ \
+ __typeof__(x) _min1 = (x); \
+ __typeof__(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+#endif
+
+#ifndef max
+# define max(x, y) __extension__ ({ \
+ __typeof__(x) _max1 = (x); \
+ __typeof__(y) _max2 = (y); \
+ (void) (&_max1 == &_max2); \
+ _max1 > _max2 ? _max1 : _max2; })
+#endif
+
+#ifndef cmp_numbers
+# define cmp_numbers(x, y) __extension__ ({ \
+ __typeof__(x) _a = (x); \
+ __typeof__(y) _b = (y); \
+ (void) (&_a == &_b); \
+ _a == _b ? 0 : _a > _b ? 1 : -1; })
+#endif
+
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+/*
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ */
+#ifndef container_of
+#define container_of(ptr, type, member) __extension__ ({ \
+ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+#endif
+
+#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
+# ifdef HAVE___PROGNAME
+extern char *__progname;
+# define program_invocation_short_name __progname
+# else
+# ifdef HAVE_GETEXECNAME
+# define program_invocation_short_name \
+ prog_inv_sh_nm_from_file(getexecname(), 0)
+# else
+# define program_invocation_short_name \
+ prog_inv_sh_nm_from_file(__FILE__, 1)
+# endif
+static char prog_inv_sh_nm_buf[256];
+static inline char *
+prog_inv_sh_nm_from_file(char *f, char stripext)
+{
+ char *t;
+
+ if ((t = strrchr(f, '/')) != NULL)
+ t++;
+ else
+ t = f;
+
+ strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
+ prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
+
+ if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
+ *t = '\0';
+
+ return prog_inv_sh_nm_buf;
+}
+# endif
+#endif
+
+
+#ifndef HAVE_ERR_H
+static inline void
+errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
+{
+ fprintf(stderr, "%s: ", program_invocation_short_name);
+ if (fmt != NULL) {
+ va_list argp;
+ va_start(argp, fmt);
+ vfprintf(stderr, fmt, argp);
+ va_end(argp);
+ if (adderr)
+ fprintf(stderr, ": ");
+ }
+ if (adderr)
+ fprintf(stderr, "%m");
+ fprintf(stderr, "\n");
+ if (doexit)
+ exit(excode);
+}
+
+#ifndef HAVE_ERR
+# define err(E, FMT...) errmsg(1, E, 1, FMT)
+#endif
+
+#ifndef HAVE_ERRX
+# define errx(E, FMT...) errmsg(1, E, 0, FMT)
+#endif
+
+#ifndef HAVE_WARN
+# define warn(FMT...) errmsg(0, 0, 1, FMT)
+#endif
+
+#ifndef HAVE_WARNX
+# define warnx(FMT...) errmsg(0, 0, 0, FMT)
+#endif
+#endif /* !HAVE_ERR_H */
+
+
+/* Don't use inline function to avoid '#include "nls.h"' in c.h
+ */
+#define errtryhelp(eval) __extension__ ({ \
+ fprintf(stderr, _("Try '%s --help' for more information.\n"), \
+ program_invocation_short_name); \
+ exit(eval); \
+})
+
+/* After failed execvp() */
+#define EX_EXEC_FAILED 126 /* Program located, but not usable. */
+#define EX_EXEC_ENOENT 127 /* Could not find program to exec. */
+#define errexec(name) err(errno == ENOENT ? EX_EXEC_ENOENT : EX_EXEC_FAILED, \
+ _("failed to execute %s"), name)
+
+
+static inline __attribute__((const)) int is_power_of_2(unsigned long num)
+{
+ return (num != 0 && ((num & (num - 1)) == 0));
+}
+
+#ifndef HAVE_LOFF_T
+typedef int64_t loff_t;
+#endif
+
+#if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD)
+#include <sys/types.h>
+#include <dirent.h>
+static inline int dirfd(DIR *d)
+{
+ return d->dd_fd;
+}
+#endif
+
+/*
+ * Fallback defines for old versions of glibc
+ */
+#include <fcntl.h>
+
+#ifdef O_CLOEXEC
+#define UL_CLOEXECSTR "e"
+#else
+#define UL_CLOEXECSTR ""
+#endif
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+#ifdef __FreeBSD_kernel__
+#ifndef F_DUPFD_CLOEXEC
+#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */
+#endif
+#endif
+
+
+#ifndef AI_ADDRCONFIG
+#define AI_ADDRCONFIG 0x0020
+#endif
+
+#ifndef IUTF8
+#define IUTF8 0040000
+#endif
+
+/*
+ * MAXHOSTNAMELEN replacement
+ */
+static inline size_t get_hostname_max(void)
+{
+ long len = sysconf(_SC_HOST_NAME_MAX);
+
+ if (0 < len)
+ return len;
+
+#ifdef MAXHOSTNAMELEN
+ return MAXHOSTNAMELEN;
+#elif HOST_NAME_MAX
+ return HOST_NAME_MAX;
+#endif
+ return 64;
+}
+
+/*
+ * The usleep function was marked obsolete in POSIX.1-2001 and was removed
+ * in POSIX.1-2008. It was replaced with nanosleep() that provides more
+ * advantages (like no interaction with signals and other timer functions).
+ */
+#include <time.h>
+
+static inline int xusleep(useconds_t usec)
+{
+#ifdef HAVE_NANOSLEEP
+ struct timespec waittime = {
+ .tv_sec = usec / 1000000L,
+ .tv_nsec = (usec % 1000000L) * 1000
+ };
+ return nanosleep(&waittime, NULL);
+#elif defined(HAVE_USLEEP)
+ return usleep(usec);
+#else
+# error "System with usleep() or nanosleep() required!"
+#endif
+}
+
+/*
+ * Constant strings for usage() functions. For more info see
+ * Documentation/{howto-usage-function.txt,boilerplate.c}
+ */
+#define USAGE_HEADER _("\nUsage:\n")
+#define USAGE_OPTIONS _("\nOptions:\n")
+#define USAGE_FUNCTIONS _("\nFunctions:\n")
+#define USAGE_COMMANDS _("\nCommands:\n")
+#define USAGE_ARGUMENTS _("\nArguments:\n")
+#define USAGE_COLUMNS _("\nAvailable output columns:\n")
+#define USAGE_SEPARATOR "\n"
+
+#define USAGE_OPTSTR_HELP _("display this help")
+#define USAGE_OPTSTR_VERSION _("display version")
+
+#define USAGE_HELP_OPTIONS(marg_dsc) \
+ "%-" #marg_dsc "s%s\n" \
+ "%-" #marg_dsc "s%s\n" \
+ , " -h, --help", USAGE_OPTSTR_HELP \
+ , " -V, --version", USAGE_OPTSTR_VERSION
+
+#define USAGE_ARG_SEPARATOR "\n"
+#define USAGE_ARG_SIZE(_name) \
+ _(" %s arguments may be followed by the suffixes for\n" \
+ " GiB, TiB, PiB, EiB, ZiB, and YiB (the \"iB\" is optional)\n"), _name
+
+#define USAGE_MAN_TAIL(_man) _("\nFor more details see %s.\n"), _man
+
+#define UTIL_LINUX_VERSION _("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING
+
+#define print_version(eval) __extension__ ({ \
+ exit(eval); \
+})
+
+/*
+ * seek stuff
+ */
+#ifndef SEEK_DATA
+# define SEEK_DATA 3
+#endif
+#ifndef SEEK_HOLE
+# define SEEK_HOLE 4
+#endif
+
+
+/*
+ * Macros to convert #define'itions to strings, for example
+ * #define XYXXY 42
+ * printf ("%s=%s\n", stringify(XYXXY), stringify_value(XYXXY));
+ */
+#define stringify_value(s) stringify(s)
+#define stringify(s) #s
+
+/* Detect if we're compiled with Address Sanitizer
+ * - gcc (__SANITIZE_ADDRESS__)
+ * - clang (__has_feature(address_sanitizer))
+ */
+#if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
+# ifdef __SANITIZE_ADDRESS__
+# define HAS_FEATURE_ADDRESS_SANITIZER 1
+# elif defined(__has_feature)
+# if __has_feature(address_sanitizer)
+# define HAS_FEATURE_ADDRESS_SANITIZER 1
+# endif
+# endif
+# if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
+# define HAS_FEATURE_ADDRESS_SANITIZER 0
+# endif
+#endif
+
+/*
+ * UL_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time
+ * instrumentation shipped with Clang and GCC) to not instrument the
+ * annotated function. Furthermore, it will prevent the compiler from
+ * inlining the function because inlining currently breaks the blacklisting
+ * mechanism of AddressSanitizer.
+ */
+#if __has_feature(address_sanitizer) && __has_attribute(no_sanitize_memory) && __has_attribute(no_sanitize_address)
+# define UL_ASAN_BLACKLIST __attribute__((noinline)) __attribute__((no_sanitize_memory)) __attribute__((no_sanitize_address))
+#else
+# define UL_ASAN_BLACKLIST /* nothing */
+#endif
+
+/*
+ * Note that sysconf(_SC_GETPW_R_SIZE_MAX) returns *initial* suggested size for
+ * pwd buffer and in some cases it is not large enough. See POSIX and
+ * getpwnam_r man page for more details.
+ */
+#define UL_GETPW_BUFSIZ (16 * 1024)
+
+/*
+ * Darwin or other BSDs may only have MAP_ANON. To get it on Darwin we must
+ * define _DARWIN_C_SOURCE before including sys/mman.h. We do this in config.h.
+ */
+#if !defined MAP_ANONYMOUS && defined MAP_ANON
+# define MAP_ANONYMOUS (MAP_ANON)
+#endif
+
+#endif /* UTIL_LINUX_C_H */
diff --git a/src/libexec/poudriere/setsid/setsid.1 b/src/libexec/poudriere/setsid/setsid.1
new file mode 100644
index 00000000..c1553c8e
--- /dev/null
+++ b/src/libexec/poudriere/setsid/setsid.1
@@ -0,0 +1,69 @@
+'\" t
+.\" Title: setsid
+.\" Author: [see the "AUTHOR(S)" section]
+.\" Generator: Asciidoctor 2.0.12
+.\" Date: 2021-06-27
+.\" Manual: User Commands
+.\" Source: util-linux 2.37
+.\" Language: English
+.\"
+.TH "SETSID" "1" "2021-06-27" "util\-linux 2.37" "User Commands"
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.ss \n[.ss] 0
+.nh
+.ad l
+.de URL
+\fI\\$2\fP <\\$1>\\$3
+..
+.als MTO URL
+.if \n[.g] \{\
+. mso www.tmac
+. am URL
+. ad l
+. .
+. am MTO
+. ad l
+. .
+. LINKSTYLE blue R < >
+.\}
+.SH "NAME"
+setsid \- run a program in a new session
+.SH "SYNOPSIS"
+.sp
+\fBsetsid\fP [options] \fIprogram\fP [\fIarguments\fP]
+.SH "DESCRIPTION"
+.sp
+\fBsetsid\fP runs a program in a new session. The command calls \fBfork\fP(2) if already a process group leader. Otherwise, it executes a program in the current process. This default behavior is possible to override by the \fB\-\-fork\fP option.
+.SH "OPTIONS"
+.sp
+\fB\-c\fP, \fB\-\-ctty\fP
+.RS 4
+Set the controlling terminal to the current one.
+.RE
+.sp
+\fB\-f\fP, \fB\-\-fork\fP
+.RS 4
+Always create a new process.
+.RE
+.sp
+\fB\-w\fP, \fB\-\-wait\fP
+.RS 4
+Wait for the execution of the program to end, and return the exit status of this program as the exit status of \fBsetsid\fP.
+.RE
+.sp
+\fB\-V\fP, \fB\-\-version\fP
+.RS 4
+Display version information and exit.
+.RE
+.sp
+\fB\-h\fP, \fB\-\-help\fP
+.RS 4
+Display help text and exit.
+.RE
+.SH "AUTHORS"
+.sp
+.MTO "jrs\(atworld.std.com" "Rick Sladkey" ""
+.SH "SEE ALSO"
+.sp
+\fBsetsid\fP(2) \ No newline at end of file
diff --git a/src/libexec/poudriere/setsid/setsid.c b/src/libexec/poudriere/setsid/setsid.c
new file mode 100644
index 00000000..5eafea4b
--- /dev/null
+++ b/src/libexec/poudriere/setsid/setsid.c
@@ -0,0 +1,120 @@
+/*
+ * setsid.c -- execute a command in a new session
+ * Rick Sladkey <jrs@world.std.com>
+ * In the public domain.
+ *
+ * 1999-02-22 Arkadiusz Miƛkiewicz <misiek@pld.ORG.PL>
+ * - added Native Language Support
+ *
+ * 2001-01-18 John Fremlin <vii@penguinpowered.com>
+ * - fork in case we are process group leader
+ *
+ * 2008-08-20 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
+ * - if forked, wait on child process and emit its return code.
+ */
+
+#include <getopt.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "c.h"
+
+#define _(x) (x)
+
+static void __attribute__((__noreturn__)) usage(void)
+{
+ FILE *out = stdout;
+ fputs(USAGE_HEADER, out);
+ fprintf(out, _(
+ " %s [options] <program> [arguments ...]\n"),
+ program_invocation_short_name);
+
+ fputs(USAGE_SEPARATOR, out);
+ fputs(_("Run a program in a new session.\n"), out);
+
+ fputs(USAGE_OPTIONS, out);
+ fputs(_(" -c, --ctty set the controlling terminal to the current one\n"), out);
+ fputs(_(" -f, --fork always fork\n"), out);
+ fputs(_(" -w, --wait wait program to exit, and use the same return\n"), out);
+
+ printf(USAGE_HELP_OPTIONS(16));
+
+ printf(USAGE_MAN_TAIL("setsid(1)"));
+ exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+ int ch, forcefork = 0;
+ int ctty = 0;
+ pid_t pid;
+ int status = 0;
+
+ static const struct option longopts[] = {
+ {"ctty", no_argument, NULL, 'c'},
+ {"fork", no_argument, NULL, 'f'},
+ {"wait", no_argument, NULL, 'w'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ setlocale(LC_ALL, "");
+
+ while ((ch = getopt_long(argc, argv, "+Vhcfw", longopts, NULL)) != -1)
+ switch (ch) {
+ case 'c':
+ ctty=1;
+ break;
+ case 'f':
+ forcefork = 1;
+ break;
+ case 'w':
+ status = 1;
+ break;
+
+ case 'h':
+ usage();
+ case 'V':
+ print_version(EXIT_SUCCESS);
+ default:
+ exit(EXIT_FAILURE);
+ }
+
+ if (argc - optind < 1) {
+ errx(EXIT_FAILURE, _("no command specified"));
+ }
+
+ if (forcefork || getpgrp() == getpid()) {
+ pid = fork();
+ switch (pid) {
+ case -1:
+ err(EXIT_FAILURE, _("fork"));
+ case 0:
+ /* child */
+ break;
+ default:
+ /* parent */
+ if (!status)
+ return EXIT_SUCCESS;
+ if (wait(&status) != pid)
+ err(EXIT_FAILURE, "wait");
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
+ err(status, _("child %d did not exit normally"), pid);
+ }
+ }
+ if (setsid() < 0)
+ /* cannot happen */
+ err(EXIT_FAILURE, _("setsid failed"));
+
+ if (ctty && ioctl(STDIN_FILENO, TIOCSCTTY, 1))
+ err(EXIT_FAILURE, _("failed to set the controlling terminal"));
+ execvp(argv[optind], argv + optind);
+ errexec(argv[optind]);
+}