aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2024-07-20 12:28:00 +0200
committerAlejandro Colomar <alx@kernel.org>2024-07-20 12:55:42 +0200
commit9f353db4412b740ae8e66e590e47b69d09e6725d (patch)
tree265e21d2e29cde5a5ea6ad5a10043c2adef01f07
parentca5cb657979bd4c10fbfeb7ba87929adcab5e3c6 (diff)
downloadman-pages-9f353db4412b740ae8e66e590e47b69d09e6725d.tar.gz
getutent.3: EXAMPLES: Add missing error handling
Reported-by: gcc(1) (`make build-ex-cc`) Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man/man3/getutent.316
1 files changed, 11 insertions, 5 deletions
diff --git a/man/man3/getutent.3 b/man/man3/getutent.3
index 656a52cd26..b783f9f59a 100644
--- a/man/man3/getutent.3
+++ b/man/man3/getutent.3
@@ -308,6 +308,7 @@ and
.P
.\" SRC BEGIN (getutent.c)
.EX
+#include <err.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
@@ -320,7 +321,8 @@ main(void)
{
struct utmp entry;
\&
- system("echo before adding entry:;who");
+ if (system("echo before adding entry:;who") == \-1)
+ err(EXIT_FAILURE, "system");
\&
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
@@ -332,18 +334,22 @@ main(void)
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
- pututline(&entry);
+ if (pututline(&entry) == NULL)
+ err(EXIT_FAILURE, "pututline");
\&
- system("echo after adding entry:;who");
+ if (system("echo after adding entry:;who") == \-1)
+ err(EXIT_FAILURE, "system");
\&
entry.ut_type = DEAD_PROCESS;
memset(entry.ut_line, 0, UT_LINESIZE);
entry.ut_time = 0;
memset(entry.ut_user, 0, UT_NAMESIZE);
setutent();
- pututline(&entry);
+ if (pututline(&entry) == NULL)
+ err(EXIT_FAILURE, "pututline");
\&
- system("echo after removing entry:;who");
+ if (system("echo after removing entry:;who") == \-1)
+ err(EXIT_FAILURE, "system");
\&
endutent();
exit(EXIT_SUCCESS);