X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fgrantpt.c;h=b757044ca5675a1cc8196c5db1ca498f1733e496;hb=a76da24458afd3758386c60ab5c0bed4e100509e;hp=985e31d5fc2ae0ee72ab619a2d7c6a5ed449ba9e;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/grantpt.c b/lib/grantpt.c index 985e31d5f..b757044ca 100644 --- a/lib/grantpt.c +++ b/lib/grantpt.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -46,6 +47,13 @@ int grantpt (int fd) { +#if defined __OpenBSD__ + /* On OpenBSD, master and slave of a pseudo-terminal are allocated together, + through an ioctl on /dev/ptm. There is no need for grantpt(). */ + if (fcntl (fd, F_GETFD) < 0) + return -1; + return 0; +#else /* This function is most often called from a process without 'root' credentials. Use the helper program. */ int retval = -1; @@ -56,20 +64,20 @@ grantpt (int fd) { /* This is executed in the child process. */ -#if HAVE_SETRLIMIT && defined RLIMIT_CORE +# if HAVE_SETRLIMIT && defined RLIMIT_CORE /* Disable core dumps. */ struct rlimit rl = { 0, 0 }; __setrlimit (RLIMIT_CORE, &rl); -#endif +# endif /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */ if (fd != PTY_FILENO) if (__dup2 (fd, PTY_FILENO) < 0) _exit (FAIL_EBADF); -#ifdef CLOSE_ALL_FDS +# ifdef CLOSE_ALL_FDS CLOSE_ALL_FDS (); -#endif +# endif execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, NULL, NULL); _exit (FAIL_EXEC); @@ -111,4 +119,5 @@ grantpt (int fd) cleanup: return retval; +#endif }