From 72b6d428af4925e7064c6166b732301c8918e8c4 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Sun, 12 Feb 2023 02:15:32 +0000
Subject: Add multicall configuration
Signed-off-by: Laurent Bercot
---
.gitignore | 2 ++
INSTALL | 23 +++++++++++++
Makefile | 30 +++++++++++------
NEWS | 3 +-
configure | 9 ++++++
doc/index.html | 11 +++++++
doc/s6-linux-utils.html | 53 ++++++++++++++++++++++++++++++
doc/upgrade.html | 2 ++
package/modes | 1 +
package/targets.mak | 36 +++++++++++++--------
tools/gen-multicall.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 232 insertions(+), 24 deletions(-)
create mode 100644 doc/s6-linux-utils.html
create mode 100755 tools/gen-multicall.sh
diff --git a/.gitignore b/.gitignore
index b360b5b..6231133 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@
/lib*.so.xyzzy
/config.mak
/src/include/s6-linux-utils/config.h
+/src/multicall/s6-linux-utils.c
+/s6-linux-utils
/rngseed
/s6-chroot
/s6-freeramdisk
diff --git a/INSTALL b/INSTALL
index c4d428d..5a8fa61 100644
--- a/INSTALL
+++ b/INSTALL
@@ -163,3 +163,26 @@ without relying on a PATH search.
skarnet.org packages do not support out-of-tree builds. They
are small, so it does not cost much to duplicate the entire
source tree if parallel builds are needed.
+
+
+* Multicall binary
+ ----------------
+
+ Starting with version 2.6.1.0, the s6-linux-utils package comes
+with an alternative build in the form of a multicall binary, simply
+called "s6-linux-utils", that includes the functionality of *all*
+the other binaries; it switches functionalities depending on the name
+it is called with, or the subcommand it is given:
+"s6-linux-utils s6-ps -H" will print a tree of the current running
+processes, same as "s6-ps -H" if s6-ps is a link to the
+s6-linux-utils program.
+
+ To use this, use the --enable-multicall option to configure. Only
+the s6-linux-utils binary will be built, and other programs will be
+created as symbolic links to s6-linux-utils at installation time.
+
+ The multicall setup saves a lot of disk space, at the price of
+am unnoticeable amount of CPU usage. RAM usage is about equivalent
+and difficult to assess. The setup is meant for embedded devices
+or small distributions with a focus on saving disk space.
+
diff --git a/Makefile b/Makefile
index cd6c7f0..0fc3d40 100644
--- a/Makefile
+++ b/Makefile
@@ -17,8 +17,9 @@ CC = $(error Please use ./configure first)
STATIC_LIBS :=
SHARED_LIBS :=
INTERNAL_LIBS :=
-EXTRA_TARGETS :=
LIB_DEFS :=
+BIN_SYMLINKS :=
+EXTRA_TEMP :=
define library_definition
LIB$(firstword $(subst =, ,$(1))) := lib$(lastword $(subst =, ,$(1))).$(if $(DO_ALLSTATIC),a,so).xyzzy
@@ -53,14 +54,14 @@ RANLIB := $(CROSS_COMPILE)ranlib
STRIP := $(CROSS_COMPILE)strip
INSTALL := ./tools/install.sh
-ALL_BINS := $(LIBEXEC_TARGETS) $(BIN_TARGETS)
+ALL_BINS := $(BIN_TARGETS) $(LIBEXEC_TARGETS)
ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) $(INTERNAL_LIBS)
ALL_INCLUDES := $(wildcard src/include/$(package)/*.h)
all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES)
clean:
- @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(wildcard src/*/*.o src/*/*.lo) $(EXTRA_TARGETS)
+ @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(EXTRA_TEMP) $(wildcard src/*/*.o src/*/*.lo)
distclean: clean
@exec rm -f config.mak src/include/$(package)/config.h
@@ -84,7 +85,7 @@ endif
install: install-dynlib install-libexec install-bin install-lib install-include
install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so)
install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%)
-install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%)
+install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%) $(BIN_SYMLINKS:%=$(DESTDIR)$(bindir)/%)
install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a)
install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h)
install-data: $(ALL_DATA:src/etc/%=$(DESTDIR)$(datadir)/%)
@@ -96,7 +97,7 @@ $(DESTDIR)$(exthome): $(DESTDIR)$(home)
update: $(DESTDIR)$(exthome)
-global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M)) $(BIN_TARGETS:%=$(DESTDIR)$(sproot)/command/%)
+global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M)) $(BIN_TARGETS:%=$(DESTDIR)$(sproot)/command/%) $(BIN_SYMLINKS:%=$(DESTDIR)$(sproot)/command/%)
$(DESTDIR)$(sproot)/command/%: $(DESTDIR)$(home)/command/%
exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/command/$(
- See the enclosed INSTALL file for installation details.
+ - Starting with version 2.6.1.0, you can use the
+--enable-multicall configure option to save disk space.
Upgrade notes
@@ -99,6 +101,9 @@ the previous versions of s6-linux-utils and the current one.
126 if they fail to execute into a program for another reason.
+
+ (Miscellaneous tools)
+
+
+ (Multicall configuration)
+
+
Related resources
diff --git a/doc/s6-linux-utils.html b/doc/s6-linux-utils.html
new file mode 100644
index 0000000..d366937
--- /dev/null
+++ b/doc/s6-linux-utils.html
@@ -0,0 +1,53 @@
+
+
+
+
+
+ s6-linux-utils: the s6-linux-utils multicall binary
+
+
+
+
+
+
+
+s6-linux-utils
+Software
+skarnet.org
+
+
+ The s6-linux-utils multicall binary
+
+
+The s6-linux-utils program is only available when the
+--enable-multicall option has been given to the configure
+program at build time. In this configuration, s6-linux-utils is
+a multicall binary implementing the functionality of all
+the programs in the s6-linux-utils package; and the other programs, instead
+of being executables of their own, are symbolic links to the
+s6-linux-utils binary.
+
+
+ Interface
+
+
+ s6-linux-utils subcommand subcommand_arguments...
+
+
+
+ s6-linux-utils will run the subcommand will its arguments. For
+instance, s6-linux-utils s6-ps -H will run the equivalent of the
+s6-ps program, so this command will print a
+tree of the currently running processes.
+
+
+
+ Alternatively, if s6-linux-utils is called with the name of an existing
+command, it will run the equivalent of that command. For instance,
+if the /usr/bin/s6-ps file is a (hard or symbolic) link to
+the s6-linux-utils binary, /usr/bin/s6-ps -H will print
+a tree of the currently running processes.
+
+
+
+
diff --git a/doc/upgrade.html b/doc/upgrade.html
index 79e9ef1..eaa7187 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -23,6 +23,8 @@
in 2.6.0.1
diff --git a/package/modes b/package/modes
index 46b4623..aad1e20 100644
--- a/package/modes
+++ b/package/modes
@@ -9,3 +9,4 @@ s6-ps 0755
s6-swapoff 0744
s6-swapon 0744
s6-umount 0755
+s6-linux-utils 0755
diff --git a/package/targets.mak b/package/targets.mak
index fb7af4c..6403a9b 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -1,14 +1,24 @@
-BIN_TARGETS := \
-rngseed \
-s6-chroot \
-s6-freeramdisk \
-s6-hostname \
-s6-logwatch \
-s6-mount \
-s6-pivotchroot \
-s6-ps \
-s6-swapoff \
-s6-swapon \
-s6-umount
-
LIBEXEC_TARGETS :=
+
+ifeq ($(MULTICALL),1)
+
+BIN_TARGETS := $(package)
+BIN_SYMLINKS := $(notdir $(wildcard src/$(package)/deps-exe/*))
+EXTRA_TEMP := src/multicall/$(package).c
+
+define symlink_definition
+SYMLINK_TARGET_$(1) := $(package)
+endef
+$(foreach name,$(BIN_SYMLINKS),$(eval $(call symlink_definition,$(name))))
+
+src/multicall/$(package).c: tools/gen-multicall.sh src/$(package)/deps-exe
+ ./tools/gen-multicall.sh $(package) > src/multicall/$(package).c
+
+src/multicall/$(package).o: src/multicall/$(package).c src/include/$(package)/config.h
+
+else
+
+BIN_TARGETS := $(notdir $(wildcard src/$(package)/deps-exe/*))
+BIN_SYMLINKS :=
+
+endif
diff --git a/tools/gen-multicall.sh b/tools/gen-multicall.sh
new file mode 100755
index 0000000..843f4df
--- /dev/null
+++ b/tools/gen-multicall.sh
@@ -0,0 +1,86 @@
+#!/bin/sh -e
+
+P="$1"
+p=`echo $P | tr - _`
+
+echo '/* ISC license. */'
+echo
+echo '#include '
+echo
+{ echo '#include ' ; echo '#include ' ; cat src/$P/*.c | grep '^#include <' | grep -vF '
+
+#include
+
+#include <$P/config.h>
+#include "s6ps.h"
+
+typedef int main_func (int, char const *const *, char const *const *) ;
+typedef main_func *main_func_ref ;
+
+typedef struct multicall_app_s multicall_app, *multicall_app_ref ;
+struct multicall_app_s
+{
+ char const *name ;
+ main_func_ref mainf ;
+} ;
+
+static int multicall_app_cmp (void const *a, void const *b)
+{
+ char const *name = a ;
+ multicall_app const *p = b ;
+ return strcmp(name, p->name) ;
+}
+EOF
+
+for i in `ls -1 src/$P/deps-exe` ; do
+ j=`echo $i | tr - _`
+ echo
+ grep -v '^#include ' < src/$P/${i}.c | grep -vF '/* ISC license. */' | sed -e "s/int main (.*)$/int ${j}_main (int argc, char const *const *argv, char const *const *envp)/"
+ echo
+ echo '#undef USAGE'
+ echo '#undef dieusage'
+ echo '#undef dienomem'
+done
+
+cat <mainf))(argc-1, argv+1, envp) ;
+}
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ multicall_app const *p ;
+ char const *name = strrchr(argv[0], '/') ;
+ if (name) name++ ; else name = argv[0] ;
+ p = bsearch(name, multicall_apps, sizeof(multicall_apps) / sizeof(multicall_app), sizeof(multicall_app), &multicall_app_cmp) ;
+ return p ? (*(p->mainf))(argc, argv, envp) : ${p}_main(argc, argv, envp) ;
+}
+EOF
--
cgit 1.4.1