1 /* Acquire ownership of the slave side of a pseudo-terminal.
2 Copyright (C) 1998-2002, 2009-2010 Free Software Foundation, Inc.
3 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 # include <sys/types.h>
30 # include <sys/time.h>
31 # include <sys/resource.h>
34 #include "configmake.h"
35 #include "pty-private.h"
38 # define __builtin_expect(expr,val) (expr)
39 # define __set_errno(e) errno = (e)
42 # define __setrlimit setrlimit
43 # define __waitpid waitpid
49 /* This function is most often called from a process without 'root'
50 credentials. Use the helper program. */
52 pid_t pid = __fork ();
57 /* This is executed in the child process. */
59 #if HAVE_SETRLIMIT && defined RLIMIT_CORE
60 /* Disable core dumps. */
61 struct rlimit rl = { 0, 0 };
62 __setrlimit (RLIMIT_CORE, &rl);
65 /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */
67 if (__dup2 (fd, PTY_FILENO) < 0)
74 execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, NULL, NULL);
81 if (__waitpid (pid, &w, 0) == -1)
84 __set_errno (ENOEXEC);
86 switch (WEXITSTATUS (w))
101 __set_errno (ENOEXEC);
104 __set_errno (ENOMEM);
108 assert(! "getpt: internal error: invalid exit code from pt_chown");