SETGID(3P)

✨ SETGID(3P) β€” the group-ID glow-up ✨

okay bestie, so this one lives in the POSIX Programmer's Manual, and before we go ANY further you need to know the tea:

Heads up fr fr: this page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β€” so go check the corresponding Linux manual page for the deets on Linux behavior. Or the interface might just... not be implemented on Linux at all. πŸ’€

🌸 PROLOG 🌸

okay so real talk, this page comes from the POSIX Programmer's Manual. That means the Linux version of this interface can be different (so go peek at the matching Linux manual page for the actual Linux behavior), or it might not even exist on Linux. Either way, don't come for me, come for the Linux page. 🫢


πŸ’– NAME πŸ’–

setgid β€” set-group-ID. it's giving "change the group ID of a process" and it's iconic for it.


✨ SYNOPSIS ✨

#include <unistd.h>

int setgid(gid_t gid);

πŸ‘‘ DESCRIPTION πŸ‘‘

ok so here's the whole vibe. setgid() is gonna do different things depending on whether you have the power or not. main character energy, honestly.

  • If the process has appropriate privileges, setgid() shall set the real group ID, the effective group ID, and the saved set-group-ID of the calling process to gid. all three. at once. slay.
  • If the process does not have appropriate privileges, but gid is equal to the real group ID or the saved set-group-ID, then setgid() shall set the effective group ID to gid. The real group ID and the saved set-group-ID shall remain unchanged. so only one of the three gets touched, bestie, don't get it twisted.
  • The setgid() function shall not affect the supplementary group list in any way. literally none. zero. nada. πŸ™ˆ
  • Any supplementary group IDs of the calling process shall remain unchanged. same thing, said twice, because it matters that much. periodt.

🌈 RETURN VALUE 🌈

  • If it works? you get 0. clean. gorgeous. ate. πŸ’…
  • If it doesn't? you get -1, and errno gets set to tell you exactly what went wrong. it's giving "we need to talk".

πŸŽ€ ERRORS πŸŽ€

The setgid() function shall fail if:

  • EINVAL β€” The value of the gid argument is invalid and is not supported by the implementation. it's just not valid bestie, the implementation said no 🚫
  • EPERM β€” The process does not have appropriate privileges and gid does not match the real group ID or the saved set-group-ID. so you don't have the power AND you're not matching either of the two IDs you're allowed to match. double no. 😭
The following sections are informative. (translation: the next few bits are ✨context✨ not ✨rules✨)

πŸ¦‹ EXAMPLES πŸ¦‹

None. empty. a blank canvas. the audacity, honestly. πŸ’€


🌸 APPLICATION USAGE 🌸

None. also empty. matching energy. πŸŽ€


πŸ’œ RATIONALE πŸ’œ

Refer to the RATIONALE section in setuid(). yeah, this one's just a hand-off. go read that one, it has the lore. iykyk.


⭐ FUTURE DIRECTIONS ⭐

None. the future is... nothing. iconic in its own way.


πŸ”₯ SEE ALSO πŸ”₯

  • exec
  • getegid()
  • geteuid()
  • getgid()
  • getuid()
  • setegid()
  • seteuid()
  • setregid()
  • setreuid()
  • setuid()

Also, from the Base Definitions volume of POSIX.1‐2017: <sys_types.h> and <unistd.h>. go read those headers, they're right there. 🫢


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! this masterpiece was brought to you by IEEE/The Open Group, 2017 β€” yeah, 2017, she's been serving this information for a minute and she still ate πŸ’…βœ¨πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from