authorgravatar for _@gr.htGregory Mullen <_@gr.ht> 2023-05-10 14:33:36-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-11 19:43:06+03:00
logaa9ea612168836e2c2867dcd79c768155d1e3bfb
tree23169b8f5cd34d3e598c8a1da5f801a98417def0
parent7f7bd206dc8309ca767b47fb97bb9e7c2dc882c3

Add tc{set,get}pgrp to std.os.linux


2 files changed, 46 insertions(+), 1 deletions(-)

lib/std/os.zig+38-1
...@@ -6791,7 +6791,9 @@ pub fn getrusage(who: i32) rusage {...@@ -6791,7 +6791,9 @@ pub fn getrusage(who: i32) rusage {
6791 }6791 }
6792}6792}
67936793
6794pub const TermiosGetError = error{NotATerminal} || UnexpectedError;6794pub const TIOCError = error{NotATerminal};
6795
6796pub const TermiosGetError = TIOCError || UnexpectedError;
67956797
6796pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {6798pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {
6797 while (true) {6799 while (true) {
...@@ -6822,6 +6824,41 @@ pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) Termio...@@ -6822,6 +6824,41 @@ pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) Termio
6822 }6824 }
6823}6825}
68246826
6827pub const TermioGetPgrpError = TIOCError || UnexpectedError;
6828
6829/// Returns the process group ID for the TTY associated with the given handle.
6830pub fn tcgetpgrp(handle: fd_t) TermioGetPgrpError!pid_t {
6831 while (true) {
6832 var pgrp: pid_t = undefined;
6833 switch (errno(system.tcgetpgrp(handle, &pgrp))) {
6834 .SUCCESS => return pgrp,
6835 .BADF => unreachable,
6836 .INVAL => unreachable,
6837 .NOTTY => return error.NotATerminal,
6838 else => |err| return unexpectedErrno(err),
6839 }
6840 }
6841}
6842
6843pub const TermioSetPgrpError = TermioGetPgrpError || error{NotAPgrpMember};
6844
6845/// Sets the controlling process group ID for given TTY.
6846/// handle must be valid fd_t to a TTY associated with calling process.
6847/// pgrp must be a valid process group, and the calling process must be a member
6848/// of that group.
6849pub fn tcsetpgrp(handle: fd_t, pgrp: pid_t) TermioSetPgrpError!void {
6850 while (true) {
6851 switch (errno(system.tcsetpgrp(handle, &pgrp))) {
6852 .SUCCESS => return,
6853 .BADF => unreachable,
6854 .INVAL => unreachable,
6855 .NOTTY => return error.NotATerminal,
6856 .PERM => return TermioSetPgrpError.NotAPgrpMember,
6857 else => |err| return unexpectedErrno(err),
6858 }
6859 }
6860}
6861
6825pub const IoCtl_SIOCGIFINDEX_Error = error{6862pub const IoCtl_SIOCGIFINDEX_Error = error{
6826 FileSystem,6863 FileSystem,
6827 InterfaceNotFound,6864 InterfaceNotFound,
lib/std/os/linux.zig+8
...@@ -1631,6 +1631,14 @@ pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usi...@@ -1631,6 +1631,14 @@ pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usi
1631 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSETS + @enumToInt(optional_action), @ptrToInt(termios_p));1631 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSETS + @enumToInt(optional_action), @ptrToInt(termios_p));
1632}1632}
16331633
1634pub fn tcgetpgrp(fd: fd_t, pgrp: *pid_t) usize {
1635 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCGPGRP, @ptrToInt(pgrp));
1636}
1637
1638pub fn tcsetpgrp(fd: fd_t, pgrp: *const pid_t) usize {
1639 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCSPGRP, @ptrToInt(pgrp));
1640}
1641
1634pub fn tcdrain(fd: fd_t) usize {1642pub fn tcdrain(fd: fd_t) usize {
1635 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSBRK, 1);1643 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSBRK, 1);
1636}1644}