#ifdef HAVE_CONFIG_H #include #endif #include #include "../internal/syscall.h" /* Foreground-process-group ioctls (x86_64 _IO/_IOR derivations). */ #define VLIBC_PROC_TIOCGPGRP 0x540F #define VLIBC_PROC_TIOCSPGRP 0x5410 /* * Process group and session control (POSIX base): setpgid, getpgrp, * setsid. The XSI/obsolescent extras (setpgrp, getpgid, getsid, * tcgetpgrp, tcsetpgrp) are gated at level 2 below. */ /* * setpgid: move pid (0 = the caller) into process group pgid (0 = pid's * own value). A process can change groups for itself and its children; * session leaders cannot change groups. */ int setpgid(pid_t pid, pid_t pgid) { return syscall_ret(__syscall2(SYS_setpgid, pid, pgid)); } /* * getpgrp: the caller's process group. */ pid_t getpgrp(void) { return (pid_t)syscall_ret(__syscall0(SYS_getpgrp)); } /* * setsid: make the caller the leader of a new session and process group, * detaching it from the controlling terminal. Returns the new session id * (the caller's pid), or -1 with errno EPERM when the caller is already * a process group leader. */ pid_t setsid(void) { return (pid_t)syscall_ret(__syscall0(SYS_setsid)); } #if VLIBC_LEVEL_GE(2) /* Level 2 (muslmimic): XSI and obsolescent session extras. */ /* * setpgrp (obsolescent): setpgid(0, 0) — the caller becomes the leader * of its own process group. */ int setpgrp(void) { return setpgid(0, 0); } /* * getpgid (XSI): the process group of pid (0 = the caller). */ pid_t getpgid(pid_t pid) { return (pid_t)syscall_ret(__syscall1(SYS_getpgid, pid)); } /* * getsid (XSI): the session id of pid (0 = the caller). */ pid_t getsid(pid_t pid) { return (pid_t)syscall_ret(__syscall1(SYS_getsid, pid)); } /* * tcgetpgrp (XSI): the foreground process group of the terminal on * fildes, or -1 with errno set (ENOTTY when fildes is not a terminal). */ pid_t tcgetpgrp(int fildes) { int pgrp = 0; if (syscall_ret(__syscall3(SYS_ioctl, fildes, VLIBC_PROC_TIOCGPGRP, (long)&pgrp)) < 0) { return (pid_t)-1; } return (pid_t)pgrp; } /* * tcsetpgrp (XSI): make pgid the foreground process group of the * terminal on fildes. */ int tcsetpgrp(int fildes, pid_t pgid) { return syscall_ret(__syscall3(SYS_ioctl, fildes, VLIBC_PROC_TIOCSPGRP, pgid)); } #endif /* VLIBC_LEVEL_GE(2) */