diff options
| author | Kacper Fiedorowicz <kf@efab.pl> | 2026-01-03 18:44:51 +0100 |
|---|---|---|
| committer | Kacper Fiedorowicz <kf@efab.pl> | 2026-01-03 18:44:51 +0100 |
| commit | 6018e17637264a9561b37be699c3d53b6661de23 (patch) | |
| tree | 8546c9fa94358e7d6daaad5f11ac53e61be97ad5 /bin | |
| parent | ab21f339a33abb1144f3c0f5c4285324e7e88392 (diff) | |
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/Kbuild | 2 | ||||
| -rw-r--r-- | bin/Kconfig | 14 | ||||
| -rw-r--r-- | bin/nohup/Kbuild | 3 | ||||
| -rw-r--r-- | bin/nohup/nohup.c | 47 | ||||
| -rw-r--r-- | bin/playground/Kbuild | 6 | ||||
| -rw-r--r-- | bin/playground/main.c | 6 | ||||
| -rw-r--r-- | bin/unlink/Kbuild | 3 | ||||
| -rw-r--r-- | bin/unlink/unlink.c | 30 |
8 files changed, 99 insertions, 12 deletions
@@ -4,8 +4,10 @@ obj-$(CONFIG_BIN_ECHO) += echo/ obj-$(CONFIG_BIN_FALSE) += false/ obj-$(CONFIG_BIN_FREE) += free/ obj-$(CONFIG_BIN_GZIP) += gzip/ +obj-$(CONFIG_BIN_NOHUP) += nohup/ obj-$(CONFIG_BIN_PWD) += pwd/ obj-$(CONFIG_BIN_SLEEP) += sleep/ obj-$(CONFIG_BIN_SYNC) += sync/ obj-$(CONFIG_BIN_TRUE) += true/ obj-$(CONFIG_BIN_YES) += yes/ +obj-$(CONFIG_BIN_UNLINK) += unlink/ diff --git a/bin/Kconfig b/bin/Kconfig index 67e4e63d..325e6ab3 100644 --- a/bin/Kconfig +++ b/bin/Kconfig @@ -48,4 +48,18 @@ config BIN_TRUE help Build/Add the 'true' command which returns a zero exit status. +config BIN_NOHUP + bool "nohup" + default y + depends on LIB_LIBC + help + Build/Add the 'nohup' command which returns a zero exit status. + +config BIN_UNLINK + bool "unlink" + default y + depends on LIB_LIBC + help + Build/Add the 'unlink' command which returns a zero exit status. + endmenu diff --git a/bin/nohup/Kbuild b/bin/nohup/Kbuild new file mode 100644 index 00000000..2214faf1 --- /dev/null +++ b/bin/nohup/Kbuild @@ -0,0 +1,3 @@ +bin-y := nohup +obj-y += nohup.o +libs-y += $(srctree)/lib/libc/libc.a diff --git a/bin/nohup/nohup.c b/bin/nohup/nohup.c new file mode 100644 index 00000000..8a6171eb --- /dev/null +++ b/bin/nohup/nohup.c @@ -0,0 +1,47 @@ +#include <errno.h> +#include <fcntl.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + int fildes; + + if (argc < 2) { + write(STDOUT_FILENO, "nohup utility [argument...]\n", 29); + return 1; + } + + if (signal(SIGHUP, SIG_IGN) == SIG_ERR) { + perror("nohup: signal"); + return 1; + } + + if (isatty(STDOUT_FILENO)) { + fildes = open("nohup.out", O_WRONLY | O_APPEND | O_CREAT); + if (fildes < 0) { + perror("nohup: open"); + return 1; + } + + if (dup2(fildes, STDOUT_FILENO) < 0) { + perror("nohup: dup2"); + return 1; + } + + close(fildes); + } + + if (isatty(STDERR_FILENO)) { + if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + perror("nohup: dup2"); + return 1; + } + } + + execvp(argv[0], argv); + perror("nohup: execvp"); + return 127 + (errno == ENOENT); +} diff --git a/bin/playground/Kbuild b/bin/playground/Kbuild deleted file mode 100644 index d9c08784..00000000 --- a/bin/playground/Kbuild +++ /dev/null @@ -1,6 +0,0 @@ -bin-y := main -obj-y := main.o - -cflags-y += -fblocks - -libs-y := $(srctree)/lib/libc/libc.a diff --git a/bin/playground/main.c b/bin/playground/main.c deleted file mode 100644 index a6dab69a..00000000 --- a/bin/playground/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* Place where code from libs can be tested */ - -int main(void) -{ - return 0; -} diff --git a/bin/unlink/Kbuild b/bin/unlink/Kbuild new file mode 100644 index 00000000..91be1b03 --- /dev/null +++ b/bin/unlink/Kbuild @@ -0,0 +1,3 @@ +bin-y := unlink +obj-y += unlink.o +libs-y += $(srctree)/lib/libc/libc.a diff --git a/bin/unlink/unlink.c b/bin/unlink/unlink.c new file mode 100644 index 00000000..ae2a6da2 --- /dev/null +++ b/bin/unlink/unlink.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + char opt; + + while ((opt = getopt(argc, argv, "")) != -1) { + switch (opt) { + default: + goto usage; + return 1; + } + } + + if (argc != 2) { + goto usage; + return 1; + } + + if (unlink(argv[1]) == -1) { + perror("unlink: "); + return 1; + } + + return 0; +usage: + write(STDERR_FILENO, "usage: unlink file\n", 10); + return 0; +} |
