• POSIX system() function (was: The end of software secrecy ...)

    From Geoff Clare@3:633/10 to All on Thu Oct 29 14:26:52 2026
    Scott Lurndal wrote:

    Prior to 2017, POSIX didn't require that the system function
    invoke a shell, simply that it would execute an implementation defined command string. I must admit that I had pushed for the latter definition when part of the base working group for XPG5 (1994ish) (I was, at the time, working for Unisys for which POSIX support was being considered on the
    Large Systems line, which had no equivalent of the unix shell).

    You are misremembering POSIX/XPG/SUS history. The following is from the original POSIX.2-1992 standard (B.3.1.2 page 723):

    The system() function shall execute the command specified by the
    string pointed to by command. The environment of the executed
    command shall be as if a child process were created using the
    POSIX.1 {8} fork() function, and the child process invoked the sh
    utility (see 4.56) using the POSIX.1 {8} execl() function as follows:

    execl(<shell path>, "sh", "-c", command, (char ?)0);

    where <shell path> is an unspecified pathname for the sh utility.

    The same requirement was included in XPG4 and SUSv1 - SUSv4. In SUSv5 (POSIX.1-2024) it changed to:

    execl(<shell path>, "sh", "-c", "--", command, (char ?)0);

    so that if the command string begins with "-" it is not parsed as an
    option string.

    The only thing that was (and still is) unspecified is where the POSIX sh utility is located (e.g. on Solaris it was /usr/xpg4/bin/sh).

    Perhaps what you're thinking of is that in XPG4, SUSv1 and SUSv2 the requirement was conditional on the "Commands and Utilities" volume (XCU)
    of the standard being supported. It was possible to certify a system as conforming to only the C language stuff (XSH) in which case calling system(NULL) would return zero to indicate no command processor is
    available if XCU was not supported. This changed in SUSv3 (2001) when
    the conditional was removed and the requirement "The system() function
    shall always return non-zero when command is NULL" was added.

    --
    Geoff Clare <netnews@gclare.org.uk>

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)