annotate lib/grantpt.c @ 40169:ecb43221748b

strtod, strtold: Work around HP-UX 11.31/ia64 bug. * lib/strtod.c (STRTOD): When there is an extra character after the exponent marker 'p', reparse the number. * doc/posix-functions/strtod.texi: Document the HP-UX 11.31 bug. * doc/posix-functions/strtold.texi: Likewise.
author Bruno Haible <bruno@clisp.org>
date Fri, 01 Feb 2019 00:18:57 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Acquire ownership of the slave side of a pseudo-terminal.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 1998-2002, 2009-2019 Free Software Foundation, Inc.
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <stdlib.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <assert.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <string.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <sys/wait.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <unistd.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #if HAVE_SETRLIMIT
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 # include <sys/types.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 # include <sys/time.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 # include <sys/resource.h>
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #endif
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include "configmake.h"
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include "pty-private.h"
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #ifndef _LIBC
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 # define __set_errno(e) errno = (e)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # define __dup2 dup2
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 # define __fork fork
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 # define __setrlimit setrlimit
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 # define __waitpid waitpid
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #endif
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 int
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 grantpt (int fd)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 {
18035
674bd7704497 fix pty related tests issues on Windows
Pavel Fedin <p.fedin@samsung.com>
parents: 17848
diff changeset
48 #if defined __OpenBSD__ || defined _WIN32
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
49 /* On OpenBSD, master and slave of a pseudo-terminal are allocated together,
18035
674bd7704497 fix pty related tests issues on Windows
Pavel Fedin <p.fedin@samsung.com>
parents: 17848
diff changeset
50 through an ioctl on /dev/ptm. On Windows there are no ptys.
674bd7704497 fix pty related tests issues on Windows
Pavel Fedin <p.fedin@samsung.com>
parents: 17848
diff changeset
51 Therefore in either case there is no need for grantpt(). */
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
52 return 0;
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
53 #else
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 /* This function is most often called from a process without 'root'
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 credentials. Use the helper program. */
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 int retval = -1;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 pid_t pid = __fork ();
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 if (pid == -1)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 goto cleanup;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 else if (pid == 0)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 {
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* This is executed in the child process. */
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
64 # if HAVE_SETRLIMIT && defined RLIMIT_CORE
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Disable core dumps. */
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 struct rlimit rl = { 0, 0 };
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 __setrlimit (RLIMIT_CORE, &rl);
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
68 # endif
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 if (fd != PTY_FILENO)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 if (__dup2 (fd, PTY_FILENO) < 0)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 _exit (FAIL_EBADF);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
75 # ifdef CLOSE_ALL_FDS
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 CLOSE_ALL_FDS ();
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
77 # endif
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, NULL, NULL);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 _exit (FAIL_EXEC);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 }
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 else
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 {
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 int w;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 if (__waitpid (pid, &w, 0) == -1)
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 goto cleanup;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 if (!WIFEXITED (w))
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 __set_errno (ENOEXEC);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 else
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 switch (WEXITSTATUS (w))
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 case 0:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 retval = 0;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 case FAIL_EBADF:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 __set_errno (EBADF);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 case FAIL_EINVAL:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 __set_errno (EINVAL);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 case FAIL_EACCES:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 __set_errno (EACCES);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 case FAIL_EXEC:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 __set_errno (ENOEXEC);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 case FAIL_ENOMEM:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 __set_errno (ENOMEM);
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 break;
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 default:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 assert(! "getpt: internal error: invalid exit code from pt_chown");
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 }
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 }
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 cleanup:
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 return retval;
15976
e4144dcb6f45 posix_openpt: Support for OpenBSD.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
119 #endif
13028
12650cb16dc5 New module 'grantpt'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 }