qlibs:(pathexec)

πŸ“¦ version 31, in alpine 3.24

πŸ’– NAME πŸ’–

okay so this is the glow-up of qlibs:(pathexec) 🫢 and the star of the page is pathexec β€” it literally runs a program within a given environment. bestie, it's giving "launch this program, but with the exact env you want" ✨

✨ SYNTAX ✨

#include "pathexec.h"

pathexec_run(const char *p,char **a,char **e);
pathexec(char *const *a);
pathexec_env(const char *s,char *t);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so pathexec_run searches for a program named p πŸ”Ž. then it replaces the current process with a copy of that program β€” like a full main-character takeover πŸ’…. the main function in that program will be given arguments a and environment e.

pathexec_run looks for p as specified by the $PATH environment variable. $PATH is a colon-separated list of directories d; pathexec_run tries execve on files named d/p, in the order that the directories appear inside $PATH. an empty directory name is treated as a single dot. periodt.

if $PATH is not set, pathexec_run uses the path /bin:/usr/bin; i.e., it tries execve on /bin/p, then /usr/bin/p. no cap.

if p contains a slash, pathexec_run ignores $PATH and simply runs execve on a file named p. slay, direct route πŸ›£οΈ.

pathexec calls pathexec_run with program name a[0], arguments a, and the same environment as the current process, modified as described below. pathexec has the same return behavior as pathexec_run.

pathexec_env modifies the environment used by pathexec. it removes a variable named s, if one exists. then it adds a variable named s with value t, if the pointer t is nonzero. the name s must not contain =. 🚨

πŸ”₯ RETURN CODES πŸ”₯

normally pathexec_run does not return, because the process has been replaced β€” it's gone, bye πŸ‘‹. however, if all the execve attempts fail, pathexec_run returns, setting errno to the most interesting error returned by execve.

furthermore, pathexec_run returns immediately if an execve attempt fails with an error other than error_noent, error_acces, error_perm, or error_isdir. this list is subject to change β€” so don't come for me if it shifts, bestie 😭.

normally pathexec_env returns 1. if it is unable to allocate memory, it returns 0, leaving the pathexec environment alone. lowkey important: that's a no-touch situation 🫢.

🌈 SEE ALSO 🌈

  • error(3) β€” go read that one too, iykyk πŸ’œ

cute sign-off: this page is from qlibs:(pathexec), section 3 ✨ mwah, bestie β€” go run something iconic πŸŽ€

πŸ“¦ where this page comes from