From: Christian Göttsche Date: Mon, 11 Dec 2023 16:32:13 +0000 (+0100) Subject: Update close(2) checking X-Git-Tag: 4.15.0-rc1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdb2490ab69103938182eba737a52af79b3d2cc5;p=thirdparty%2Fshadow.git Update close(2) checking Check for close(2) failure at more places closing a file descriptor written to. Also ignore failures with errno set to EINTR (see man:close(2) for details). --- diff --git a/lib/copydir.c b/lib/copydir.c index c485088ba..d61902524 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -814,7 +814,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, } (void) close (ifd); - if (close (ofd) != 0) { + if (close (ofd) != 0 && errno != EINTR) { return -1; } diff --git a/lib/idmapping.c b/lib/idmapping.c index 3fcad8d3c..83ab745bf 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -222,6 +222,10 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings log_get_progname(), map_file, strerror(errno)); exit(EXIT_FAILURE); } - close(fd); + if (close(fd) != 0 && errno != EINTR) { + fprintf(log_get_logfd(), _("%s: closing %s failed: %s\n"), + log_get_progname(), map_file, strerror(errno)); + exit(EXIT_FAILURE); + } free(buf); } diff --git a/src/useradd.c b/src/useradd.c index 3b20e56ff..9a7037f95 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2041,7 +2041,7 @@ static void faillog_reset (uid_t uid) Prog, (unsigned long) uid, strerror (errno)); SYSLOG ((LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid)); } - if (close (fd) != 0) { + if (close (fd) != 0 && errno != EINTR) { fprintf (stderr, _("%s: failed to close the faillog file for UID %lu: %s\n"), Prog, (unsigned long) uid, strerror (errno)); @@ -2087,7 +2087,7 @@ static void lastlog_reset (uid_t uid) SYSLOG ((LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid)); /* continue */ } - if (close (fd) != 0) { + if (close (fd) != 0 && errno != EINTR) { fprintf (stderr, _("%s: failed to close the lastlog file for UID %lu: %s\n"), Prog, (unsigned long) uid, strerror (errno)); @@ -2442,8 +2442,12 @@ static void create_mail (void) perror(_("Setting mailbox file permissions")); } - fsync(fd); - close(fd); + if (fsync(fd) != 0) { + perror (_("Synchronize mailbox file")); + } + if (close(fd) != 0 && errno != EINTR) { + perror (_("Closing mailbox file")); + } #ifdef WITH_SELINUX /* Reset SELinux to create files with default contexts */ if (reset_selinux_file_context() != 0) { diff --git a/src/usermod.c b/src/usermod.c index 9cbc504c2..285c2636d 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -1963,7 +1963,11 @@ static void update_lastlog (void) } } - (void) close (fd); + if (close (fd) != 0 && errno != EINTR) { + fprintf (stderr, + _("%s: failed to copy the lastlog entry of user %ju to user %ju: %s\n"), + Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerror (errno)); + } } #endif /* ENABLE_LASTLOG */ @@ -2023,7 +2027,11 @@ static void update_faillog (void) } } - (void) close (fd); + if (close (fd) != 0 && errno != EINTR) { + fprintf (stderr, + _("%s: failed to copy the faillog entry of user %ju to user %ju: %s\n"), + Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerror (errno)); + } } #ifndef NO_MOVE_MAILBOX