SETGID(3POSIX)

🌸 SETGID(3POSIX) β€” the POSIX Programmer's Manual, bestie edition 🌸

okay so real talk before we even start: this page lives inside the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go read the matching Linux manual page for the actual Linux tea β˜•), or the interface may not be implemented on Linux at all. Not me warning you upfront πŸ’…


✨ NAME ✨

setgid β€” set-group-ID. that's it, that's the whole name. short, iconic, does exactly what it says 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <unistd.h>

int setgid(gid_t gid);

πŸ’– DESCRIPTION πŸ’–

Okay so here's the deal. If the process has appropriate privileges, then setgid() shall set the real group ID, the effective group ID, and the saved set-group-ID of the calling process β€” all three of them, bestie β€” to gid. Three-for-one, ate that πŸ’…

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. lowkey a limited-edition version of the call but it's still slaying ✨

The setgid() function shall not affect the supplementary group list in any way. periodt.

Any supplementary group IDs of the calling process shall remain unchanged. (yes, same energy as the line above β€” they really wanted you to get it πŸ™ˆ)


πŸ‘‘ RETURN VALUE πŸ‘‘

Upon successful completion, 0 is returned. Otherwise, -1 shall be returned and errno set to indicate the error. so basically: 0 = we ate, -1 = we did not eat 😭


πŸ’€ ERRORS πŸ’€

The setgid() function shall fail if:

  • EINVAL β€” The value of the gid argument is invalid and is not supported by the implementation.
  • EPERM β€” The process does not have appropriate privileges and gid does not match the real group ID or the saved set-group-ID.
The following sections are informative. (so like, vibe check: read them, but they're not the normative stuff πŸŽ€)

🌈 EXAMPLES 🌈

None.

(genuinely nothing. no examples. we're all just out here raw-dogging the spec 🧚)


πŸ“ APPLICATION USAGE πŸ“

None.

(also nothing. two empty sections in a row and honestly? iconic minimalism.)


πŸ’œ RATIONALE πŸ’œ

Refer to the RATIONALE section in setuid(). that's it, that's the whole rationale β€” go read your sibling's homework bestie πŸ“š


⭐ FUTURE DIRECTIONS ⭐

None.

(no glow-up planned. this function is what it is and we respect it.)


πŸ”₯ SEE ALSO πŸ”₯

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

And from the Base Definitions volume of POSIX.1‐2017:

  • <sys_types.h>
  • <unistd.h>

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 πŸ’– shoutout to IEEE/The Open Group, 2017 β€” the year this legend got its stamp. no cap, we're done here. stay privileged, stay valid, and please check your errno πŸ«ΆπŸ’…βœ¨