Mercurial > gnulib
annotate lib/passfd.c @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
1 /* Copyright (C) 2011-2019 Free Software Foundation, Inc. |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
2 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
3 This program is free software: you can redistribute it and/or modify |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
4 it under the terms of the GNU General Public License as published by |
14420
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
5 the Free Software Foundation; either version 3 of the License, or |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
6 (at your option) any later version. |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
7 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
8 This program is distributed in the hope that it will be useful, |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
9 but WITHOUT ANY WARRANTY; without even the implied warranty of |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
11 GNU General Public License for more details. |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
12 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
19190 | 14 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
15 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
16 #include <config.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
17 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
18 /* Specification. */ |
14420
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
19 #include "passfd.h" |
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
20 |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
21 #include <errno.h> |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
22 #include <fcntl.h> |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
23 #include <stddef.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
24 #include <stdlib.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
25 #include <string.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
26 #include <sys/types.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
27 #include <unistd.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
28 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
29 #include <sys/socket.h> |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
30 |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
31 #include "cloexec.h" |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
32 |
14663 | 33 /* The code that uses CMSG_FIRSTHDR is enabled on |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
34 Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, AIX, OSF/1, Cygwin. |
14663 | 35 The code that uses HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS is enabled on |
36 HP-UX, IRIX, Solaris. */ | |
37 | |
38 /* MSG_CMSG_CLOEXEC is defined only on Linux, as of 2011. */ | |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
39 #ifndef MSG_CMSG_CLOEXEC |
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
40 # define MSG_CMSG_CLOEXEC 0 |
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
41 #endif |
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
42 |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
43 #if HAVE_SENDMSG |
14420
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
44 /* sendfd sends the file descriptor fd along the socket |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
45 to a process calling recvfd on the other end. |
14420
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
46 |
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
47 Return 0 on success, or -1 with errno set in case of error. |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
48 */ |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
49 int |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
50 sendfd (int sock, int fd) |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
51 { |
14626
0f3fba4a62b1
passfd: avoid compiler warning
Eric Blake <eblake@redhat.com>
parents:
14600
diff
changeset
|
52 char byte = 0; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
53 struct iovec iov; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
54 struct msghdr msg; |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
55 # ifdef CMSG_FIRSTHDR |
14510 | 56 struct cmsghdr *cmsg; |
57 char buf[CMSG_SPACE (sizeof fd)]; | |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
58 # endif |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
59 |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
60 /* send at least one char */ |
14508
6bacc85ddf06
passfd: fix incorrect sendmsg arguments
Eric Blake <eblake@redhat.com>
parents:
14427
diff
changeset
|
61 memset (&msg, 0, sizeof msg); |
14626
0f3fba4a62b1
passfd: avoid compiler warning
Eric Blake <eblake@redhat.com>
parents:
14600
diff
changeset
|
62 iov.iov_base = &byte; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
63 iov.iov_len = 1; |
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
64 msg.msg_iov = &iov; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
65 msg.msg_iovlen = 1; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
66 msg.msg_name = NULL; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
67 msg.msg_namelen = 0; |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
68 |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
69 # ifdef CMSG_FIRSTHDR |
14510 | 70 msg.msg_control = buf; |
71 msg.msg_controllen = sizeof buf; | |
72 cmsg = CMSG_FIRSTHDR (&msg); | |
73 cmsg->cmsg_level = SOL_SOCKET; | |
74 cmsg->cmsg_type = SCM_RIGHTS; | |
75 cmsg->cmsg_len = CMSG_LEN (sizeof fd); | |
76 /* Initialize the payload: */ | |
77 memcpy (CMSG_DATA (cmsg), &fd, sizeof fd); | |
17934
b4da4a9fe406
passfd: avoid valgrind uninitalised data warning
Pavel Hrdina <phrdina@redhat.com>
parents:
17848
diff
changeset
|
78 msg.msg_controllen = cmsg->cmsg_len; |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
79 # elif HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS |
14510 | 80 msg.msg_accrights = &fd; |
81 msg.msg_accrightslen = sizeof fd; | |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
82 # else |
14510 | 83 errno = ENOSYS; |
84 return -1; | |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
85 # endif |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
86 |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
87 if (sendmsg (sock, &msg, 0) != iov.iov_len) |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
88 return -1; |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
89 return 0; |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
90 } |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
91 #else |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
92 int |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
93 sendfd (int sock _GL_UNUSED, int fd _GL_UNUSED) |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
94 { |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
95 errno = ENOSYS; |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
96 return -1; |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
97 } |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
98 #endif |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
99 |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
100 |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
101 #if HAVE_RECVMSG |
14420
08622275f761
passfd module, part 2, tweaks.
Bruno Haible <bruno@clisp.org>
parents:
14419
diff
changeset
|
102 /* recvfd receives a file descriptor through the socket. |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
103 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>). |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
104 |
17014
dac0cd2e8030
passfd: fix comment on recvfd
Eric Blake <eblake@redhat.com>
parents:
16935
diff
changeset
|
105 Return the fd on success, or -1 with errno set in case of error. |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
106 */ |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
107 int |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
108 recvfd (int sock, int flags) |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
109 { |
14626
0f3fba4a62b1
passfd: avoid compiler warning
Eric Blake <eblake@redhat.com>
parents:
14600
diff
changeset
|
110 char byte = 0; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
111 struct iovec iov; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
112 struct msghdr msg; |
14510 | 113 int fd = -1; |
17573
c67bafa8ca26
passfd: give nicer error for recvfd at eof
Eric Blake <eblake@redhat.com>
parents:
17249
diff
changeset
|
114 ssize_t len; |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
115 # ifdef CMSG_FIRSTHDR |
14510 | 116 struct cmsghdr *cmsg; |
117 char buf[CMSG_SPACE (sizeof fd)]; | |
118 int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0; | |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
119 # endif |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
120 |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
121 if ((flags & ~O_CLOEXEC) != 0) |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
122 { |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
123 errno = EINVAL; |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
124 return -1; |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
125 } |
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
126 |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
127 /* send at least one char */ |
14510 | 128 memset (&msg, 0, sizeof msg); |
14626
0f3fba4a62b1
passfd: avoid compiler warning
Eric Blake <eblake@redhat.com>
parents:
14600
diff
changeset
|
129 iov.iov_base = &byte; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
130 iov.iov_len = 1; |
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
131 msg.msg_iov = &iov; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
132 msg.msg_iovlen = 1; |
14509
509ee86b2306
passfd: standardize coding conventions
Eric Blake <eblake@redhat.com>
parents:
14508
diff
changeset
|
133 msg.msg_name = NULL; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
134 msg.msg_namelen = 0; |
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
135 |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
136 # ifdef CMSG_FIRSTHDR |
14510 | 137 msg.msg_control = buf; |
138 msg.msg_controllen = sizeof buf; | |
139 cmsg = CMSG_FIRSTHDR (&msg); | |
140 cmsg->cmsg_level = SOL_SOCKET; | |
141 cmsg->cmsg_type = SCM_RIGHTS; | |
142 cmsg->cmsg_len = CMSG_LEN (sizeof fd); | |
143 /* Initialize the payload: */ | |
144 memcpy (CMSG_DATA (cmsg), &fd, sizeof fd); | |
145 msg.msg_controllen = cmsg->cmsg_len; | |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
146 |
17573
c67bafa8ca26
passfd: give nicer error for recvfd at eof
Eric Blake <eblake@redhat.com>
parents:
17249
diff
changeset
|
147 len = recvmsg (sock, &msg, flags_recvmsg); |
c67bafa8ca26
passfd: give nicer error for recvfd at eof
Eric Blake <eblake@redhat.com>
parents:
17249
diff
changeset
|
148 if (len < 0) |
14510 | 149 return -1; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
150 |
14510 | 151 cmsg = CMSG_FIRSTHDR (&msg); |
152 /* be paranoiac */ | |
17573
c67bafa8ca26
passfd: give nicer error for recvfd at eof
Eric Blake <eblake@redhat.com>
parents:
17249
diff
changeset
|
153 if (len == 0 || cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd) |
14510 | 154 || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) |
155 { | |
156 /* fake errno: at end the file is not available */ | |
17573
c67bafa8ca26
passfd: give nicer error for recvfd at eof
Eric Blake <eblake@redhat.com>
parents:
17249
diff
changeset
|
157 errno = len ? EACCES : ENOTCONN; |
14510 | 158 return -1; |
159 } | |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
160 |
14510 | 161 memcpy (&fd, CMSG_DATA (cmsg), sizeof fd); |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
162 |
14510 | 163 /* set close-on-exec flag */ |
164 if (!MSG_CMSG_CLOEXEC && (flags & O_CLOEXEC)) | |
165 { | |
166 if (set_cloexec_flag (fd, true) < 0) | |
167 { | |
168 int saved_errno = errno; | |
169 (void) close (fd); | |
170 errno = saved_errno; | |
171 return -1; | |
172 } | |
173 } | |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
174 |
14600
f57a9fcc777a
passfd: speed up configure and drop unused code
Eric Blake <eblake@redhat.com>
parents:
14599
diff
changeset
|
175 # elif HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS |
14510 | 176 msg.msg_accrights = &fd; |
177 msg.msg_accrightslen = sizeof fd; | |
178 if (recvmsg (sock, &msg, 0) < 0) | |
179 return -1; | |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
180 |
14510 | 181 /* set close-on-exec flag */ |
182 if (flags & O_CLOEXEC) | |
183 { | |
184 if (set_cloexec_flag (fd, true) < 0) | |
185 { | |
186 int saved_errno = errno; | |
187 close (fd); | |
188 errno = saved_errno; | |
189 return -1; | |
190 } | |
191 } | |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
192 # else |
14510 | 193 errno = ENOSYS; |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
194 # endif |
14421
f23a6a383241
passfd module, part 3.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
14420
diff
changeset
|
195 |
14510 | 196 return fd; |
14419
236edbfecf1d
passfd module, part 2.
Bastien Roucariès <roucaries.bastien@gmail.com>
parents:
diff
changeset
|
197 } |
14599
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
198 #else |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
199 int |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
200 recvfd (int sock _GL_UNUSED, int flags _GL_UNUSED) |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
201 { |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
202 errno = ENOSYS; |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
203 return -1; |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
204 } |
2a40136b85ae
passfd: allow compilation on mingw
Eric Blake <eblake@redhat.com>
parents:
14510
diff
changeset
|
205 #endif |