1- use crate :: backend ;
2- use crate :: process :: Pid ;
1+ use crate :: process :: { Gid , Pid , Uid } ;
2+ use crate :: { backend , io } ;
33
44/// `gettid()`—Returns the thread ID.
55///
@@ -15,3 +15,53 @@ use crate::process::Pid;
1515pub fn gettid ( ) -> Pid {
1616 backend:: thread:: syscalls:: gettid ( )
1717}
18+
19+ /// `setuid(uid)`
20+ ///
21+ /// # Warning
22+ ///
23+ /// This is not the setxid you are looking for... POSIX requires xids to be
24+ /// process granular, but on Linux they are per-thread. Thus, this call only
25+ /// changes the xid for the current *thread*, not the entire process even though
26+ /// that is in violation of the POSIX standard.
27+ ///
28+ /// For details on this distinction, see the C library vs. kernel differences in
29+ /// the [man page][linux_notes]. This call implements the kernel behavior.
30+ ///
31+ /// # References
32+ /// - [POSIX]
33+ /// - [Linux]
34+ ///
35+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setuid.html
36+ /// [Linux]: https://man7.org/linux/man-pages/man2/setuid.2.html
37+ /// [linux_notes]: https://man7.org/linux/man-pages/man2/setuid.2.html#NOTES
38+ #[ inline]
39+ #[ must_use]
40+ pub fn set_thread_uid ( uid : Uid ) -> io:: Result < ( ) > {
41+ backend:: thread:: syscalls:: setuid_thread ( uid)
42+ }
43+
44+ /// `setgid(gid)`
45+ ///
46+ /// # Warning
47+ ///
48+ /// This is not the setxid you are looking for... POSIX requires xids to be
49+ /// process granular, but on Linux they are per-thread. Thus, this call only
50+ /// changes the xid for the current *thread*, not the entire process even though
51+ /// that is in violation of the POSIX standard.
52+ ///
53+ /// For details on this distinction, see the C library vs. kernel differences in
54+ /// the [man page][linux_notes]. This call implements the kernel behavior.
55+ ///
56+ /// # References
57+ /// - [POSIX]
58+ /// - [Linux]
59+ ///
60+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setgid.html
61+ /// [Linux]: https://man7.org/linux/man-pages/man2/setgid.2.html
62+ /// [linux_notes]: https://man7.org/linux/man-pages/man2/setgid.2.html#NOTES
63+ #[ inline]
64+ #[ must_use]
65+ pub fn set_thread_gid ( gid : Gid ) -> io:: Result < ( ) > {
66+ backend:: thread:: syscalls:: setgid_thread ( gid)
67+ }
0 commit comments