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).
This commit is contained in:
committed by
Serge Hallyn
parent
92b889b671
commit
cdb2490ab6
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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);
|
||||
}
|
||||
|
||||
+8
-4
@@ -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) {
|
||||
|
||||
+10
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user