login: add callback for close_range()
Let's make it more robust for old kernels where is no close_range() or in cases when it's unsuccessful. Reported-by: Florian Weimer <fweimer@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
650fca1a06
commit
a3d73c246f
|
@ -91,9 +91,7 @@ static inline int close_range(unsigned int first, unsigned int last, int flags)
|
|||
# endif /* SYS_close_range */
|
||||
#endif /* __linux__ */
|
||||
|
||||
#ifndef HAVE_CLOSE_RANGE
|
||||
extern void ul_close_all_fds(unsigned int first, unsigned int last);
|
||||
#endif
|
||||
|
||||
#define UL_COPY_READ_ERROR (-1)
|
||||
#define UL_COPY_WRITE_ERROR (-2)
|
||||
|
|
|
@ -129,7 +129,6 @@ unsigned int get_fd_tabsize(void)
|
|||
return m;
|
||||
}
|
||||
|
||||
#ifndef HAVE_CLOSE_RANGE
|
||||
void ul_close_all_fds(unsigned int first, unsigned int last)
|
||||
{
|
||||
struct dirent *d;
|
||||
|
@ -166,7 +165,6 @@ void ul_close_all_fds(unsigned int first, unsigned int last)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_PROGRAM_FILEUTILS
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -189,10 +187,10 @@ int main(int argc, char *argv[])
|
|||
ignore_result( dup(STDIN_FILENO) );
|
||||
|
||||
# ifdef HAVE_CLOSE_RANGE
|
||||
close_range(STDERR_FILENO + 1, ~0U, 0);
|
||||
# else
|
||||
ul_close_all_fds(STDERR_FILENO + 1, ~0U);
|
||||
if (close_range(STDERR_FILENO + 1, ~0U, 0) < 0)
|
||||
# endif
|
||||
ul_close_all_fds(STDERR_FILENO + 1, ~0U);
|
||||
|
||||
} else if (strcmp(argv[1], "--copy-file") == 0) {
|
||||
int ret = ul_copy_file(STDIN_FILENO, STDOUT_FILENO);
|
||||
if (ret == UL_COPY_READ_ERROR)
|
||||
|
|
|
@ -1357,10 +1357,9 @@ static void initialize(int argc, char **argv, struct login_context *cxt)
|
|||
#endif
|
||||
}
|
||||
#ifdef HAVE_CLOSE_RANGE
|
||||
close_range(STDERR_FILENO + 1, ~0U, 0);
|
||||
#else
|
||||
ul_close_all_fds(STDERR_FILENO + 1, ~0U);
|
||||
if (close_range(STDERR_FILENO + 1, ~0U, 0) < 0)
|
||||
#endif
|
||||
ul_close_all_fds(STDERR_FILENO + 1, ~0U);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue