Signed-off-by: Drew DeVault <sir@cmpwn.com>
---
v2: make bootstrap
Note the build is expected to fail as this depends on some other patches
in flight
makefiles/freebsd.aarch64.mk | 2 +-
makefiles/freebsd.riscv64.mk | 2 +-
makefiles/freebsd.x86_64.mk | 2 +-
makefiles/linux.aarch64.mk | 2 +-
makefiles/linux.riscv64.mk | 2 +-
makefiles/linux.x86_64.mk | 2 +-
makefiles/openbsd.aarch64.mk | 2 +-
makefiles/openbsd.riscv64.mk | 2 +-
makefiles/openbsd.x86_64.mk | 2 +-
rt/+freebsd/syscalls.ha | 8 ++++++++
rt/+openbsd/syscalls.ha | 23 +++++++++++++++++++++++
unix/+freebsd/setsid.ha | 27 +++++++++++++++++++++++++++
unix/+linux/setsid.ha | 27 +++++++++++++++++++++++++++
unix/+openbsd/setsid.ha | 27 +++++++++++++++++++++++++++
14 files changed, 121 insertions(+), 9 deletions(-)
create mode 100644 unix/+freebsd/setsid.ha
create mode 100644 unix/+linux/setsid.ha
create mode 100644 unix/+openbsd/setsid.ha
diff --git a/makefiles/freebsd.aarch64.mk b/makefiles/freebsd.aarch64.mk
index 519f2f4b..b065b04f 100644
--- a/makefiles/freebsd.aarch64.mk
+++ b/makefiles/freebsd.aarch64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
+unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setsid.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/freebsd.riscv64.mk b/makefiles/freebsd.riscv64.mk
index bedd79f0..6ee70593 100644
--- a/makefiles/freebsd.riscv64.mk
+++ b/makefiles/freebsd.riscv64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
+unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setsid.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/freebsd.x86_64.mk b/makefiles/freebsd.x86_64.mk
index c9429b3c..69db7df4 100644
--- a/makefiles/freebsd.x86_64.mk
+++ b/makefiles/freebsd.x86_64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
+unix_ha = unix/+freebsd/getpid.ha unix/+freebsd/getuid.ha unix/+freebsd/groups.ha unix/+freebsd/nice.ha unix/+freebsd/pipe.ha unix/+freebsd/setsid.ha unix/+freebsd/setuid.ha unix/+freebsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/linux.aarch64.mk b/makefiles/linux.aarch64.mk
index fd6fddfb..2cbe7b73 100644
--- a/makefiles/linux.aarch64.mk
+++ b/makefiles/linux.aarch64.mk
@@ -219,7 +219,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setuid.ha unix/+linux/umask.ha
+unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setsid.ha unix/+linux/setuid.ha unix/+linux/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/linux.riscv64.mk b/makefiles/linux.riscv64.mk
index 983d8792..d454b268 100644
--- a/makefiles/linux.riscv64.mk
+++ b/makefiles/linux.riscv64.mk
@@ -219,7 +219,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setuid.ha unix/+linux/umask.ha
+unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setsid.ha unix/+linux/setuid.ha unix/+linux/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/linux.x86_64.mk b/makefiles/linux.x86_64.mk
index 8e70a837..e8dba645 100644
--- a/makefiles/linux.x86_64.mk
+++ b/makefiles/linux.x86_64.mk
@@ -219,7 +219,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setuid.ha unix/+linux/umask.ha
+unix_ha = unix/+linux/getpid.ha unix/+linux/getuid.ha unix/+linux/groups.ha unix/+linux/nice.ha unix/+linux/pipe.ha unix/+linux/setsid.ha unix/+linux/setuid.ha unix/+linux/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/openbsd.aarch64.mk b/makefiles/openbsd.aarch64.mk
index d040d8f9..27d270d2 100644
--- a/makefiles/openbsd.aarch64.mk
+++ b/makefiles/openbsd.aarch64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
+unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setsid.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/openbsd.riscv64.mk b/makefiles/openbsd.riscv64.mk
index 515c3953..9ffd516c 100644
--- a/makefiles/openbsd.riscv64.mk
+++ b/makefiles/openbsd.riscv64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
+unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setsid.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/makefiles/openbsd.x86_64.mk b/makefiles/openbsd.x86_64.mk
index 6fdd7b5d..59a982c0 100644
--- a/makefiles/openbsd.x86_64.mk
+++ b/makefiles/openbsd.x86_64.mk
@@ -201,7 +201,7 @@ $(HARECACHE)/hare_module.ssa: $(hare_module_ha) $(HARECACHE)/ascii.td $(HARECACH
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/hare_module.ssa -t $(HARECACHE)/hare_module.td.tmp -N hare::module $(hare_module_ha)
-unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
+unix_ha = unix/+openbsd/getpid.ha unix/+openbsd/getuid.ha unix/+openbsd/groups.ha unix/+openbsd/nice.ha unix/+openbsd/pipe.ha unix/+openbsd/setsid.ha unix/+openbsd/setuid.ha unix/+openbsd/umask.ha
$(HARECACHE)/unix.ssa: $(unix_ha) $(HARECACHE)/errors.td $(HARECACHE)/fs.td $(HARECACHE)/io.td $(HARECACHE)/rt.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha
index 22d7b7ba..ccf4cbe2 100644
--- a/rt/+freebsd/syscalls.ha
+++ b/rt/+freebsd/syscalls.ha
@@ -340,6 +340,14 @@ export fn setpgid(pid: pid_t, pgid: pid_t) (void | errno) = {
wrap_return(syscall2(SYS_setpgid, pid: u64, pgid: u64))?;
};
+export fn getsid(pid: int) (int | errno) = {
+ return wrap_return(syscall1(SYS_getsid, pid: u64))?: int;
+};
+
+export fn setsid() (void | errno) = {
+ return wrap_return(syscall0(SYS_setsid))?: void;
+};
+
export fn getpriority(which: int, who: id_t) (int | errno) = {
return wrap_return(syscall2(SYS_getpriority,
which: u64, who: u64))?: int;
diff --git a/rt/+openbsd/syscalls.ha b/rt/+openbsd/syscalls.ha
index 0e28ad32..6fa0f113 100644
--- a/rt/+openbsd/syscalls.ha
+++ b/rt/+openbsd/syscalls.ha
@@ -1045,7 +1045,18 @@ export fn socketpair(
// getthrname
// setthrname
// pinsyscall
+
// setsid
+
+@symbol("setsid") fn libc_setsid() pid_t;
+
+export fn setsid() (void | errno) = {
+ let res = libc_setsid();
+ if (res == -1) {
+ return *__errno(): errno;
+ };
+};
+
// quotactl
// ypconnect
// nfssvc
@@ -1171,7 +1182,19 @@ export fn getpgid(pid: pid_t) (pid_t | errno) = {
// poll
// issetugid
// lchown
+
// getsid
+
+@symbol("getsid") fn libc_getsid(pid: pid_t) pid_t;
+
+export fn getsid(pid: pid_t) (pid_t | errno) = {
+ let res = libc_getsid(pid);
+ if (res == -1) {
+ return *__errno(): errno;
+ };
+ return res;
+};
+
// msync
// pipe
// fhopen
diff --git a/unix/+freebsd/setsid.ha b/unix/+freebsd/setsid.ha
new file mode 100644
index 00000000..ae165ee7
--- /dev/null
+++ b/unix/+freebsd/setsid.ha
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: MPL-2.0
+// (c) Hare authors <https://harelang.org>
+
+use errors;
+use rt;
+
+// Creates a new Unix session and sets the current process to the session
+// leader.
+export fn setsid() (void | errors::error) = {
+ match (rt::setsid()) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case void =>
+ return;
+ };
+};
+
+// Returns the session ID of the given process. Pass zero to return the current
+// process's session ID.
+export fn getsid(pid: int) (int | errors::error) = {
+ match (rt::getsid(pid)) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case let sid: int =>
+ return sid;
+ };
+};
diff --git a/unix/+linux/setsid.ha b/unix/+linux/setsid.ha
new file mode 100644
index 00000000..ae165ee7
--- /dev/null
+++ b/unix/+linux/setsid.ha
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: MPL-2.0
+// (c) Hare authors <https://harelang.org>
+
+use errors;
+use rt;
+
+// Creates a new Unix session and sets the current process to the session
+// leader.
+export fn setsid() (void | errors::error) = {
+ match (rt::setsid()) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case void =>
+ return;
+ };
+};
+
+// Returns the session ID of the given process. Pass zero to return the current
+// process's session ID.
+export fn getsid(pid: int) (int | errors::error) = {
+ match (rt::getsid(pid)) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case let sid: int =>
+ return sid;
+ };
+};
diff --git a/unix/+openbsd/setsid.ha b/unix/+openbsd/setsid.ha
new file mode 100644
index 00000000..ae165ee7
--- /dev/null
+++ b/unix/+openbsd/setsid.ha
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: MPL-2.0
+// (c) Hare authors <https://harelang.org>
+
+use errors;
+use rt;
+
+// Creates a new Unix session and sets the current process to the session
+// leader.
+export fn setsid() (void | errors::error) = {
+ match (rt::setsid()) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case void =>
+ return;
+ };
+};
+
+// Returns the session ID of the given process. Pass zero to return the current
+// process's session ID.
+export fn getsid(pid: int) (int | errors::error) = {
+ match (rt::getsid(pid)) {
+ case let err: rt::errno =>
+ return errors::errno(err);
+ case let sid: int =>
+ return sid;
+ };
+};
--
2.43.1
>+export fn setsid() (void | errno) = {
>+ return wrap_return(syscall0(SYS_setsid))?: void;
>+};
> // setsid
>+
>+@symbol("setsid") fn libc_setsid() pid_t;
>+
>+export fn setsid() (void | errno) = {
>+ let res = libc_setsid();
>+ if (res == -1) {
>+ return *__errno(): errno;
>+ };
>+};
Since that’s what the platforms’ setsids do, I think setsid should
return the new pid_t.