diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-02-11 08:13:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-02-11 08:13:14 +0000 |
commit | 2f8984613e17f9e5971ec338240b0bb6d2dd1cc6 (patch) | |
tree | 4061a64dc5ee8c415ca249ec1852cfc666e1468b | |
parent | 3caba3fd8f3825544c065ec62e4298c6edc76b28 (diff) | |
download | s6-linux-utils-2f8984613e17f9e5971ec338240b0bb6d2dd1cc6.tar.xz |
Code refactor; only s6-ps has remaining globals now
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | package/deps.mak | 67 | ||||
-rw-r--r-- | package/targets.mak | 1 | ||||
-rw-r--r-- | src/include-local/mount-constants.h (renamed from src/minutils/mount-constants.h) | 37 | ||||
-rw-r--r-- | src/include-local/s6-ps.h (renamed from src/minutils/s6-ps.h) | 10 | ||||
-rw-r--r-- | src/libps/deps-lib/s6ps (renamed from src/minutils/deps-exe/s6-ps) | 7 | ||||
-rw-r--r-- | src/libps/s6ps_grcache.c (renamed from src/minutils/s6ps_grcache.c) | 2 | ||||
-rw-r--r-- | src/libps/s6ps_otree.c (renamed from src/minutils/s6ps_otree.c) | 2 | ||||
-rw-r--r-- | src/libps/s6ps_pfield.c (renamed from src/minutils/s6ps_pfield.c) | 3 | ||||
-rw-r--r-- | src/libps/s6ps_pwcache.c (renamed from src/minutils/s6ps_pwcache.c) | 1 | ||||
-rw-r--r-- | src/libps/s6ps_statparse.c (renamed from src/minutils/s6ps_statparse.c) | 8 | ||||
-rw-r--r-- | src/libps/s6ps_ttycache.c (renamed from src/minutils/s6ps_ttycache.c) | 2 | ||||
-rw-r--r-- | src/libps/s6ps_wchan.c (renamed from src/minutils/s6ps_wchan.c) | 2 | ||||
-rw-r--r-- | src/minutils/s6-mount.c | 149 | ||||
-rw-r--r-- | src/multicall/deps-exe/s6-linux-utils | 5 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/rngseed (renamed from src/minutils/deps-exe/rngseed) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-chroot (renamed from src/minutils/deps-exe/s6-chroot) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-freeramdisk (renamed from src/minutils/deps-exe/s6-freeramdisk) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-hostname (renamed from src/minutils/deps-exe/s6-hostname) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-logwatch (renamed from src/minutils/deps-exe/s6-logwatch) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-mount (renamed from src/minutils/deps-exe/s6-mount) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-pivotchroot (renamed from src/minutils/deps-exe/s6-pivotchroot) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-ps | 4 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-swapoff (renamed from src/minutils/deps-exe/s6-swapoff) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-swapon (renamed from src/minutils/deps-exe/s6-swapon) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/deps-exe/s6-umount (renamed from src/minutils/deps-exe/s6-umount) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/rngseed.c (renamed from src/minutils/rngseed.c) | 22 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-chroot.c (renamed from src/minutils/s6-chroot.c) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-freeramdisk.c (renamed from src/minutils/s6-freeramdisk.c) | 1 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-hostname.c (renamed from src/minutils/s6-hostname.c) | 11 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-logwatch.c (renamed from src/minutils/s6-logwatch.c) | 69 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-mount.c | 166 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-pivotchroot.c (renamed from src/minutils/s6-pivotchroot.c) | 0 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-ps.c (renamed from src/minutils/s6-ps.c) | 1 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-swapoff.c (renamed from src/minutils/s6-swapoff.c) | 9 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-swapon.c (renamed from src/minutils/s6-swapon.c) | 3 | ||||
-rw-r--r-- | src/s6-linux-utils/s6-umount.c (renamed from src/minutils/s6-umount.c) | 15 |
37 files changed, 319 insertions, 283 deletions
@@ -1,8 +1,7 @@ *.o -*.a +*.a.xyzzy *.lo -*.so -*.so.* +*.so.xyzzy /config.mak /src/include/s6-linux-utils/config.h /rngseed diff --git a/package/deps.mak b/package/deps.mak index 3150147..0dac63f 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -2,44 +2,53 @@ # This file has been generated by tools/gen-deps.sh # -src/minutils/rngseed.o src/minutils/rngseed.lo: src/minutils/rngseed.c src/include/s6-linux-utils/config.h -src/minutils/s6-chroot.o src/minutils/s6-chroot.lo: src/minutils/s6-chroot.c -src/minutils/s6-freeramdisk.o src/minutils/s6-freeramdisk.lo: src/minutils/s6-freeramdisk.c -src/minutils/s6-hostname.o src/minutils/s6-hostname.lo: src/minutils/s6-hostname.c -src/minutils/s6-logwatch.o src/minutils/s6-logwatch.lo: src/minutils/s6-logwatch.c -src/minutils/s6-mount.o src/minutils/s6-mount.lo: src/minutils/s6-mount.c src/minutils/mount-constants.h -src/minutils/s6-pivotchroot.o src/minutils/s6-pivotchroot.lo: src/minutils/s6-pivotchroot.c -src/minutils/s6-ps.o src/minutils/s6-ps.lo: src/minutils/s6-ps.c src/minutils/s6-ps.h -src/minutils/s6-swapoff.o src/minutils/s6-swapoff.lo: src/minutils/s6-swapoff.c -src/minutils/s6-swapon.o src/minutils/s6-swapon.lo: src/minutils/s6-swapon.c -src/minutils/s6-umount.o src/minutils/s6-umount.lo: src/minutils/s6-umount.c -src/minutils/s6ps_grcache.o src/minutils/s6ps_grcache.lo: src/minutils/s6ps_grcache.c src/minutils/s6-ps.h -src/minutils/s6ps_otree.o src/minutils/s6ps_otree.lo: src/minutils/s6ps_otree.c src/minutils/s6-ps.h -src/minutils/s6ps_pfield.o src/minutils/s6ps_pfield.lo: src/minutils/s6ps_pfield.c src/minutils/s6-ps.h -src/minutils/s6ps_pwcache.o src/minutils/s6ps_pwcache.lo: src/minutils/s6ps_pwcache.c src/minutils/s6-ps.h -src/minutils/s6ps_statparse.o src/minutils/s6ps_statparse.lo: src/minutils/s6ps_statparse.c src/minutils/s6-ps.h -src/minutils/s6ps_ttycache.o src/minutils/s6ps_ttycache.lo: src/minutils/s6ps_ttycache.c src/minutils/s6-ps.h -src/minutils/s6ps_wchan.o src/minutils/s6ps_wchan.lo: src/minutils/s6ps_wchan.c src/minutils/s6-ps.h +src/libps/s6ps_grcache.o src/libps/s6ps_grcache.lo: src/libps/s6ps_grcache.c src/include-local/s6-ps.h +src/libps/s6ps_otree.o src/libps/s6ps_otree.lo: src/libps/s6ps_otree.c src/include-local/s6-ps.h +src/libps/s6ps_pfield.o src/libps/s6ps_pfield.lo: src/libps/s6ps_pfield.c src/include-local/s6-ps.h +src/libps/s6ps_pwcache.o src/libps/s6ps_pwcache.lo: src/libps/s6ps_pwcache.c src/include-local/s6-ps.h +src/libps/s6ps_statparse.o src/libps/s6ps_statparse.lo: src/libps/s6ps_statparse.c src/include-local/s6-ps.h +src/libps/s6ps_ttycache.o src/libps/s6ps_ttycache.lo: src/libps/s6ps_ttycache.c src/include-local/s6-ps.h +src/libps/s6ps_wchan.o src/libps/s6ps_wchan.lo: src/libps/s6ps_wchan.c src/include-local/s6-ps.h +src/s6-linux-utils/rngseed.o src/s6-linux-utils/rngseed.lo: src/s6-linux-utils/rngseed.c src/include/s6-linux-utils/config.h +src/s6-linux-utils/s6-chroot.o src/s6-linux-utils/s6-chroot.lo: src/s6-linux-utils/s6-chroot.c +src/s6-linux-utils/s6-freeramdisk.o src/s6-linux-utils/s6-freeramdisk.lo: src/s6-linux-utils/s6-freeramdisk.c +src/s6-linux-utils/s6-hostname.o src/s6-linux-utils/s6-hostname.lo: src/s6-linux-utils/s6-hostname.c +src/s6-linux-utils/s6-logwatch.o src/s6-linux-utils/s6-logwatch.lo: src/s6-linux-utils/s6-logwatch.c +src/s6-linux-utils/s6-mount.o src/s6-linux-utils/s6-mount.lo: src/s6-linux-utils/s6-mount.c src/include-local/mount-constants.h +src/s6-linux-utils/s6-pivotchroot.o src/s6-linux-utils/s6-pivotchroot.lo: src/s6-linux-utils/s6-pivotchroot.c +src/s6-linux-utils/s6-ps.o src/s6-linux-utils/s6-ps.lo: src/s6-linux-utils/s6-ps.c src/include-local/s6-ps.h +src/s6-linux-utils/s6-swapoff.o src/s6-linux-utils/s6-swapoff.lo: src/s6-linux-utils/s6-swapoff.c +src/s6-linux-utils/s6-swapon.o src/s6-linux-utils/s6-swapon.lo: src/s6-linux-utils/s6-swapon.c +src/s6-linux-utils/s6-umount.o src/s6-linux-utils/s6-umount.lo: src/s6-linux-utils/s6-umount.c +ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) +libs6ps.a.xyzzy: src/libps/s6ps_grcache.o src/libps/s6ps_otree.o src/libps/s6ps_pfield.o src/libps/s6ps_pwcache.o src/libps/s6ps_statparse.o src/libps/s6ps_ttycache.o src/libps/s6ps_wchan.o +else +libs6ps.a.xyzzy: src/libps/s6ps_grcache.lo src/libps/s6ps_otree.lo src/libps/s6ps_pfield.lo src/libps/s6ps_pwcache.lo src/libps/s6ps_statparse.lo src/libps/s6ps_ttycache.lo src/libps/s6ps_wchan.lo +endif +libs6ps.so.xyzzy: EXTRA_LIBS := +libs6ps.so.xyzzy: src/libps/s6ps_grcache.lo src/libps/s6ps_otree.lo src/libps/s6ps_pfield.lo src/libps/s6ps_pwcache.lo src/libps/s6ps_statparse.lo src/libps/s6ps_ttycache.lo src/libps/s6ps_wchan.lo +s6-linux-utils: EXTRA_LIBS := -lskarnet ${SYSCLOCK_LIB} ${MAYBEPTHREAD_LIB} +s6-linux-utils: src/multicall/s6-linux-utils.o libs6ps.a.xyzzy ${LIBNSSS} rngseed: EXTRA_LIBS := -lskarnet ${SYSCLOCK_LIB} -rngseed: src/minutils/rngseed.o +rngseed: src/s6-linux-utils/rngseed.o s6-chroot: EXTRA_LIBS := -lskarnet -s6-chroot: src/minutils/s6-chroot.o +s6-chroot: src/s6-linux-utils/s6-chroot.o s6-freeramdisk: EXTRA_LIBS := -lskarnet -s6-freeramdisk: src/minutils/s6-freeramdisk.o +s6-freeramdisk: src/s6-linux-utils/s6-freeramdisk.o s6-hostname: EXTRA_LIBS := -lskarnet -s6-hostname: src/minutils/s6-hostname.o +s6-hostname: src/s6-linux-utils/s6-hostname.o s6-logwatch: EXTRA_LIBS := -lskarnet -s6-logwatch: src/minutils/s6-logwatch.o +s6-logwatch: src/s6-linux-utils/s6-logwatch.o s6-mount: EXTRA_LIBS := -lskarnet -s6-mount: src/minutils/s6-mount.o +s6-mount: src/s6-linux-utils/s6-mount.o s6-pivotchroot: EXTRA_LIBS := -lskarnet -s6-pivotchroot: src/minutils/s6-pivotchroot.o +s6-pivotchroot: src/s6-linux-utils/s6-pivotchroot.o s6-ps: EXTRA_LIBS := -lskarnet ${MAYBEPTHREAD_LIB} -s6-ps: src/minutils/s6-ps.o src/minutils/s6ps_statparse.o src/minutils/s6ps_otree.o src/minutils/s6ps_pfield.o src/minutils/s6ps_pwcache.o src/minutils/s6ps_grcache.o src/minutils/s6ps_ttycache.o src/minutils/s6ps_wchan.o ${LIBNSSS} +s6-ps: src/s6-linux-utils/s6-ps.o libs6ps.a.xyzzy ${LIBNSSS} s6-swapoff: EXTRA_LIBS := -lskarnet -s6-swapoff: src/minutils/s6-swapoff.o +s6-swapoff: src/s6-linux-utils/s6-swapoff.o s6-swapon: EXTRA_LIBS := -lskarnet -s6-swapon: src/minutils/s6-swapon.o +s6-swapon: src/s6-linux-utils/s6-swapon.o s6-umount: EXTRA_LIBS := -lskarnet -s6-umount: src/minutils/s6-umount.o +s6-umount: src/s6-linux-utils/s6-umount.o diff --git a/package/targets.mak b/package/targets.mak index f42cb5a..fb7af4c 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -12,4 +12,3 @@ s6-swapon \ s6-umount LIBEXEC_TARGETS := - diff --git a/src/minutils/mount-constants.h b/src/include-local/mount-constants.h index 1e6f3c0..3b30035 100644 --- a/src/minutils/mount-constants.h +++ b/src/include-local/mount-constants.h @@ -3,7 +3,7 @@ #ifndef MOUNT_CONSTANTS_H #define MOUNT_CONSTANTS_H -/* taken from util-linux-ng */ +/* taken from util-linux */ #ifndef MS_RDONLY #define MS_RDONLY 1 /* Mount read-only */ @@ -29,6 +29,9 @@ #ifndef MS_DIRSYNC #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ #endif +#ifndef MS_NOSYMFOLLOW +#define MS_NOSYMFOLLOW 256 /* Don't follow symlinks */ +#endif #ifndef MS_NOATIME #define MS_NOATIME 0x400 /* 1024: Do not update access times. */ #endif @@ -44,38 +47,32 @@ #ifndef MS_REC #define MS_REC 0x4000 /* 16384: Recursive loopback */ #endif -#ifndef MS_VERBOSE -#define MS_VERBOSE 0x8000 /* 32768 */ -#endif -#ifndef MS_RELATIME -#define MS_RELATIME 0x200000 /* 200000: Update access times relative to mtime/ctime */ +#ifndef MS_SILENT +#define MS_SILENT 0x8000 /* 32768: Don't emit certain kernel messages */ #endif #ifndef MS_UNBINDABLE -#define MS_UNBINDABLE (1<<17) /* 131072 unbindable */ +#define MS_UNBINDABLE (1<<17) /* 131072: Make unbindable */ #endif #ifndef MS_PRIVATE -#define MS_PRIVATE (1<<18) /* 262144 Private */ +#define MS_PRIVATE (1<<18) /* 262144: Make private */ #endif #ifndef MS_SLAVE -#define MS_SLAVE (1<<19) /* 524288 Slave */ +#define MS_SLAVE (1<<19) /* 524288: Make slave */ #endif #ifndef MS_SHARED -#define MS_SHARED (1<<20) /* 1048576 Shared */ +#define MS_SHARED (1<<20) /* 1048576: Make shared */ +#endif +#ifndef MS_RELATIME +#define MS_RELATIME (1<<21) /* 2097152: Update atime relative to mtime/ctime */ #endif #ifndef MS_I_VERSION -#define MS_I_VERSION (1<<23) /* update inode I_version field */ +#define MS_I_VERSION (1<<23) /* Update the inode I_version field */ #endif #ifndef MS_STRICTATIME -#define MS_STRICTATIME (1<<24) /* strict atime semantics */ -#endif -/* - * Magic mount flag number. Had to be or-ed to the flag values. - */ -#ifndef MS_MGC_VAL -#define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */ +#define MS_STRICTATIME (1<<24) /* Always perform atime updates */ #endif -#ifndef MS_MGC_MSK -#define MS_MGC_MSK 0xffff0000 /* magic flag number mask */ +#ifndef MS_LAZYTIME +#define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */ #endif #endif diff --git a/src/minutils/s6-ps.h b/src/include-local/s6-ps.h index eb56dc1..7c963f1 100644 --- a/src/minutils/s6-ps.h +++ b/src/include-local/s6-ps.h @@ -1,10 +1,11 @@ /* ISC license. */ -#ifndef _S6PS_H_ -#define _S6PS_H_ +#ifndef S6PS_H +#define S6PS_H #include <sys/types.h> #include <stdint.h> + #include <skalibs/uint64.h> #include <skalibs/stralloc.h> #include <skalibs/tai.h> @@ -19,9 +20,6 @@ struct dius_s } ; #define DIUS_ZERO { .left = 0, .right = 0 } - - /* pfield: the output fields */ - typedef enum pfield_e pfield_t, *pfield_t_ref ; enum pfield_e { @@ -64,8 +62,6 @@ enum pfield_e extern char const *const *s6ps_opttable ; extern char const *const *s6ps_fieldheaders ; - /* pscan: the main structure */ - typedef struct pscan_s pscan_t, *pscan_t_ref ; struct pscan_s { diff --git a/src/minutils/deps-exe/s6-ps b/src/libps/deps-lib/s6ps index 1f0adc5..0f078a6 100644 --- a/src/minutils/deps-exe/s6-ps +++ b/src/libps/deps-lib/s6ps @@ -1,10 +1,7 @@ -s6ps_statparse.o +s6ps_grcache.o s6ps_otree.o s6ps_pfield.o s6ps_pwcache.o -s6ps_grcache.o +s6ps_statparse.o s6ps_ttycache.o s6ps_wchan.o -${LIBNSSS} --lskarnet -${MAYBEPTHREAD_LIB} diff --git a/src/minutils/s6ps_grcache.c b/src/libps/s6ps_grcache.c index ba62098..189f5ae 100644 --- a/src/minutils/s6ps_grcache.c +++ b/src/libps/s6ps_grcache.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <stdint.h> + #include <grp.h> #include <errno.h> #include <skalibs/types.h> @@ -8,6 +9,7 @@ #include <skalibs/genalloc.h> #include <skalibs/skamisc.h> #include <skalibs/avltree.h> + #include "s6-ps.h" static avltree grcache_tree = AVLTREE_ZERO ; diff --git a/src/minutils/s6ps_otree.c b/src/libps/s6ps_otree.c index f7952ab..6ba8589 100644 --- a/src/minutils/s6ps_otree.c +++ b/src/libps/s6ps_otree.c @@ -1,7 +1,9 @@ /* ISC license. */ #include <errno.h> + #include <skalibs/avltreen.h> + #include "s6-ps.h" typedef struct ptreeiter_s ptreeiter_t, *ptreeiter_t_ref ; diff --git a/src/minutils/s6ps_pfield.c b/src/libps/s6ps_pfield.c index 0280186..9e53e50 100644 --- a/src/minutils/s6ps_pfield.c +++ b/src/libps/s6ps_pfield.c @@ -5,12 +5,14 @@ #include <unistd.h> #include <time.h> #include <sys/sysinfo.h> + #include <skalibs/uint64.h> #include <skalibs/types.h> #include <skalibs/strerr.h> #include <skalibs/tai.h> #include <skalibs/djbtime.h> #include <skalibs/stralloc.h> + #include "s6-ps.h" static char const *const fieldheaders[PFIELD_PHAIL] = @@ -492,7 +494,6 @@ static int fmt_pcpu (pscan_t *p, size_t *pos, size_t *len) return percent(&p->data, 10000 * (p->utime + p->stime) / gettotalj(p->start), pos, len) ; } - static int fmt_ttime (pscan_t *p, size_t *pos, size_t *len) { return fmt_jiffies(p, pos, len, p->utime + p->stime) ; diff --git a/src/minutils/s6ps_pwcache.c b/src/libps/s6ps_pwcache.c index 283a393..ce4caa8 100644 --- a/src/minutils/s6ps_pwcache.c +++ b/src/libps/s6ps_pwcache.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <pwd.h> #include <errno.h> + #include <skalibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> diff --git a/src/minutils/s6ps_statparse.c b/src/libps/s6ps_statparse.c index fe4c355..ea46d70 100644 --- a/src/minutils/s6ps_statparse.c +++ b/src/libps/s6ps_statparse.c @@ -3,10 +3,12 @@ #include <stdint.h> #include <sys/types.h> #include <errno.h> + #include <skalibs/uint64.h> #include <skalibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/tai.h> + #include "s6-ps.h" @@ -17,8 +19,8 @@ #define STATVARS 49 -typedef size_t sca$1_func (char const *, void *) ; -typedef sca$1_func *sca$1_func_ref ; +typedef size_t pscan_func (char const *, void *) ; +typedef pscan_func *pscan_func_ref ; static size_t f64 (char const *s, void *u64) { @@ -48,7 +50,7 @@ DEFUNS(fint, int) DEFUNS(fpid, pid_t) DEFUNU(fdev, dev_t) -static sca$1_func_ref scanfuncs[STATVARS] = +static pscan_func_ref scanfuncs[STATVARS] = { &fpid, /* ppid */ &fpid, /* pgrp */ diff --git a/src/minutils/s6ps_ttycache.c b/src/libps/s6ps_ttycache.c index 0608967..27282e7 100644 --- a/src/minutils/s6ps_ttycache.c +++ b/src/libps/s6ps_ttycache.c @@ -5,6 +5,7 @@ #include <sys/stat.h> #include <sys/sysmacros.h> #include <errno.h> + #include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> @@ -13,6 +14,7 @@ #include <skalibs/djbunix.h> #include <skalibs/skamisc.h> #include <skalibs/avltree.h> + #include "s6-ps.h" static avltree ttycache_tree = AVLTREE_ZERO ; diff --git a/src/minutils/s6ps_wchan.c b/src/libps/s6ps_wchan.c index 209e1ef..9261693 100644 --- a/src/minutils/s6ps_wchan.c +++ b/src/libps/s6ps_wchan.c @@ -2,10 +2,12 @@ #include <string.h> #include <sys/utsname.h> + #include <skalibs/uint64.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> + #include "s6-ps.h" static stralloc sysmap = STRALLOC_ZERO ; diff --git a/src/minutils/s6-mount.c b/src/minutils/s6-mount.c deleted file mode 100644 index 428bda4..0000000 --- a/src/minutils/s6-mount.c +++ /dev/null @@ -1,149 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> -#include <sys/mount.h> -#include <mntent.h> -#include <stdio.h> -#include <skalibs/bytestr.h> -#include <skalibs/sgetopt.h> -#include <skalibs/strerr.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> -#include "mount-constants.h" - -#define USAGE "s6-mount -a [ -z fstab ] | s6-mount [ -n ] [ -t type ] [ -o option[,option...] ]... device mountpoint" -#define BUFSIZE 4096 - -#define SWITCH(opt) do -#define HCTIWS(opt) while(0) ; -#define CASE(s) if (n == sizeof(s) - 1 && !strncmp(opt, (s), n)) - -static void scanopt (stralloc *data, unsigned long *flags, char const *opt) -{ - for (;;) - { - unsigned int n = str_chr(opt, ',') ; - SWITCH(opt) - { - CASE("defaults") { *flags = MS_MGC_VAL ; break ; } - CASE("ro") { *flags |= MS_RDONLY ; break ; } - CASE("rw") { *flags &= ~MS_RDONLY ; break ; } - CASE("remount") { *flags |= MS_REMOUNT ; break ; } - CASE("sync") { *flags |= MS_SYNCHRONOUS ; break ; } - CASE("async") { *flags &= ~MS_SYNCHRONOUS ; break ; } - CASE("nodev") { *flags |= MS_NODEV ; break ; } - CASE("dev") { *flags &= ~MS_NODEV ; break ; } - CASE("noexec") { *flags |= MS_NOEXEC ; break ; } - CASE("exec") { *flags &= ~MS_NOEXEC ; break ; } - CASE("nosuid") { *flags |= MS_NOSUID ; break ; } - CASE("suid") { *flags &= ~MS_NOSUID ; break ; } - CASE("noatime") { *flags |= MS_NOATIME ; break ; } - CASE("atime") { *flags &= ~MS_NOATIME ; break ; } - CASE("nodiratime") { *flags |= MS_NODIRATIME ; break ; } - CASE("diratime") { *flags &= ~MS_NODIRATIME ; break ; } - CASE("strictatime") { *flags |= MS_STRICTATIME ; break ; } - CASE("nostrictatime") { *flags &= ~MS_STRICTATIME ; break ; } - CASE("relatime") { *flags |= MS_RELATIME ; break ; } - CASE("norelatime") { *flags &= ~MS_RELATIME ; break ; } - CASE("bind") { *flags |= MS_BIND ; break ; } - CASE("nobind") { *flags &= ~MS_BIND ; break ; } - CASE("move") { *flags |= MS_MOVE ; break ; } - CASE("nomove") { *flags &= ~MS_MOVE ; break ; } - CASE("dirsync") { *flags |= MS_DIRSYNC ; break ; } - CASE("nodirsync") { *flags &= ~MS_DIRSYNC ; break ; } - CASE("mandlock") { *flags |= MS_MANDLOCK ; break ; } - CASE("nomandlock") { *flags &= ~MS_MANDLOCK ; break ; } - CASE("silent") { *flags |= MS_SILENT ; break ; } - CASE("nosilent") { *flags &= ~MS_SILENT ; break ; } -#ifdef MS_LAZYTIME - CASE("lazytime") { *flags |= MS_LAZYTIME ; break ; } - CASE("nolazytime") { *flags &= ~MS_LAZYTIME ; break ; } -#endif - - CASE("shared") { *flags &= ~(MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE) ; *flags |= MS_SHARED ; break ; } - CASE("private") { *flags &= ~(MS_SHARED | MS_SLAVE | MS_UNBINDABLE) ; *flags |= MS_PRIVATE ; break ; } - CASE("slave") { *flags &= ~(MS_SHARED | MS_PRIVATE | MS_UNBINDABLE) ; *flags |= MS_SLAVE ; break ; } - CASE("unbindable") { *flags &= ~(MS_SHARED | MS_PRIVATE | MS_SLAVE) ; *flags |= MS_UNBINDABLE ; break ; } - - if ((data->s && data->len && !stralloc_catb(data, ",", 1)) || !stralloc_catb(data, opt, n)) - strerr_diefu1sys(111, "build data string") ; - } - HCTIWS(opt) - - opt += n ; - if (!*opt) break ; - if (*opt != ',') strerr_dief1x(100, "unrecognized option") ; - opt++ ; - } -} - -static int mountall (char const *fstab) -{ - struct mntent *d ; - int e = 0 ; - FILE *yuck = setmntent(fstab, "r") ; - if (!yuck) strerr_diefu2sys(111, "open ", fstab) ; - while ((d = getmntent(yuck))) - { - unsigned long flags = MS_MGC_VAL ; - stralloc data = STRALLOC_ZERO ; - scanopt(&data, &flags, d->mnt_opts) ; - if (!stralloc_0(&data)) - strerr_diefu1sys(111, "build data string") ; -#ifdef DEBUG - strerr_warni4x("mounting ", d->mnt_fsname, " on ", d->mnt_dir) ; -#endif - if (mount(d->mnt_fsname, d->mnt_dir, d->mnt_type, flags, data.s) == -1) - { - e++ ; - strerr_warnwu4sys("mount ", d->mnt_fsname, " on ", d->mnt_dir) ; - } - stralloc_free(&data) ; - } - endmntent(yuck) ; - return e ; -} - -int main (int argc, char const *const *argv) -{ - stralloc data = STRALLOC_ZERO ; - unsigned long flags = MS_MGC_VAL ; - char const *fstype = "none" ; - char const *fstab = "/etc/fstab" ; - PROG = "s6-mount" ; - { - int doall = 0 ; - subgetopt l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "nz:arwt:o:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'n' : break ; - case 'z' : fstab = l.arg ; break ; - case 'a' : doall = 1 ; break ; - case 't' : fstype = l.arg ; break ; - case 'w' : scanopt(&data, &flags, "rw") ; break ; - case 'r' : scanopt(&data, &flags, "ro") ; break ; - case 'o' : scanopt(&data, &flags, l.arg) ; break ; - default : strerr_dieusage(100, USAGE) ; - } - } - argc -= l.ind ; argv += l.ind ; - if (doall) return mountall(fstab) ; - } - if (!argc) - { - int fd = open_readb("/proc/mounts") ; - if (fd < 0) strerr_diefu2sys(111, "read ", "/proc/mounts") ; - if (fd_cat(fd, 1) < 0) strerr_diefu2sys(111, "fd_cat ", "/proc/mounts") ; - fd_close(fd) ; - } - else if (argc == 1) strerr_dieusage(100, USAGE) ; - else if (!stralloc_0(&data)) strerr_diefu1sys(111, "build data string") ; - else if (mount(argv[0], argv[1], fstype, flags, data.s) == -1) - strerr_diefu4sys(errno == EBUSY ? 1 : 111, "mount ", argv[0], " on ", argv[1]) ; - return 0 ; -} diff --git a/src/multicall/deps-exe/s6-linux-utils b/src/multicall/deps-exe/s6-linux-utils new file mode 100644 index 0000000..730b277 --- /dev/null +++ b/src/multicall/deps-exe/s6-linux-utils @@ -0,0 +1,5 @@ +libs6ps.a.xyzzy +${LIBNSSS} +-lskarnet +${SYSCLOCK_LIB} +${MAYBEPTHREAD_LIB} diff --git a/src/minutils/deps-exe/rngseed b/src/s6-linux-utils/deps-exe/rngseed index a11a5f4..a11a5f4 100644 --- a/src/minutils/deps-exe/rngseed +++ b/src/s6-linux-utils/deps-exe/rngseed diff --git a/src/minutils/deps-exe/s6-chroot b/src/s6-linux-utils/deps-exe/s6-chroot index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-chroot +++ b/src/s6-linux-utils/deps-exe/s6-chroot diff --git a/src/minutils/deps-exe/s6-freeramdisk b/src/s6-linux-utils/deps-exe/s6-freeramdisk index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-freeramdisk +++ b/src/s6-linux-utils/deps-exe/s6-freeramdisk diff --git a/src/minutils/deps-exe/s6-hostname b/src/s6-linux-utils/deps-exe/s6-hostname index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-hostname +++ b/src/s6-linux-utils/deps-exe/s6-hostname diff --git a/src/minutils/deps-exe/s6-logwatch b/src/s6-linux-utils/deps-exe/s6-logwatch index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-logwatch +++ b/src/s6-linux-utils/deps-exe/s6-logwatch diff --git a/src/minutils/deps-exe/s6-mount b/src/s6-linux-utils/deps-exe/s6-mount index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-mount +++ b/src/s6-linux-utils/deps-exe/s6-mount diff --git a/src/minutils/deps-exe/s6-pivotchroot b/src/s6-linux-utils/deps-exe/s6-pivotchroot index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-pivotchroot +++ b/src/s6-linux-utils/deps-exe/s6-pivotchroot diff --git a/src/s6-linux-utils/deps-exe/s6-ps b/src/s6-linux-utils/deps-exe/s6-ps new file mode 100644 index 0000000..ee390f1 --- /dev/null +++ b/src/s6-linux-utils/deps-exe/s6-ps @@ -0,0 +1,4 @@ +libs6ps.a.xyzzy +${LIBNSSS} +-lskarnet +${MAYBEPTHREAD_LIB} diff --git a/src/minutils/deps-exe/s6-swapoff b/src/s6-linux-utils/deps-exe/s6-swapoff index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-swapoff +++ b/src/s6-linux-utils/deps-exe/s6-swapoff diff --git a/src/minutils/deps-exe/s6-swapon b/src/s6-linux-utils/deps-exe/s6-swapon index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-swapon +++ b/src/s6-linux-utils/deps-exe/s6-swapon diff --git a/src/minutils/deps-exe/s6-umount b/src/s6-linux-utils/deps-exe/s6-umount index e7187fe..e7187fe 100644 --- a/src/minutils/deps-exe/s6-umount +++ b/src/s6-linux-utils/deps-exe/s6-umount diff --git a/src/minutils/rngseed.c b/src/s6-linux-utils/rngseed.c index bc16bbb..2b1772c 100644 --- a/src/minutils/rngseed.c +++ b/src/s6-linux-utils/rngseed.c @@ -31,10 +31,9 @@ #define USAGE "rngseed [ -d seeddir ] [ -v verbosity ] [ -r | -R ] [ -n | -N ] [ -w | -W ]" #define dieusage() strerr_dieusage(100, USAGE) -#define HASH_PREFIX "SeedRNG v1 Old+New Prefix" -#define HASH_FALLBACK "SeedRNG v1 No New Seed Failure" +#define RNGSEED_HASH_PREFIX "SeedRNG v1 Old+New Prefix" -struct flags_s +struct rngseed_flags_s { unsigned int read: 1 ; unsigned int rcred: 1 ; @@ -42,7 +41,7 @@ struct flags_s unsigned int write: 1 ; unsigned int wcred: 1 ; } ; -#define FLAGS_ZERO { .read = 0, .rcred = 1, .block = 1, .write = 0, .wcred = 1 } +#define RNGSEED_FLAGS_ZERO { .read = 0, .rcred = 1, .block = 1, .write = 0, .wcred = 1 } struct randpoolinfo_s { @@ -51,9 +50,7 @@ struct randpoolinfo_s char buffer[512] ; } ; -static unsigned int verbosity = 1 ; - -static inline void mkdirp (char *s, size_t len) +static inline void rngseed_mkdirp (char *s, size_t len) { mode_t m = umask(0) ; size_t i = 1 ; @@ -67,7 +64,7 @@ static inline void mkdirp (char *s, size_t len) umask(m) ; } -static inline int read_seed_nb (char *s, size_t len) +static inline int rngseed_read_seed_nb (char *s, size_t len) { int wcred ; size_t w = 0 ; @@ -102,7 +99,8 @@ int main (int argc, char const *const *argv) { blake2s_ctx ctx = BLAKE2S_INIT(32) ; char const *seeddir = RNGSEED_DIR ; - struct flags_s flags = FLAGS_ZERO ; + struct rngseed_flags_s flags = RNGSEED_FLAGS_ZERO ; + unsigned int verbosity = 1 ; PROG = "rngseed" ; { subgetopt l = SUBGETOPT_ZERO ; @@ -139,7 +137,7 @@ int main (int argc, char const *const *argv) if (dirlen) { file[dirlen] = 0 ; - mkdirp(file, dirlen) ; + rngseed_mkdirp(file, dirlen) ; if (mkdir(file, 0700) == -1) { struct stat st ; @@ -156,7 +154,7 @@ int main (int argc, char const *const *argv) } file[dirlen] = '/' ; } - blake2s_update(&ctx, HASH_PREFIX, sizeof(HASH_PREFIX) - 1) ; + blake2s_update(&ctx, RNGSEED_HASH_PREFIX, sizeof(RNGSEED_HASH_PREFIX) - 1) ; clock_gettime(CLOCK_REALTIME, &ts) ; blake2s_update(&ctx, (char *)&ts, sizeof ts) ; clock_gettime(CLOCK_BOOTTIME, &ts) ; @@ -258,7 +256,7 @@ int main (int argc, char const *const *argv) strerr_warni3x("reading ", s, " bits of random to make the seed") ; } if (flags.block) random_buf(seed, len) ; - else wcred = read_seed_nb(seed, len) ; + else wcred = rngseed_read_seed_nb(seed, len) ; if (!wcred && verbosity) strerr_warnwu1x("make the seed creditable") ; blake2s_update(&ctx, (char *)&len, sizeof(len)) ; blake2s_update(&ctx, seed, len) ; diff --git a/src/minutils/s6-chroot.c b/src/s6-linux-utils/s6-chroot.c index ae1fb7b..ae1fb7b 100644 --- a/src/minutils/s6-chroot.c +++ b/src/s6-linux-utils/s6-chroot.c diff --git a/src/minutils/s6-freeramdisk.c b/src/s6-linux-utils/s6-freeramdisk.c index adfb07c..b965527 100644 --- a/src/minutils/s6-freeramdisk.c +++ b/src/s6-linux-utils/s6-freeramdisk.c @@ -5,6 +5,7 @@ #include <fcntl.h> #include <sys/mount.h> #include <sys/ioctl.h> + #include <skalibs/strerr.h> #define USAGE "s6-freeramdisk ramdisk_device" diff --git a/src/minutils/s6-hostname.c b/src/s6-linux-utils/s6-hostname.c index d673e81..f2138cf 100644 --- a/src/minutils/s6-hostname.c +++ b/src/s6-linux-utils/s6-hostname.c @@ -1,11 +1,10 @@ /* ISC license. */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif +#include <skalibs/nonposix.h> #include <unistd.h> #include <string.h> + #include <skalibs/allreadwrite.h> #include <skalibs/strerr.h> #include <skalibs/stralloc.h> @@ -13,7 +12,7 @@ #define USAGE "s6-hostname [ hostname ]" -static int getit (void) +static int hostname_getit (void) { stralloc sa = STRALLOC_ZERO ; if (sagethostname(&sa) < 0) strerr_diefu1sys(111, "get hostname") ; @@ -23,7 +22,7 @@ static int getit (void) return 0 ; } -static int setit (char const *h) +static int hostname_setit (char const *h) { if (sethostname(h, strlen(h)) < 0) strerr_diefu1sys(111, "set hostname") ; @@ -33,5 +32,5 @@ static int setit (char const *h) int main (int argc, char const *const *argv) { PROG = "s6-hostname" ; - return (argc < 2) ? getit() : setit(argv[1]) ; + return (argc < 2) ? hostname_getit() : hostname_setit(argv[1]) ; } diff --git a/src/minutils/s6-logwatch.c b/src/s6-linux-utils/s6-logwatch.c index e815f81..7240c5e 100644 --- a/src/minutils/s6-logwatch.c +++ b/src/s6-linux-utils/s6-logwatch.c @@ -7,6 +7,7 @@ #include <unistd.h> #include <signal.h> #include <sys/inotify.h> + #include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/sgetopt.h> @@ -20,12 +21,9 @@ #define USAGE "s6-logwatch [ logdir ]" #define dieusage() strerr_dieusage(100, USAGE) -#define B_READING 0 -#define B_BLOCKING 1 -#define B_WAITING 2 -static unsigned int state ; -static int fd ; -static int newcurrent = 0 ; +#define LOGWATCH_READING 0 +#define LOGWATCH_BLOCKING 1 +#define LOGWATCH_WAITING 2 union inotify_event_u { @@ -33,54 +31,54 @@ union inotify_event_u char buf[sizeof(struct inotify_event) + NAME_MAX + 1] ; } ; -static void goteof (void) +static inline void logwatch_goteof (int *fd, unsigned int *state, int *newcurrent) { - if (newcurrent) + if (*newcurrent) { - fd_close(fd) ; - fd = open_read("current") ; - if (fd < 0) strerr_diefu1sys(111, "current") ; - newcurrent = 0 ; - state = B_READING ; + fd_close(*fd) ; + *fd = open_read("current") ; + if (*fd < 0) strerr_diefu1sys(111, "current") ; + *newcurrent = 0 ; + *state = LOGWATCH_READING ; } - else state = B_BLOCKING ; + else *state = LOGWATCH_BLOCKING ; } -static int readit (int fd) +static int logwatch_readit (int *fd, unsigned int *state, int *newcurrent) { struct iovec v[2] ; ssize_t r ; buffer_wpeek(buffer_1, v) ; - r = fd_readv(fd, v, 2) ; + r = fd_readv(*fd, v, 2) ; switch (r) { case -1 : return 0 ; - case 0 : goteof() ; break ; + case 0 : logwatch_goteof(fd, state, newcurrent) ; break ; default : buffer_wseek(buffer_1, r) ; } return 1 ; } -static void maketransition (unsigned int transition) +static inline void logwatch_maketransition (unsigned int transition, int *fd, unsigned int *state, int *newcurrent) { static unsigned char const table[3][3] = { { 0x10, 0x00, 0x00 }, { 0x60, 0x22, 0x00 }, { 0x40, 0x03, 0x02 } } ; - unsigned char c = table[state][transition] ; - state = c & 0x0f ; - if (state == 3) strerr_dief1x(101, "current moved twice without being recreated") ; - if (c & 0x10) newcurrent = 1 ; - if (c & 0x20) { fd_close(fd) ; fd = -1 ; } + unsigned char c = table[*state][transition] ; + *state = c & 0x0f ; + if (*state == 3) strerr_dief1x(101, "current moved twice without being recreated") ; + if (c & 0x10) *newcurrent = 1 ; + if (c & 0x20) { fd_close(*fd) ; *fd = -1 ; } if (c & 0x40) { - fd = open_read("current") ; - if (fd < 0) strerr_diefu1sys(111, "current") ; + *fd = open_read("current") ; + if (*fd < 0) strerr_diefu1sys(111, "current") ; } } -static void handle_event (int ifd, int watch) +static void logwatch_handle_event (int ifd, int watch, int *fd, unsigned int *state, int *newcurrent) { ssize_t r ; size_t offset = 0 ; @@ -97,7 +95,7 @@ static void handle_event (int ifd, int watch) if (event->mask & IN_CREATE) transition = 0 ; else if (event->mask & IN_MOVED_FROM) transition = 1 ; else if (event->mask & IN_MODIFY) transition = 2 ; - if (transition >= 0) maketransition(transition) ; + if (transition >= 0) logwatch_maketransition(transition, fd, state, newcurrent) ; } } } @@ -107,6 +105,9 @@ int main (int argc, char const *const *argv) iopause_fd x[2] = { { .events = IOPAUSE_READ }, { .fd = 1 } } ; char const *dir = "." ; int watch ; + int fd ; + unsigned int state ; + int newcurrent = 0 ; unsigned int maxlen = 4096 ; PROG = "s6-logwatch" ; { @@ -139,13 +140,13 @@ int main (int argc, char const *const *argv) if (fd < 0) { if (errno != ENOENT) strerr_diefu3sys(111, "open ", dir, "/current") ; - state = B_WAITING ; + state = LOGWATCH_WAITING ; } - else state = B_READING ; + else state = LOGWATCH_READING ; if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "sig_ignore(SIGPIPE)") ; - if (state == B_READING) + if (state == LOGWATCH_READING) { - if (!readit(fd)) strerr_diefu3sys(111, "read from ", dir, "/current") ; + if (!logwatch_readit(&fd, &state, &newcurrent)) strerr_diefu3sys(111, "read from ", dir, "/current") ; } for (;;) @@ -162,11 +163,11 @@ int main (int argc, char const *const *argv) strerr_diefu1sys(111, "write to stdout") ; if (x[1].revents & IOPAUSE_EXCEPT) break ; } - if (state == B_READING && buffer_available(buffer_1)) + if (state == LOGWATCH_READING && buffer_available(buffer_1)) { - if (!readit(fd)) strerr_diefu3sys(111, "read from ", dir, "/current") ; + if (!logwatch_readit(&fd, &state, &newcurrent)) strerr_diefu3sys(111, "read from ", dir, "/current") ; } - if (x[0].revents & IOPAUSE_READ) handle_event(x[0].fd, watch) ; + if (x[0].revents & IOPAUSE_READ) logwatch_handle_event(x[0].fd, watch, &fd, &state, &newcurrent) ; } return 0 ; } diff --git a/src/s6-linux-utils/s6-mount.c b/src/s6-linux-utils/s6-mount.c new file mode 100644 index 0000000..58fc2ff --- /dev/null +++ b/src/s6-linux-utils/s6-mount.c @@ -0,0 +1,166 @@ +/* ISC license. */ + +#include <string.h> +#include <errno.h> +#include <sys/mount.h> +#include <mntent.h> +#include <stdio.h> +#include <stdlib.h> + +#include <skalibs/bytestr.h> +#include <skalibs/sgetopt.h> +#include <skalibs/strerr.h> +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> + +#include "mount-constants.h" + +#define USAGE "s6-mount -a [ -z fstab ] | s6-mount [ -n ] [ -t type ] [ -o option[,option...] ]... device mountpoint" +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") + +struct mount_flag_modif_s +{ + char const *name ; + unsigned long add ; + unsigned long del ; +} ; + +static int mount_flag_cmp (void const *a, void const *b) +{ + char const *key = a ; + struct mount_flag_modif_s const *p = b ; + return strcmp(key, p->name) ; +} + +static void mount_scanopt (stralloc *data, unsigned long *flags, char const *s) +{ + static struct mount_flag_modif_s const mount_flag_modifs[] = + { + { .name = "async", .add = 0, .del = MS_SYNCHRONOUS }, + { .name = "atime", .add = 0, .del = MS_NOATIME }, + { .name = "bind", .add = MS_BIND, .del = 0 }, + { .name = "defaults", .add = 0, .del = MS_RDONLY | MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_SYNCHRONOUS }, + { .name = "dev", .add = 0, .del = MS_NODEV }, + { .name = "diratime", .add = 0, .del = MS_NODIRATIME }, + { .name = "dirsync", .add = MS_DIRSYNC, .del = 0 }, + { .name = "exec", .add = 0, .del = MS_NOEXEC }, + { .name = "lazytime", .add = MS_LAZYTIME, .del = 0 }, + { .name = "loud", .add = 0, .del = MS_SILENT }, + { .name = "mandlock", .add = MS_MANDLOCK, .del = 0 }, + { .name = "move", .add = MS_MOVE, .del = 0 }, + { .name = "noatime", .add = MS_NOATIME, .del = 0 }, + { .name = "nobind", .add = 0, .del = MS_BIND }, + { .name = "nodev", .add = MS_NODEV, .del = 0 }, + { .name = "nodiratime", .add = MS_NODIRATIME, .del = 0 }, + { .name = "nodirsync", .add = 0, .del = MS_DIRSYNC }, + { .name = "nolazytime", .add = 0, .del = MS_LAZYTIME }, + { .name = "noexec", .add = MS_NOEXEC, .del = 0 }, + { .name = "nomandlock", .add = 0, .del = MS_MANDLOCK }, + { .name = "nomove", .add = 0, .del = MS_MOVE }, + { .name = "norelatime", .add = 0, .del = MS_RELATIME }, + { .name = "nostrictatime", .add = 0, .del = MS_STRICTATIME }, + { .name = "nosymfollow", .add = MS_NOSYMFOLLOW, .del = 0 }, + { .name = "nosuid", .add = MS_NOSUID, .del = 0 }, + { .name = "private", .add = MS_PRIVATE, .del = MS_SHARED | MS_SLAVE | MS_UNBINDABLE }, + { .name = "relatime", .add = MS_RELATIME, .del = 0 }, + { .name = "remount", .add = MS_REMOUNT, .del = 0 }, + { .name = "ro", .add = MS_RDONLY, .del = 0 }, + { .name = "rw", .add = 0, .del = MS_RDONLY }, + { .name = "shared", .add = MS_SHARED, .del = MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE }, + { .name = "silent", .add = MS_SILENT, .del = 0 }, + { .name = "slave", .add = MS_SLAVE, .del = MS_SHARED | MS_PRIVATE | MS_UNBINDABLE }, + { .name = "strictatime", .add = MS_STRICTATIME, .del = 0 }, + { .name = "suid", .add = 0, .del = MS_NOSUID }, + { .name = "symfollow", .add = 0, .del = MS_NOSYMFOLLOW }, + { .name = "sync", .add = MS_SYNCHRONOUS, .del = 0 }, + { .name = "unbindable", .add = MS_UNBINDABLE, .del = MS_SHARED | MS_PRIVATE | MS_SLAVE }, + } ; + + while (*s) + { + struct mount_flag_modif_s const *p ; + size_t n = str_chr(s, ',') ; + char opt[n+1] ; + memcpy(opt, s, n) ; + opt[n] = 0 ; + p = bsearch(opt, mount_flag_modifs, sizeof(mount_flag_modifs) / sizeof(struct mount_flag_modif_s), sizeof(struct mount_flag_modif_s), &mount_flag_cmp) ; + if (p) + { + *flags &= ~p->del ; + *flags |= p->add ; + } + else + { + if (data->s && data->len && !stralloc_catb(data, ",", 1)) dienomem() ; + if (!stralloc_catb(data, s, n)) dienomem() ; + } + s += n + (s[n] == ',') ; + } +} + +static int mountall (char const *fstab) +{ + struct mntent *d ; + int e = 0 ; + FILE *yuck = setmntent(fstab, "r") ; + if (!yuck) strerr_diefu2sys(111, "open ", fstab) ; + while ((d = getmntent(yuck))) + { + unsigned long flags = 0 ; + stralloc data = STRALLOC_ZERO ; + mount_scanopt(&data, &flags, d->mnt_opts) ; + if (!stralloc_0(&data)) + strerr_diefu1sys(111, "build data string") ; + if (mount(d->mnt_fsname, d->mnt_dir, d->mnt_type, flags, data.s) == -1) + { + e++ ; + strerr_warnwu4sys("mount ", d->mnt_fsname, " on ", d->mnt_dir) ; + } + stralloc_free(&data) ; + } + endmntent(yuck) ; + return e ; +} + +int main (int argc, char const *const *argv) +{ + stralloc data = STRALLOC_ZERO ; + unsigned long flags = 0 ; + char const *fstype = "none" ; + char const *fstab = "/etc/fstab" ; + PROG = "s6-mount" ; + { + int doall = 0 ; + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "nz:arwt:o:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'n' : break ; + case 'z' : fstab = l.arg ; break ; + case 'a' : doall = 1 ; break ; + case 't' : fstype = l.arg ; break ; + case 'w' : mount_scanopt(&data, &flags, "rw") ; break ; + case 'r' : mount_scanopt(&data, &flags, "ro") ; break ; + case 'o' : mount_scanopt(&data, &flags, l.arg) ; break ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + if (doall) return mountall(fstab) ; + } + if (!argc) + { + int fd = open_readb("/proc/mounts") ; + if (fd < 0) strerr_diefu2sys(111, "read ", "/proc/mounts") ; + if (fd_cat(fd, 1) < 0) strerr_diefu2sys(111, "fd_cat ", "/proc/mounts") ; + fd_close(fd) ; + } + else if (argc == 1) strerr_dieusage(100, USAGE) ; + else if (!stralloc_0(&data)) strerr_diefu1sys(111, "build data string") ; + else if (mount(argv[0], argv[1], fstype, flags, data.s) == -1) + strerr_diefu4sys(errno == EBUSY ? 1 : 111, "mount ", argv[0], " on ", argv[1]) ; + return 0 ; +} diff --git a/src/minutils/s6-pivotchroot.c b/src/s6-linux-utils/s6-pivotchroot.c index b35a00b..b35a00b 100644 --- a/src/minutils/s6-pivotchroot.c +++ b/src/s6-linux-utils/s6-pivotchroot.c diff --git a/src/minutils/s6-ps.c b/src/s6-linux-utils/s6-ps.c index 3363f24..fe4b433 100644 --- a/src/minutils/s6-ps.c +++ b/src/s6-linux-utils/s6-ps.c @@ -26,6 +26,7 @@ #include <skalibs/skamisc.h> #include <skalibs/unix-transactional.h> #include <skalibs/avltreen.h> + #include "s6-ps.h" #define USAGE "s6-ps [ -H ] [ -w spacing ] [ -W wchanfile ] [ -l | -o field,field... ]" diff --git a/src/minutils/s6-swapoff.c b/src/s6-linux-utils/s6-swapoff.c index 00df142..13a2530 100644 --- a/src/minutils/s6-swapoff.c +++ b/src/s6-linux-utils/s6-swapoff.c @@ -4,6 +4,7 @@ #include <sys/types.h> #include <sys/swap.h> #include <errno.h> + #include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/strerr.h> @@ -13,18 +14,16 @@ #define USAGE "s6-swapoff device <or> s6-swapoff -a" -#define BUFSIZE 4095 - -static int swapoffall ( ) +static int swapoffall (void) { - char buf[BUFSIZE+1] ; + char buf[4096] ; buffer b ; stralloc sa = STRALLOC_ZERO ; int e = 0 ; int r ; int fd = open_readb("/proc/swaps") ; if (fd < 0) strerr_diefu1sys(111, "open_readb /proc/swaps") ; - buffer_init(&b, &buffer_read, fd, buf, BUFSIZE+1) ; + buffer_init(&b, &buffer_read, fd, buf, 4096) ; if (skagetln(&b, &sa, '\n') < 0) strerr_diefu1sys(111, "skagetln") ; for (;;) { diff --git a/src/minutils/s6-swapon.c b/src/s6-linux-utils/s6-swapon.c index 41aabef..d9166a7 100644 --- a/src/minutils/s6-swapon.c +++ b/src/s6-linux-utils/s6-swapon.c @@ -5,11 +5,12 @@ #include <string.h> #include <stdio.h> #include <mntent.h> + #include <skalibs/strerr.h> #define USAGE "s6-swapon device <or> s6-swapon -a" -static int swaponall () +static int swaponall (void) { struct mntent *d ; int e = 0 ; diff --git a/src/minutils/s6-umount.c b/src/s6-linux-utils/s6-umount.c index 3ac1091..8a9b918 100644 --- a/src/minutils/s6-umount.c +++ b/src/s6-linux-utils/s6-umount.c @@ -2,6 +2,7 @@ #include <string.h> #include <sys/mount.h> + #include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/strerr.h> @@ -11,13 +12,12 @@ #define USAGE "s6-umount mountpoint <or> s6-umount -a" -#define BUFSIZE 4096 -#define MAXLINES 512 +#define UMOUNTALL_MAXLINES 512 -static int umountall ( ) +static int umountall (void) { - stralloc mountpoints[MAXLINES] ; - char buf[BUFSIZE+1] ; + stralloc mountpoints[UMOUNTALL_MAXLINES] ; + char buf[4096] ; buffer b ; stralloc sa = STRALLOC_ZERO ; unsigned int line = 0 ; @@ -26,11 +26,12 @@ static int umountall ( ) int fd = open_readb("/proc/mounts") ; if (fd < 0) strerr_diefu1sys(111, "open /proc/mounts") ; memset(mountpoints, 0, sizeof(mountpoints)) ; - buffer_init(&b, &buffer_read, fd, buf, BUFSIZE+1) ; + buffer_init(&b, &buffer_read, fd, buf, 4096) ; for (;;) { size_t n, p ; - if (line >= MAXLINES) strerr_dief1x(111, "/proc/mounts too big") ; + if (line >= UMOUNTALL_MAXLINES) + strerr_dief1x(111, "/proc/mounts too big") ; sa.len = 0 ; r = skagetln(&b, &sa, '\n') ; if (r <= 0) break ; |