Pseudo-terminals, and what tmux and htop needed around them
- /dev/ptmx and /dev/pts/N: Unix98 pairs with a full line discipline, window sizes, job control and hangup (kernel/dev/pty.c). - The console speaks scroll regions, insert/delete line, SU/SD, RI/IND/NEL, DECSC/DECRC; swallows charset designations and private CSI sequences; and LF only returns the carriage under ONLCR. - setsid() drops the controlling terminal, so a pane's pty becomes its ctty. - pipe2() honours O_NONBLOCK and O_CLOEXEC (libevent's signal pipe). - File modes are stored and enforced: chmod, fchmod(at), umask, creation modes; /tmp is 1777. - /proc/stat has real user/system/idle; /proc/<pid>/task; kthread flag. - SO_PEERCRED, IOV_MAX 1024. - /proc/strace: name a program and its syscalls go to the kernel log. - World gains htop, btop, tmux, mc, ncdu, fastfetch, games, X toys, NetSurf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
parent
c65bfa3fa3
commit
fd9d392416
28 changed files with 1577 additions and 47 deletions
|
|
@ -125,6 +125,11 @@ alloc_locked(int type)
|
|||
s->ref = 1;
|
||||
s->type = type;
|
||||
s->state = SS_UNBOUND;
|
||||
if(myproc()){
|
||||
s->cred_pid = myproc()->pid;
|
||||
s->cred_uid = myproc()->euid;
|
||||
s->cred_gid = myproc()->egid;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
@ -852,6 +857,9 @@ sockconnect(struct socket *s, uint dev, uint64 ino)
|
|||
|
||||
peer->peer = s;
|
||||
peer->state = SS_CONNECTED;
|
||||
peer->cred_pid = srv->cred_pid;
|
||||
peer->cred_uid = srv->cred_uid;
|
||||
peer->cred_gid = srv->cred_gid;
|
||||
s->peer = peer;
|
||||
s->state = SS_CONNECTED;
|
||||
|
||||
|
|
@ -1016,3 +1024,21 @@ socksendto(struct socket *s, char *buf, int n, uint addr, ushort port)
|
|||
return -EAFNOSUPPORT; // an AF_INET destination on an AF_UNIX socket
|
||||
return sockwrite(s, buf, n);
|
||||
}
|
||||
|
||||
// SO_PEERCRED: the credentials recorded for the far end of a connected Unix
|
||||
// socket. -1 if there is no far end.
|
||||
int
|
||||
sock_peercred(struct socket *s, int *pid, uint *uid, uint *gid)
|
||||
{
|
||||
int r = -1;
|
||||
|
||||
acquire(&stab.lock);
|
||||
if(s->domain != AF_INET && s->peer){
|
||||
*pid = s->peer->cred_pid;
|
||||
*uid = s->peer->cred_uid;
|
||||
*gid = s->peer->cred_gid;
|
||||
r = 0;
|
||||
}
|
||||
release(&stab.lock);
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue