]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
man/man3/posix_spawn.3: EXAMPLES: Validate the number of arguments
authorDr. David Alan Gilbert <dave@treblig.org>
Mon, 18 Aug 2025 22:59:10 +0000 (23:59 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 19 Aug 2025 11:10:15 +0000 (13:10 +0200)
Make the example check for an executable name on the command line
rather than segfaulting in the child.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Message-ID: <20250818225910.101238-1-dave@treblig.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
man/man3/posix_spawn.3

index 3aaf3873e1ae3ce09c6b522774985598c8a199f5..c4c5b3c96ad987318801e0751d0ff4b8c9ac8fc3 100644 (file)
@@ -730,6 +730,11 @@ main(int argc, char *argv[])
             break;
         }
     }
+\&
+    if (argv[optind] == NULL) {
+        fprintf(stderr, "Usage: %s [\-cs] executable [args]\[rs]n", argv[0]);
+        exit(EXIT_FAILURE);
+    }
 \&
     /* Spawn the child. The name of the program to execute and the
        command\-line arguments are taken from the command\-line arguments