diff options
author | petershh <petershh@disroot.org> | 2022-08-03 12:12:24 +0300 |
---|---|---|
committer | Peter <santurysim@gmail.com> | 2022-08-03 12:24:06 +0300 |
commit | 568e9eab9c6a866ac2fa10f889e106a4e63c0581 (patch) | |
tree | dd6a57bf08e40d82c7fa59e0893e9ade538a0d2b | |
parent | 3482b63c7ecc76ef0e3409c013f9464f15d1b279 (diff) | |
download | shh-portable-utils-568e9eab9c6a866ac2fa10f889e106a4e63c0581.tar.xz |
Add mkfifo
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | package/deps.mak | 3 | ||||
-rw-r--r-- | package/modes | 1 | ||||
-rw-r--r-- | package/targets.mak | 1 | ||||
-rw-r--r-- | src/shh-portable-utils/change_mode.c | 1 | ||||
-rw-r--r-- | src/shh-portable-utils/deps-exe/mkfifo | 4 | ||||
-rw-r--r-- | src/shh-portable-utils/mkfifo.c | 64 |
7 files changed, 75 insertions, 0 deletions
@@ -15,6 +15,7 @@ src/include/shh-portable-utils/config.h /false /link /ln +/mkfifo /nice /nohup /renice diff --git a/package/deps.mak b/package/deps.mak index 527dc2f..fc6cfd1 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -14,6 +14,7 @@ src/shh-portable-utils/dirname.o src/shh-portable-utils/dirname.lo: src/shh-port src/shh-portable-utils/false.o src/shh-portable-utils/false.lo: src/shh-portable-utils/false.c src/shh-portable-utils/link.o src/shh-portable-utils/link.lo: src/shh-portable-utils/link.c src/shh-portable-utils/ln.o src/shh-portable-utils/ln.lo: src/shh-portable-utils/ln.c +src/shh-portable-utils/mkfifo.o src/shh-portable-utils/mkfifo.lo: src/shh-portable-utils/mkfifo.c src/shh-portable-utils/shhfuncs.h src/shh-portable-utils/nice.o src/shh-portable-utils/nice.lo: src/shh-portable-utils/nice.c src/shh-portable-utils/nohup.o src/shh-portable-utils/nohup.lo: src/shh-portable-utils/nohup.c src/shh-portable-utils/parse_group.o src/shh-portable-utils/parse_group.lo: src/shh-portable-utils/parse_group.c @@ -49,6 +50,8 @@ link: EXTRA_LIBS := -lskarnet link: src/shh-portable-utils/link.o ln: EXTRA_LIBS := -lskarnet ln: src/shh-portable-utils/ln.o +mkfifo: EXTRA_LIBS := -lskarnet +mkfifo: src/shh-portable-utils/mkfifo.o src/shh-portable-utils/parse_mode_octal.o src/shh-portable-utils/parse_mode_symbolic.o src/shh-portable-utils/change_mode.o nice: EXTRA_LIBS := -lskarnet nice: src/shh-portable-utils/nice.o nohup: EXTRA_LIBS := -lskarnet diff --git a/package/modes b/package/modes index 5ece3f4..3173407 100644 --- a/package/modes +++ b/package/modes @@ -8,6 +8,7 @@ dirname 0755 false 0755 link 0755 ln 0755 +mkfifo 0755 nice 0755 nohup 0755 renice 0755 diff --git a/package/targets.mak b/package/targets.mak index 47c7185..a7516ab 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -9,6 +9,7 @@ dirname \ false \ link \ ln \ +mkfifo \ nice \ nohup \ renice \ diff --git a/src/shh-portable-utils/change_mode.c b/src/shh-portable-utils/change_mode.c index cc919c4..ec5cf5f 100644 --- a/src/shh-portable-utils/change_mode.c +++ b/src/shh-portable-utils/change_mode.c @@ -60,6 +60,7 @@ mode_t change_mode(mode_t initial_mode, chmod_directive *directives, switch (directives[i].action) { case '=': cur_mode &= ~clear; + /* fallthrough */ case '+': cur_mode |= (who & perm); break; diff --git a/src/shh-portable-utils/deps-exe/mkfifo b/src/shh-portable-utils/deps-exe/mkfifo new file mode 100644 index 0000000..e765767 --- /dev/null +++ b/src/shh-portable-utils/deps-exe/mkfifo @@ -0,0 +1,4 @@ +parse_mode_octal.o +parse_mode_symbolic.o +change_mode.o +-lskarnet diff --git a/src/shh-portable-utils/mkfifo.c b/src/shh-portable-utils/mkfifo.c new file mode 100644 index 0000000..61e0ca0 --- /dev/null +++ b/src/shh-portable-utils/mkfifo.c @@ -0,0 +1,64 @@ +#include <errno.h> + +#include <sys/types.h> +#include <sys/stat.h> + +#include <skalibs/genalloc.h> +#include <skalibs/strerr2.h> +#include <skalibs/sgetopt.h> + +#include "shhfuncs.h" + +#define USAGE "mkfifo [-m mode] file ..." + +int main(int argc, char const *const *argv) +{ + mode_t mask; + mode_t mode = 0666; + int failure = 0; + genalloc directives = GENALLOC_ZERO; + subgetopt l = SUBGETOPT_ZERO; + PROG = "mkfifo"; + + mask = umask(0); + umask(mask); + + for (;;) { + int opt = subgetopt_r(argc, argv, "m:", &l); + if (opt == -1) + break; + switch (opt) { + case 'm': + if ('0' <= l.arg[0] && l.arg[0] <= '7') { + if (parse_mode_octal(l.arg, &mode)) + strerr_dief2x(100, "invalid mode: ", l.arg); + } else if (parse_mode_symbolic(l.arg, &directives)) { + if (errno == EINVAL) + strerr_dief2x(100, "invalid mode: ", l.arg); + else + strerr_diefu1sys(111, "parse mode"); + } else + mode = change_mode(0666, genalloc_s(chmod_directive, + &directives), + genalloc_len(chmod_directive, + &directives), + mask); + break; + default: + strerr_dieusage(100, USAGE); + } + } + argc -= l.ind; + argv += l.ind; + + if (!argc) + strerr_dieusage(100, USAGE); + + for (char const *const *name = argv; *name; name++) + if (mkfifo(*name, mode)) { + strerr_warnwu2sys("create fifo ", *name); + failure = 1; + } + + return failure ? 111 : 0; +} |