From 42c26846a58713ca53fad908f72303f467d614a3 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Sun, 10 Nov 2019 22:07:41 +0100 Subject: [PATCH] - arget-tools: add sysvinit (currently unused) --- make/target-tools.mk | 36 ++++ ...sue-that-clang-reports-about-mutlipl.patch | 52 +++++ ...acros.h-for-major-minor-defines-in-g.patch | 71 +++++++ patches/sysvinit/crypt-lib.patch | 25 +++ patches/sysvinit/pidof-add-m-option.patch | 189 ++++++++++++++++++ patches/sysvinit/realpath.patch | 78 ++++++++ 6 files changed, 451 insertions(+) create mode 100644 patches/sysvinit/0001-This-fixes-an-issue-that-clang-reports-about-mutlipl.patch create mode 100644 patches/sysvinit/0001-include-sys-sysmacros.h-for-major-minor-defines-in-g.patch create mode 100644 patches/sysvinit/crypt-lib.patch create mode 100644 patches/sysvinit/pidof-add-m-option.patch create mode 100644 patches/sysvinit/realpath.patch diff --git a/make/target-tools.mk b/make/target-tools.mk index 394a7469..560cd8c6 100644 --- a/make/target-tools.mk +++ b/make/target-tools.mk @@ -1802,6 +1802,42 @@ rsync: $(RSYNC_DEPS) $(ARCHIVE)/$(RSYNC_SOURCE) | $(TARGET_DIR) # ----------------------------------------------------------------------------- +SYSVINIT_VER = 2.88dsf +SYSVINIT_TMP = sysvinit-$(SYSVINIT_VER) +SYSVINIT_SOURCE = sysvinit-$(SYSVINIT_VER).tar.bz2 +SYSVINIT_URL = http://download.savannah.nongnu.org/releases/sysvinit + +$(ARCHIVE)/$(SYSVINIT_SOURCE): + $(DOWNLOAD) $(SYSVINIT_URL)/$(SYSVINIT_SOURCE) + +SYSVINIT_PATCH = crypt-lib.patch +SYSVINIT_PATCH += pidof-add-m-option.patch +SYSVINIT_PATCH += realpath.patch +SYSVINIT_PATCH += 0001-include-sys-sysmacros.h-for-major-minor-defines-in-g.patch +SYSVINIT_PATCH += 0001-This-fixes-an-issue-that-clang-reports-about-mutlipl.patch + +define SYSVINIT_INSTALL + for sbin in halt init shutdown killall5; do \ + $(INSTALL_EXEC) -D $(BUILD_TMP)/$(SYSVINIT_TMP)/src/$$sbin $(TARGET_DIR)/sbin/$$sbin || exit 1; \ + done + ln -sf /sbin/halt $(TARGET_DIR)/sbin/reboot + ln -sf /sbin/halt $(TARGET_DIR)/sbin/poweroff + ln -sf killall5 $(TARGET_DIR)/sbin/pidof +endef + +sysvinit: $(ARCHIVE)/$(SYSVINIT_SOURCE) | $(TARGET_DIR) + $(REMOVE)/$(SYSVINIT_TMP) + $(UNTAR)/$(SYSVINIT_SOURCE) + $(CHDIR)/$(SYSVINIT_TMP); \ + $(call apply_patches, $(addprefix $(@F)/,$(SYSVINIT_PATCH))); \ + $(BUILD_ENV) \ + $(MAKE) -C src SULOGINLIBS=-lcrypt + $(SYSVINIT_INSTALL) + $(REMOVE)/$(SYSVINIT_TMP) + $(TOUCH) + +# ----------------------------------------------------------------------------- + CA-BUNDLE_SOURCE = cacert.pem CA-BUNDLE_URL = https://curl.haxx.se/ca diff --git a/patches/sysvinit/0001-This-fixes-an-issue-that-clang-reports-about-mutlipl.patch b/patches/sysvinit/0001-This-fixes-an-issue-that-clang-reports-about-mutlipl.patch new file mode 100644 index 00000000..9ae0659e --- /dev/null +++ b/patches/sysvinit/0001-This-fixes-an-issue-that-clang-reports-about-mutlipl.patch @@ -0,0 +1,52 @@ +From 36ac97bfe51797458442a6035219a504a42e703a Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Fri, 21 Aug 2015 10:56:40 -0700 +Subject: [PATCH] This fixes an issue that clang reports about mutliple output + files + +Issue is that we are passing .h file to link step as seen below. + +| arm-oe-linux-gnueabi-clang -march=armv7-a -mthumb -mfloat-abi=hard +-mfpu=neon-vfpv4 -mtune=cortex-a7 -D__extern_always_inline=inline +-no-integrated-as +--sysroot=/mnt/home/kraj/work/angstrom/sources/openembedded-core/build/tmp-glibc/sysroots/raspberrypi2 +-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed halt.o ifdown.o hddown.o +utmp.o reboot.h -o halt +| clang-3.7: error: cannot specify -o when generating multiple output +files + +Upstream-Status: Pending + +Signed-off-by: Khem Raj +--- + src/Makefile | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index e77ed5f..a6f9f40 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -96,9 +96,9 @@ all: $(BIN) $(SBIN) $(USRBIN) + init: LDLIBS += $(INITLIBS) $(STATIC) + init: init.o init_utmp.o + +-halt: halt.o ifdown.o hddown.o utmp.o reboot.h ++halt: halt.o ifdown.o hddown.o utmp.o + +-last: last.o oldutmp.h ++last: last.o + + mesg: mesg.o + +@@ -113,7 +113,7 @@ sulogin: sulogin.o + + wall: dowall.o wall.o + +-shutdown: dowall.o shutdown.o utmp.o reboot.h ++shutdown: dowall.o shutdown.o utmp.o + + bootlogd: LDLIBS += -lutil + bootlogd: bootlogd.o +-- +2.1.4 + diff --git a/patches/sysvinit/0001-include-sys-sysmacros.h-for-major-minor-defines-in-g.patch b/patches/sysvinit/0001-include-sys-sysmacros.h-for-major-minor-defines-in-g.patch new file mode 100644 index 00000000..2575b59b --- /dev/null +++ b/patches/sysvinit/0001-include-sys-sysmacros.h-for-major-minor-defines-in-g.patch @@ -0,0 +1,71 @@ +From 29c7a529d3bb0c1e20239f885e74c5036f1a908c Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Mon, 6 Aug 2018 15:38:58 -0700 +Subject: [PATCH] include sys/sysmacros.h for major/minor defines in glibc + +Signed-off-by: Khem Raj +Upstream-Status: Pending +--- + src/bootlogd.c | 3 +++ + src/bootlogd.o | Bin 58448 -> 60376 bytes + src/dowall.c | 3 +++ + src/shutdown.c | 4 +++- + 4 files changed, 9 insertions(+), 1 deletion(-) + +Index: sysvinit-2.88dsf/src/bootlogd.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/bootlogd.c ++++ sysvinit-2.88dsf/src/bootlogd.c +@@ -53,6 +53,9 @@ + #ifdef __linux__ + #include + #endif ++#ifdef __GLIBC__ ++#include ++#endif + + char *Version = "@(#) bootlogd 2.86 03-Jun-2004 miquels@cistron.nl"; + +Index: sysvinit-2.88dsf/src/dowall.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/dowall.c ++++ sysvinit-2.88dsf/src/dowall.c +@@ -37,6 +37,9 @@ + #include + #include + #include ++#ifdef __GLIBC__ ++#include ++#endif + + #ifndef _PATH_DEV + # define _PATH_DEV "/dev/" +Index: sysvinit-2.88dsf/src/shutdown.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/shutdown.c ++++ sysvinit-2.88dsf/src/shutdown.c +@@ -57,7 +57,9 @@ + #include "reboot.h" + #include "initreq.h" + #include "init.h" +- ++#ifdef __GLIBC__ ++#include ++#endif + + char *Version = "@(#) shutdown 2.86-1 31-Jul-2004 miquels@cistron.nl"; + +Index: sysvinit-2.88dsf/src/mountpoint.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/mountpoint.c ++++ sysvinit-2.88dsf/src/mountpoint.c +@@ -32,6 +32,9 @@ + #include + #include + #include ++#ifdef __GLIBC__ ++#include ++#endif + + int dostat(char *path, struct stat *st, int do_lstat, int quiet) + { diff --git a/patches/sysvinit/crypt-lib.patch b/patches/sysvinit/crypt-lib.patch new file mode 100644 index 00000000..ceadbf0c --- /dev/null +++ b/patches/sysvinit/crypt-lib.patch @@ -0,0 +1,25 @@ +Upstream-Status: Inappropriate [configuration] + +# The src Makefile was checking for libcrypt.a on the host, not in the +# build environment. This patch checks for $LCRYPT in the environment +# and uses it if it's there. +# - jdike@linux.intel.com + +Index: sysvinit-2.88dsf/src/Makefile +=================================================================== +--- sysvinit-2.88dsf.orig/src/Makefile ++++ sysvinit-2.88dsf/src/Makefile +@@ -78,9 +78,13 @@ else + endif + + # Additional libs for GNU libc. ++ifneq ($(LCRYPT),) ++ SULOGINLIBS += $(LCRYPT) ++else + ifneq ($(wildcard /usr/lib*/libcrypt.a),) + SULOGINLIBS += -lcrypt + endif ++endif + + all: $(BIN) $(SBIN) $(USRBIN) + diff --git a/patches/sysvinit/pidof-add-m-option.patch b/patches/sysvinit/pidof-add-m-option.patch new file mode 100644 index 00000000..5b5dfdc0 --- /dev/null +++ b/patches/sysvinit/pidof-add-m-option.patch @@ -0,0 +1,189 @@ +pidof: add -m option + +When used with -o, will also omit any processes that have the same +argv[0] and argv[1] as any explicitly omitted process ids. This can be +used to avoid multiple shell scripts concurrently calling pidof returning +each other's pids. + +https://bugzilla.redhat.com/show_bug.cgi?id=883856 + +Upstream-Status: backport +Imported patch from: https://bugzilla.redhat.com/attachment.cgi?id=658166 + +Signed-off-by: Hongxu Jia +--- + man/pidof.8 | 6 ++++++ + src/killall5.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- + 2 files changed, 65 insertions(+), 3 deletions(-) + +diff --git a/man/pidof.8 b/man/pidof.8 +--- a/man/pidof.8 ++++ b/man/pidof.8 +@@ -24,6 +24,7 @@ pidof -- find the process ID of a running program. + .RB [ \-c ] + .RB [ \-n ] + .RB [ \-x ] ++.RB [ \-m ] + .RB [ \-o + .IR omitpid[,omitpid..] ] + .RB [ \-o +@@ -63,6 +64,11 @@ shells running the named scripts. + Tells \fIpidof\fP to omit processes with that process id. The special + pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP + program, in other words the calling shell or shell script. ++.IP -m ++When used with -o, will also omit any processes that have the same ++argv[0] and argv[1] as any explicitly omitted process ids. This can be ++used to avoid multiple shell scripts concurrently calling pidof returning ++each other's pids. + .SH "EXIT STATUS" + .TP + .B 0 +diff --git a/src/killall5.c b/src/killall5.c +index 5937d98..e73885e 100644 +--- a/src/killall5.c ++++ b/src/killall5.c +@@ -118,6 +118,7 @@ typedef struct _s_nfs + + /* List of processes. */ + PROC *plist; ++PROC *olist; + + /* List of processes to omit. */ + OMIT *omit; +@@ -345,6 +346,20 @@ static void clear_mnt(void) + } + } + ++static void clear_omit(void) ++{ ++ OMIT *o; ++ PROC *p; ++ for (o = omit; o; o = omit) { ++ omit = omit->next; ++ free(o); ++ } ++ for (p = olist; p; p = olist) { ++ olist = olist->next; ++ free(p); ++ } ++} ++ + /* + * Check if path is ia shadow off a NFS partition. + */ +@@ -452,6 +467,7 @@ int readproc(int do_stat) + DIR *dir; + FILE *fp; + PROC *p, *n; ++ OMIT *o, *m; + struct dirent *d; + struct stat st; + char path[PATH_MAX+1]; +@@ -624,6 +640,17 @@ int readproc(int do_stat) + p->next = plist; + plist = p; + p->pid = pid; ++ /* Could be smarter, but it's a small list. */ ++ m = omit; ++ for (o = omit; m; o = m) { ++ m = o->next; ++ if (o->pid == p->pid) { ++ n = (PROC*)xmalloc(sizeof(PROC)); ++ *n = *p; ++ n->next = olist; ++ olist = n; ++ } ++ } + } + closedir(dir); + +@@ -813,6 +840,26 @@ PIDQ_HEAD *pidof(char *prog) + return q; + } + ++int matches(PROC *o, PROC *p) ++{ ++ int ret = 0; ++ char *oargv1, *pargv1; ++ if ((o->argv0 && p->argv0 && !strcmp(o->argv0,p->argv0))) { ++ if (o->argv1 && p->argv1) { ++ if ((oargv1 = canonicalize_file_name(o->argv1)) == NULL) ++ oargv1 = strdup(o->argv1); ++ if ((pargv1 = canonicalize_file_name(p->argv1)) == NULL) ++ pargv1 = strdup(p->argv1); ++ if (! strcmp(oargv1, pargv1)) { ++ ret = 1; ++ } ++ free(oargv1); ++ free(pargv1); ++ } ++ } ++ return ret; ++} ++ + /* Give usage message and exit. */ + void usage(void) + { +@@ -845,6 +892,7 @@ void nsyslog(int pri, char *fmt, ...) + #define PIDOF_SINGLE 0x01 + #define PIDOF_OMIT 0x02 + #define PIDOF_NETFS 0x04 ++#define PIDOF_OMIT_OMIT_MATCHES 0x08 + + /* + * Pidof functionality. +@@ -861,6 +909,7 @@ int main_pidof(int argc, char **argv) + struct stat st; + char tmp[512]; + ++ olist = (PROC*)0; + omit = (OMIT*)0; + nlist = (NFS*)0; + opterr = 0; +@@ -868,7 +917,7 @@ int main_pidof(int argc, char **argv) + if ((token = getenv("PIDOF_NETFS")) && (strcmp(token,"no") != 0)) + flags |= PIDOF_NETFS; + +- while ((opt = getopt(argc,argv,"hco:sxn")) != EOF) switch (opt) { ++ while ((opt = getopt(argc,argv,"hcmo:sxn")) != EOF) switch (opt) { + case '?': + nsyslog(LOG_ERR,"invalid options on command line!\n"); + closelog(); +@@ -907,6 +956,9 @@ int main_pidof(int argc, char **argv) + case 'x': + scripts_too++; + break; ++ case 'm': ++ flags |= PIDOF_OMIT_OMIT_MATCHES; ++ break; + case 'n': + flags |= PIDOF_NETFS; + break; +@@ -938,10 +990,13 @@ int main_pidof(int argc, char **argv) + pid_t spid = 0; + while ((p = get_next_from_pid_q(q))) { + if ((flags & PIDOF_OMIT) && omit) { +- OMIT * optr; +- for (optr = omit; optr; optr = optr->next) { ++ PROC * optr; ++ for (optr = olist; optr; optr = optr->next) { + if (optr->pid == p->pid) + break; ++ if (flags & PIDOF_OMIT_OMIT_MATCHES) ++ if (matches(optr, p)) ++ break; + } + + /* +@@ -977,6 +1032,7 @@ int main_pidof(int argc, char **argv) + if (!first) + printf("\n"); + ++ clear_omit(); + clear_mnt(); + + closelog(); +-- +1.8.1.2 + diff --git a/patches/sysvinit/realpath.patch b/patches/sysvinit/realpath.patch new file mode 100644 index 00000000..5e0dca3b --- /dev/null +++ b/patches/sysvinit/realpath.patch @@ -0,0 +1,78 @@ +Fix build on musl use realpath() API its available on all libcs + +realpath() API doesnt work on systems with PATH_MAX set to be unlimited e.g. GNU/Hurd +However for Linux it should always work + +Upstream-Status: Inappropriate[Linux specific] + +Signed-off-by: Khem Raj + +Index: sysvinit-2.88dsf/src/ifdown.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/ifdown.c 2010-03-23 07:37:01.000000000 -0700 ++++ sysvinit-2.88dsf/src/ifdown.c 2014-04-02 00:43:43.675437029 -0700 +@@ -26,11 +26,11 @@ + #include + #include + #include ++#include + + #include + #include + #include +-#include + + #include + #include +Index: sysvinit-2.88dsf/src/init.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/init.c 2014-04-02 00:42:10.488770162 -0700 ++++ sysvinit-2.88dsf/src/init.c 2014-04-02 00:42:59.432103823 -0700 +@@ -49,6 +49,7 @@ + #include + #include + #include ++#include + #include + #include + +Index: sysvinit-2.88dsf/src/mountpoint.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/mountpoint.c 2009-09-10 01:28:49.000000000 -0700 ++++ sysvinit-2.88dsf/src/mountpoint.c 2014-04-02 00:44:18.248770942 -0700 +@@ -23,6 +23,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include + #include + #include + #include +Index: sysvinit-2.88dsf/src/killall5.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/killall5.c 2014-03-26 00:49:52.982668074 -0700 ++++ sysvinit-2.88dsf/src/killall5.c 2014-04-02 00:46:45.838771653 -0700 +@@ -846,9 +846,9 @@ + char *oargv1, *pargv1; + if ((o->argv0 && p->argv0 && !strcmp(o->argv0,p->argv0))) { + if (o->argv1 && p->argv1) { +- if ((oargv1 = canonicalize_file_name(o->argv1)) == NULL) ++ if ((oargv1 = realpath(o->argv1, NULL)) == NULL) + oargv1 = strdup(o->argv1); +- if ((pargv1 = canonicalize_file_name(p->argv1)) == NULL) ++ if ((pargv1 = realpath(p->argv1, NULL)) == NULL) + pargv1 = strdup(p->argv1); + if (! strcmp(oargv1, pargv1)) { + ret = 1; +Index: sysvinit-2.88dsf/src/wall.c +=================================================================== +--- sysvinit-2.88dsf.orig/src/wall.c 2009-11-22 14:05:53.000000000 -0800 ++++ sysvinit-2.88dsf/src/wall.c 2014-04-02 00:49:15.258772217 -0700 +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + #include "init.h" + +