diff options
author | Anton Kling <anton@kling.gg> | 2024-12-11 18:47:33 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-12-12 15:48:20 +0100 |
commit | 633feeea57c298306d8664c9c2768ab46fb7c6f4 (patch) | |
tree | d91cd1c19d3e850b978c7ada526246e3b35e6608 /userland | |
parent | bc828883c51c3c0f35872019f4db632e4ce82dc5 (diff) |
signal: Remove old way of sending signals and instead use procfs
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/Makefile | 2 | ||||
-rw-r--r-- | userland/libc/fcntl/open_process.c | 6 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 38 | ||||
-rw-r--r-- | userland/libc/signal/kill.c | 23 | ||||
-rw-r--r-- | userland/minibox/utilities/ls.c | 10 | ||||
-rw-r--r-- | userland/minibox/utilities/rdate.c | 6 |
6 files changed, 43 insertions, 42 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 0e56a4a..e5aeff1 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -2,7 +2,7 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Werror -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o arpa/inet/ntohl.o arpa/inet/ntohs.o netdb/getaddrinfo.o tb/sha1.o sys/socket/getpeername.o fcntl/fcntl.o queue.o sys/sendfile.o stdio/fdopen.o unistd/dup.o +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o arpa/inet/ntohl.o arpa/inet/ntohs.o netdb/getaddrinfo.o tb/sha1.o sys/socket/getpeername.o fcntl/fcntl.o queue.o sys/sendfile.o stdio/fdopen.o unistd/dup.o all: libc.a %.o: %.c diff --git a/userland/libc/fcntl/open_process.c b/userland/libc/fcntl/open_process.c deleted file mode 100644 index 8486728..0000000 --- a/userland/libc/fcntl/open_process.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <fcntl.h> -#include <syscall.h> - -int open_process(int pid) { - RC_ERRNO(syscall(SYS_OPEN_PROCESS, pid, 0, 0, 0, 0)); -} diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index 95ab817..3699854 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -34,26 +34,24 @@ #define SYS_MKDIR 26 #define SYS_RECVFROM 27 #define SYS_SENDTO 28 -#define SYS_KILL 29 -#define SYS_SIGACTION 30 -#define SYS_CHDIR 31 -#define SYS_GETCWD 32 -#define SYS_ISATTY 33 -#define SYS_RANDOMFILL 34 -#define SYS_MUNMAP 35 -#define SYS_OPEN_PROCESS 36 -#define SYS_LSEEK 37 -#define SYS_CONNECT 38 -#define SYS_SETSOCKOPT 39 -#define SYS_GETPEERNAME 40 -#define SYS_FCNTL 41 -#define SYS_CLOCK_GETTIME 42 -#define SYS_QUEUE_CREATE 43 -#define SYS_QUEUE_MOD_ENTRIES 44 -#define SYS_QUEUE_WAIT 45 -#define SYS_SENDFILE 46 -#define SYS_SHM_UNLINK 47 -#define SYS_DUP 48 +#define SYS_SIGACTION 29 +#define SYS_CHDIR 30 +#define SYS_GETCWD 31 +#define SYS_ISATTY 32 +#define SYS_RANDOMFILL 33 +#define SYS_MUNMAP 34 +#define SYS_LSEEK 35 +#define SYS_CONNECT 36 +#define SYS_SETSOCKOPT 37 +#define SYS_GETPEERNAME 38 +#define SYS_FCNTL 39 +#define SYS_CLOCK_GETTIME 40 +#define SYS_QUEUE_CREATE 41 +#define SYS_QUEUE_MOD_ENTRIES 42 +#define SYS_QUEUE_WAIT 43 +#define SYS_SENDFILE 44 +#define SYS_SHM_UNLINK 45 +#define SYS_DUP 46 int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi); diff --git a/userland/libc/signal/kill.c b/userland/libc/signal/kill.c index c8a368f..4518b49 100644 --- a/userland/libc/signal/kill.c +++ b/userland/libc/signal/kill.c @@ -1,15 +1,20 @@ +#include <assert.h> #include <fcntl.h> -#include <unistd.h> #include <signal.h> +#include <stdio.h> #include <syscall.h> - -int kill_fd(int fd, int sig) { - RC_ERRNO(syscall(SYS_KILL, fd, sig, 0, 0, 0)) -} +#include <unistd.h> int kill(int pid, int sig) { - int fd = open_process(pid); - int rc = kill_fd(fd, sig); - close(fd); - return rc; + char buffer[4096]; + snprintf(buffer, sizeof(buffer), "/proc/%d/signal", pid); + int fd = open(buffer, O_WRITE); + if (-1 == fd) { + return -1; + } + if (-1 == dprintf(fd, "%d", sig)) { + return -1; + } + assert(-1 != close(fd)); + return 0; } diff --git a/userland/minibox/utilities/ls.c b/userland/minibox/utilities/ls.c index 0ce70f8..5a8f8ea 100644 --- a/userland/minibox/utilities/ls.c +++ b/userland/minibox/utilities/ls.c @@ -20,10 +20,16 @@ int ls_main(int argc, char **argv) { newline = 1; break; }*/ + char *path = argv[1]; + char path_buffer[256]; + + if (!path) { + (void)getcwd(path_buffer, 256); + path = path_buffer; + } + struct dirent **namelist; int n; - char path[256]; - (void)getcwd(path, 256); COND_PERROR_EXP(-1 == (n = scandir(path, &namelist, 0, 0)), "scandir", return 1); diff --git a/userland/minibox/utilities/rdate.c b/userland/minibox/utilities/rdate.c index 11398c8..54a2746 100644 --- a/userland/minibox/utilities/rdate.c +++ b/userland/minibox/utilities/rdate.c @@ -42,9 +42,7 @@ int rdate_main(int argc, char **argv) { int64_t unix_time = (t - 2208988800) * 1000; int clock_fd = open("/dev/clock", O_RDWR); int64_t current; - read(clock_fd, ¤t, sizeof(int64_t)); - write(clock_fd, &unix_time, sizeof(int64_t)); - int64_t delta = (current / 1000) - (unix_time / 1000); - printf("delta: %d\n", delta); + dprintf(clock_fd, "%lld", unix_time); + close(clock_fd); return 0; } |