summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-07-01 16:21:43 +0200
committerAnton Kling <anton@kling.gg>2024-07-01 16:21:43 +0200
commit326cedcca7050ec0b143ff3d2ad94839f77ab22e (patch)
tree0fbcfdc18b0da5ba2cccb3950edf1ef906e9af5b /userland
parentab09d1f56f5881eb5d2234038d9146f74deecc10 (diff)
LibC: Change how kill() works
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/include/signal.h1
-rw-r--r--userland/libc/include/syscall.h1
-rw-r--r--userland/libc/libc.c1
-rw-r--r--userland/libc/signal/kill.c11
-rw-r--r--userland/libc/time/clock_gettime.c17
-rw-r--r--userland/minibox/utilities/kill.c4
-rw-r--r--userland/sh/sh.c4
7 files changed, 22 insertions, 17 deletions
diff --git a/userland/libc/include/signal.h b/userland/libc/include/signal.h
index 42702b2..e5f8d8b 100644
--- a/userland/libc/include/signal.h
+++ b/userland/libc/include/signal.h
@@ -39,6 +39,7 @@ struct siginfo {
typedef struct siginfo siginfo_t;
int kill(int fd, int sig);
+int kill_fd(int fd, int sig);
struct sigaction {
void (*sa_handler)(int); // Pointer to a signal-catching function or one of
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index e1c0b07..0396dce 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -47,6 +47,7 @@
#define SYS_SETSOCKOPT 39
#define SYS_GETPEERNAME 40
#define SYS_FCNTL 41
+#define SYS_CLOCK_GETTIME 42
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/libc.c b/userland/libc/libc.c
index 31d8648..decd002 100644
--- a/userland/libc/libc.c
+++ b/userland/libc/libc.c
@@ -131,6 +131,7 @@ void _libc_setup(void) {
__stderr_FILE->read = read_fd;
__stderr_FILE->is_eof = 0;
__stderr_FILE->has_error = 0;
+ __stdout_FILE->seek = NULL;
__stderr_FILE->cookie = NULL;
__stderr_FILE->fd = 2;
__stderr_FILE->fflush = fflush_fd;
diff --git a/userland/libc/signal/kill.c b/userland/libc/signal/kill.c
index c5ed62b..c8a368f 100644
--- a/userland/libc/signal/kill.c
+++ b/userland/libc/signal/kill.c
@@ -1,6 +1,15 @@
+#include <fcntl.h>
+#include <unistd.h>
#include <signal.h>
#include <syscall.h>
-int kill(int fd, int sig) {
+int kill_fd(int fd, int sig) {
RC_ERRNO(syscall(SYS_KILL, fd, sig, 0, 0, 0))
}
+
+int kill(int pid, int sig) {
+ int fd = open_process(pid);
+ int rc = kill_fd(fd, sig);
+ close(fd);
+ return rc;
+}
diff --git a/userland/libc/time/clock_gettime.c b/userland/libc/time/clock_gettime.c
index 492b968..239b389 100644
--- a/userland/libc/time/clock_gettime.c
+++ b/userland/libc/time/clock_gettime.c
@@ -1,15 +1,12 @@
+#include <errno.h>
+#include <stdint.h>
#include <syscall.h>
#include <time.h>
+#include <unistd.h>
int clock_gettime(clockid_t clock_id, struct timespec *tp) {
- (void)clock_id;
- tp->tv_sec = 0;
- tp->tv_nsec = 0;
- return 0;
- /*
-SYS_CLOCK_GETTIME_PARAMS args = {
-.clk = clock_id,
-.ts = tp,
-};
-return syscall(SYS_CLOCK_GETTIME, &args);*/
+ uint32_t ms = uptime();
+ tp->tv_sec = ms / 1000;
+ tp->tv_nsec = ms * 1000000;
+ RC_ERRNO(syscall(SYS_CLOCK_GETTIME, clock_id, tp, 0, 0, 0));
}
diff --git a/userland/minibox/utilities/kill.c b/userland/minibox/utilities/kill.c
index 8cc6877..665320e 100644
--- a/userland/minibox/utilities/kill.c
+++ b/userland/minibox/utilities/kill.c
@@ -5,8 +5,6 @@
#include <stdio.h>
int kill_main(int argc, char **argv) {
- int fd = open_process(4);
- kill(fd, SIGTERM);
- close(fd);
+ kill(4, SIGTERM);
return 0;
}
diff --git a/userland/sh/sh.c b/userland/sh/sh.c
index e386ef6..e7741aa 100644
--- a/userland/sh/sh.c
+++ b/userland/sh/sh.c
@@ -49,9 +49,7 @@ void remove_child_process(int pid) {
void slaugther_children(void) {
struct child_process *child = children;
for (; child; child = child->next) {
- int fd = open_process(child->pid);
- kill(fd, SIGTERM);
- close(fd);
+ kill(child->pid, SIGTERM);
}
}