Blame sysdeps/unix/sysv/linux/grantpt.c
|
Packit |
6c4009 |
#include <assert.h>
|
|
Packit |
6c4009 |
#include <ctype.h>
|
|
Packit |
6c4009 |
#include <dirent.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <fcntl.h>
|
|
Packit |
6c4009 |
#include <paths.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <not-cancel.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "pty-private.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if HAVE_PT_CHOWN
|
|
Packit |
6c4009 |
/* Close all file descriptors except the one specified. */
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
close_all_fds (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
DIR *dir = __opendir ("/proc/self/fd");
|
|
Packit |
6c4009 |
if (dir != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct dirent64 *d;
|
|
Packit |
6c4009 |
while ((d = __readdir64 (dir)) != NULL)
|
|
Packit |
6c4009 |
if (isdigit (d->d_name[0]))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char *endp;
|
|
Packit |
6c4009 |
long int fd = strtol (d->d_name, &endp, 10);
|
|
Packit |
6c4009 |
if (*endp == '\0' && fd != PTY_FILENO && fd != dirfd (dir))
|
|
Packit |
6c4009 |
__close_nocancel_nostatus (fd);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__closedir (dir);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int nullfd = __open_nocancel (_PATH_DEVNULL, O_RDONLY);
|
|
Packit |
6c4009 |
assert (nullfd == STDIN_FILENO);
|
|
Packit |
6c4009 |
nullfd = __open_nocancel (_PATH_DEVNULL, O_WRONLY);
|
|
Packit |
6c4009 |
assert (nullfd == STDOUT_FILENO);
|
|
Packit |
6c4009 |
__dup2 (STDOUT_FILENO, STDERR_FILENO);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
# define CLOSE_ALL_FDS() close_all_fds()
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdeps/unix/grantpt.c>
|