Compare commits
No commits in common. "b9c49648c46026682bace8f98c160e0edeb4d15e" and "870cfa36683f89a52138074df2376f100ba7133c" have entirely different histories.
b9c49648c4
...
870cfa3668
12 changed files with 13 additions and 107 deletions
|
@ -4297,7 +4297,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
// Prevent recursive init without care.
|
||||
if ( getinit(0) != getpid() )
|
||||
if ( getinit() != getpid() )
|
||||
fatal("System is already managed by an init process");
|
||||
|
||||
// Register handler that shuts down the system when init exits.
|
||||
|
|
|
@ -97,7 +97,7 @@ int sys_getentropy(void*, size_t);
|
|||
uid_t sys_geteuid(void);
|
||||
gid_t sys_getgid(void);
|
||||
int sys_gethostname(char*, size_t);
|
||||
pid_t sys_getinit(pid_t);
|
||||
pid_t sys_getinit(void);
|
||||
size_t sys_getpagesize(void);
|
||||
int sys_getpeername(int, void*, size_t*);
|
||||
pid_t sys_getpgid(pid_t);
|
||||
|
|
|
@ -1624,8 +1624,7 @@ pid_t sys_getpgid(pid_t pid)
|
|||
pid_t sys_getsid(pid_t pid)
|
||||
{
|
||||
ScopedLock lock(&process_family_lock);
|
||||
Process* process =
|
||||
!pid ? CurrentProcess() : CurrentProcess()->GetPTable()->Get(pid);
|
||||
Process* process = !pid ? CurrentProcess() : CurrentProcess()->GetPTable()->Get(pid);
|
||||
if ( !process )
|
||||
return errno = ESRCH, -1;
|
||||
if ( !process->session )
|
||||
|
@ -1633,11 +1632,10 @@ pid_t sys_getsid(pid_t pid)
|
|||
return process->session->pid;
|
||||
}
|
||||
|
||||
pid_t sys_getinit(pid_t pid)
|
||||
pid_t sys_getinit(void)
|
||||
{
|
||||
ScopedLock lock(&process_family_lock);
|
||||
Process* process =
|
||||
!pid ? CurrentProcess() : CurrentProcess()->GetPTable()->Get(pid);
|
||||
Process* process = CurrentProcess();
|
||||
if ( !process->init )
|
||||
return errno = ESRCH, -1;
|
||||
return process->init->pid;
|
||||
|
|
|
@ -781,8 +781,6 @@ MANPAGES2=\
|
|||
scram/scram.2 \
|
||||
sys/dnsconfig/getdnsconfig.2 \
|
||||
sys/dnsconfig/setdnsconfig.2 \
|
||||
unistd/setinit.2 \
|
||||
unistd/getinit.2 \
|
||||
|
||||
MANPAGES3=\
|
||||
time/add_leap_seconds.3 \
|
||||
|
|
|
@ -562,7 +562,7 @@ int exit_thread(int, int, const struct exit_thread*);
|
|||
int fchdirat(int, const char*);
|
||||
int fchroot(int);
|
||||
int fchrootat(int, const char*);
|
||||
pid_t getinit(pid_t);
|
||||
pid_t getinit(void);
|
||||
int memstat(size_t* memused, size_t* memtotal);
|
||||
int mkpartition(int fd, off_t start, off_t length);
|
||||
pid_t setinit(void);
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
setinit.2
|
|
@ -21,9 +21,10 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL1(pid_t, sys_getinit, SYSCALL_GETINIT, pid_t);
|
||||
DEFN_SYSCALL0(pid_t, sys_getinit, SYSCALL_GETINIT);
|
||||
|
||||
pid_t getinit(pid_t pid)
|
||||
// TODO: Should this accept a pid like getsid?
|
||||
pid_t getinit(void)
|
||||
{
|
||||
return sys_getinit(pid);
|
||||
return sys_getinit();
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
.Dd June 18, 2024
|
||||
.Dt SETINIT 2
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm setinit
|
||||
.Nd become and locate init
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
.Ft int
|
||||
.Fn getinit "pid_t pid"
|
||||
.Ft int
|
||||
.Fn setinit void
|
||||
.Sh DESCRIPTION
|
||||
.Fn setinit
|
||||
sets the current process as the init process for itself and its subsequently
|
||||
created descendant processes.
|
||||
.Fn setinit
|
||||
runs
|
||||
.Xr setsid 2
|
||||
to create a new session (and process group) and can fail for the same reasons as
|
||||
.Xr setsid 2 .
|
||||
.Pp
|
||||
.Fn getinit
|
||||
returns the init process for the process specified in
|
||||
.Fa pid ,
|
||||
or the current process if
|
||||
.Fa pid
|
||||
is zero.
|
||||
.Pp
|
||||
Orphaned descendant processes are reparanted to their init process.
|
||||
If an init process exits, all descendant processes atomically receive the
|
||||
.Dv SIGKILL
|
||||
signal and become unable to create new processes and threads.
|
||||
.Sh RETURN VALUES
|
||||
.Fn setinit
|
||||
returns the pid of the init process (the current process) on success, or -1 on
|
||||
error and
|
||||
.Va error
|
||||
is set appropriately.
|
||||
.Pp
|
||||
.Fn getinit
|
||||
returns the returns the pid of the init process, or -1 on
|
||||
error and
|
||||
.Va error
|
||||
is set appropriately.
|
||||
.Sh ERRORS
|
||||
.Fn setinit
|
||||
will fail if:
|
||||
.Bl -tag -width "12345678"
|
||||
.It Er EPERM
|
||||
The process is already a process group leader, a session leader, or an init
|
||||
process.
|
||||
.El
|
||||
.Pp
|
||||
.Fn getinit
|
||||
will fail if:
|
||||
.Bl -tag -width "12345678"
|
||||
.It Er ESRCH
|
||||
The process specified in
|
||||
.Fa pid
|
||||
does not exist.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr getpgrp 2 ,
|
||||
.Xr getsid 2 ,
|
||||
.Xr psctl 2 ,
|
||||
.Xr setpgrp 2 ,
|
||||
.Xr setsid 2 ,
|
||||
.Xr init 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn getinit
|
||||
and
|
||||
.Fn setinit
|
||||
system calls originally appeared in Sortix 1.1.
|
|
@ -69,21 +69,6 @@ releasing Sortix x.y, foo." to allow the maintainer to easily
|
|||
.Xr grep 1
|
||||
for it after a release.
|
||||
.Sh CHANGES
|
||||
.Ss Add init groups
|
||||
The
|
||||
.Xr setinit 2
|
||||
and
|
||||
.Xr getinit 2
|
||||
system calls have been added for nested init groups.
|
||||
The
|
||||
.Dv TIOCSCTTY
|
||||
.Xr ioctl 2
|
||||
for acquiring a controlling terminal has gained a force flag essential to
|
||||
transferring terminals into nested sessions, and the new
|
||||
.Dv TIOCUCTTY
|
||||
.Xr ioctl 2
|
||||
releases a controlling terminal.
|
||||
This is a minor compatible ABI change.
|
||||
.Ss Add tix-repository(8)
|
||||
The new
|
||||
.Xr tix-repository 8
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
|||
if ( optind < argc )
|
||||
errx(1, "extra operand: %s", argv[optind]);
|
||||
|
||||
pid_t init_pid = getinit(0);
|
||||
pid_t init_pid = getinit();
|
||||
if ( kill(init_pid, SIGQUIT) < 0 )
|
||||
err(1, "kill: %" PRIdPID, init_pid);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
|||
if ( optind < argc )
|
||||
errx(1, "extra operand: %s", argv[optind]);
|
||||
|
||||
pid_t init_pid = getinit(0);
|
||||
pid_t init_pid = getinit();
|
||||
if ( kill(init_pid, SIGTERM) < 0 )
|
||||
err(1, "kill: %" PRIdPID, init_pid);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
|||
if ( optind < argc )
|
||||
errx(1, "extra operand: %s", argv[optind]);
|
||||
|
||||
pid_t init_pid = getinit(0);
|
||||
pid_t init_pid = getinit();
|
||||
if ( kill(init_pid, SIGINT) < 0 )
|
||||
err(1, "kill: %" PRIdPID, init_pid);
|
||||
|
||||
|
|
Loading…
Reference in a new issue