diff options
| author | Alejandro Colomar <alx@kernel.org> | 2025-08-19 17:48:50 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2025-08-20 18:14:03 +0200 |
| commit | 0e7a39804a3c017a209117fc2243c6cbb543dede (patch) | |
| tree | 91e0b287d8b826d668c3d8118347f07cc8b8964a /man/man3/posix_spawn.3 | |
| parent | e2d3f14fe40ad90a1fedf0fcd27e6cc896c49a7a (diff) | |
| download | man-pages-0e7a39804a3c.tar.gz | |
man/: EXAMPLES: Use err(3) and errc(3bsd) instead of similar macros
These functions are quite portable. And if one doesn't have them for
some reason (but libbsd has been ported to many systems), one can write
them easily as macros, anyway.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'man/man3/posix_spawn.3')
| -rw-r--r-- | man/man3/posix_spawn.3 | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/man/man3/posix_spawn.3 b/man/man3/posix_spawn.3 index c4c5b3c96a..852cb58616 100644 --- a/man/man3/posix_spawn.3 +++ b/man/man3/posix_spawn.3 @@ -655,6 +655,7 @@ Child status: exited, status=127 \& .\" SRC BEGIN (posix_spawn.c) .EX +#include <err.h> #include <errno.h> #include <spawn.h> #include <stdint.h> @@ -664,13 +665,6 @@ Child status: exited, status=127 #include <unistd.h> #include <wait.h> \& -#define errExit(msg) do { perror(msg); \[rs] - exit(EXIT_FAILURE); } while (0) -\& -#define errExitEN(en, msg) \[rs] - do { errno = en; perror(msg); \[rs] - exit(EXIT_FAILURE); } while (0) -\& char **environ; \& int @@ -699,12 +693,12 @@ main(int argc, char *argv[]) \& s = posix_spawn_file_actions_init(&file_actions); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_init"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_init"); \& s = posix_spawn_file_actions_addclose(&file_actions, STDOUT_FILENO); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_addclose"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_addclose"); \& file_actionsp = &file_actions; break; @@ -716,15 +710,15 @@ main(int argc, char *argv[]) \& s = posix_spawnattr_init(&attr); if (s != 0) - errExitEN(s, "posix_spawnattr_init"); + errc(EXIT_FAILURE, s, "posix_spawnattr_init"); s = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK); if (s != 0) - errExitEN(s, "posix_spawnattr_setflags"); + errc(EXIT_FAILURE, s, "posix_spawnattr_setflags"); \& sigfillset(&mask); s = posix_spawnattr_setsigmask(&attr, &mask); if (s != 0) - errExitEN(s, "posix_spawnattr_setsigmask"); + errc(EXIT_FAILURE, s, "posix_spawnattr_setsigmask"); \& attrp = &attr; break; @@ -744,20 +738,20 @@ main(int argc, char *argv[]) s = posix_spawnp(&child_pid, argv[optind], file_actionsp, attrp, &argv[optind], environ); if (s != 0) - errExitEN(s, "posix_spawn"); + errc(EXIT_FAILURE, s, "posix_spawn"); \& /* Destroy any objects that we created earlier. */ \& if (attrp != NULL) { s = posix_spawnattr_destroy(attrp); if (s != 0) - errExitEN(s, "posix_spawnattr_destroy"); + errc(EXIT_FAILURE, s, "posix_spawnattr_destroy"); } \& if (file_actionsp != NULL) { s = posix_spawn_file_actions_destroy(file_actionsp); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_destroy"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_destroy"); } \& printf("PID of child: %jd\[rs]n", (intmax_t) child_pid); @@ -767,7 +761,7 @@ main(int argc, char *argv[]) do { s = waitpid(child_pid, &status, WUNTRACED | WCONTINUED); if (s == \-1) - errExit("waitpid"); + err(EXIT_FAILURE, "waitpid"); \& printf("Child status: "); if (WIFEXITED(status)) { |
