]> git.pld-linux.org Git - packages/autofs.git/blame - autofs-5.0.4-use-CLOEXEC-flag.patch
- import latest patchset.
[packages/autofs.git] / autofs-5.0.4-use-CLOEXEC-flag.patch
CommitLineData
e5fd101c
PS
1autofs-5.0.4 - use CLOEXEC flag
2
3From: Ian Kent <raven@themaw.net>
4
5Update autofs to use the new CLOEXEC flag if present.
6This allows us to set close on exec atomically flag when opening files,
7hopefully avoiding selinux complaining about leaked file handles.
8---
9
10 CHANGELOG | 1
11 daemon/automount.c | 42 ++++--------------
12 daemon/direct.c | 2 -
13 daemon/flag.c | 8 ++-
14 daemon/indirect.c | 2 -
15 daemon/lookup.c | 1
16 daemon/module.c | 2 -
17 daemon/spawn.c | 11 +----
18 include/automount.h | 106 +++++++++++++++++++++++++++++++++++++++++++++
19 include/state.h | 1
20 lib/cache.c | 2 -
21 lib/defaults.c | 7 ++-
22 lib/dev-ioctl-lib.c | 17 +------
23 lib/log.c | 2 -
24 lib/macros.c | 1
25 lib/mounts.c | 2 -
26 lib/nss_parse.y | 13 +-----
27 lib/parse_subs.c | 1
28 lib/rpc_subs.c | 21 ++-------
29 modules/cyrus-sasl.c | 1
30 modules/lookup_file.c | 40 +++--------------
31 modules/lookup_hesiod.c | 1
32 modules/lookup_hosts.c | 1
33 modules/lookup_ldap.c | 1
34 modules/lookup_multi.c | 1
35 modules/lookup_nisplus.c | 1
36 modules/lookup_program.c | 5 +-
37 modules/lookup_userhome.c | 1
38 modules/lookup_yp.c | 1
39 modules/mount_afs.c | 2 -
40 modules/mount_autofs.c | 2 -
41 modules/mount_bind.c | 2 -
42 modules/mount_changer.c | 10 ----
43 modules/mount_ext2.c | 2 -
44 modules/mount_generic.c | 2 -
45 modules/mount_nfs.c | 2 -
46 modules/parse_hesiod.c | 1
47 modules/parse_sun.c | 2 -
48 modules/replicated.c | 13 +-----
49 39 files changed, 149 insertions(+), 184 deletions(-)
50
51
52diff --git a/CHANGELOG b/CHANGELOG
53index bd35b00..43f3205 100644
54--- a/CHANGELOG
55+++ b/CHANGELOG
56@@ -3,6 +3,7 @@
57 - fix dumb libxml2 check
58 - fix nested submount expire deadlock.
59 - fix negative caching for non-existent map keys.
60+- use CLOEXEC flag.
61
62 4/11/2008 autofs-5.0.4
63 -----------------------
64diff --git a/daemon/automount.c b/daemon/automount.c
65index 6f078c1..e120f50 100644
66--- a/daemon/automount.c
67+++ b/daemon/automount.c
68@@ -20,13 +20,11 @@
69 * ----------------------------------------------------------------------- */
70
71 #include <dirent.h>
72-#include <fcntl.h>
73 #include <getopt.h>
74 #include <signal.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78-#include <unistd.h>
79 #include <sys/ioctl.h>
80 #include <ctype.h>
81 #include <sys/types.h>
82@@ -68,6 +66,9 @@ static pthread_t state_mach_thid;
83 /* Pre-calculated kernel packet length */
84 static size_t kpkt_len;
85
86+/* Does kernel know about SOCK_CLOEXEC and friends */
87+static int cloexec_works = 0;
88+
89 /* Attribute to create detached thread */
90 pthread_attr_t thread_attr;
91
92@@ -671,7 +672,7 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
93 static int create_logpri_fifo(struct autofs_point *ap)
94 {
95 int ret = -1;
96- int fd, cl_flags;
97+ int fd;
98 char *fifo_name;
99 char buf[MAX_ERR_BUF];
100
101@@ -697,7 +698,7 @@ static int create_logpri_fifo(struct autofs_point *ap)
102 goto out_free;
103 }
104
105- fd = open(fifo_name, O_RDWR|O_NONBLOCK);
106+ fd = open_fd(fifo_name, O_RDWR|O_NONBLOCK);
107 if (fd < 0) {
108 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
109 crit(ap->logopt,
110@@ -707,11 +708,6 @@ static int create_logpri_fifo(struct autofs_point *ap)
111 goto out_free;
112 }
113
114- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
115- cl_flags |= FD_CLOEXEC;
116- fcntl(fd, F_SETFD, cl_flags);
117- }
118-
119 ap->logpri_fifo = fd;
120
121 out_free:
122@@ -963,7 +959,7 @@ int do_expire(struct autofs_point *ap, const char *name, int namelen)
123
124 static int autofs_init_ap(struct autofs_point *ap)
125 {
126- int pipefd[2], cl_flags;
127+ int pipefd[2];
128
129 if ((ap->state != ST_INIT)) {
130 /* This can happen if an autofs process is already running*/
131@@ -974,7 +970,7 @@ static int autofs_init_ap(struct autofs_point *ap)
132 ap->pipefd = ap->kpipefd = ap->ioctlfd = -1;
133
134 /* Pipe for kernel communications */
135- if (pipe(pipefd) < 0) {
136+ if (open_pipe(pipefd) < 0) {
137 crit(ap->logopt,
138 "failed to create commumication pipe for autofs path %s",
139 ap->path);
140@@ -984,18 +980,8 @@ static int autofs_init_ap(struct autofs_point *ap)
141 ap->pipefd = pipefd[0];
142 ap->kpipefd = pipefd[1];
143
144- if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
145- cl_flags |= FD_CLOEXEC;
146- fcntl(ap->pipefd, F_SETFD, cl_flags);
147- }
148-
149- if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
150- cl_flags |= FD_CLOEXEC;
151- fcntl(ap->kpipefd, F_SETFD, cl_flags);
152- }
153-
154 /* Pipe state changes from signal handler to main loop */
155- if (pipe(ap->state_pipe) < 0) {
156+ if (open_pipe(ap->state_pipe) < 0) {
157 crit(ap->logopt,
158 "failed create state pipe for autofs path %s", ap->path);
159 close(ap->pipefd);
160@@ -1003,16 +989,6 @@ static int autofs_init_ap(struct autofs_point *ap)
161 return -1;
162 }
163
164- if ((cl_flags = fcntl(ap->state_pipe[0], F_GETFD, 0)) != -1) {
165- cl_flags |= FD_CLOEXEC;
166- fcntl(ap->state_pipe[0], F_SETFD, cl_flags);
167- }
168-
169- if ((cl_flags = fcntl(ap->state_pipe[1], F_GETFD, 0)) != -1) {
170- cl_flags |= FD_CLOEXEC;
171- fcntl(ap->state_pipe[1], F_SETFD, cl_flags);
172- }
173-
174 if (create_logpri_fifo(ap) < 0) {
175 logmsg("could not create FIFO for path %s\n", ap->path);
176 logmsg("dynamic log level changes not available for %s", ap->path);
177@@ -1080,7 +1056,7 @@ static void become_daemon(unsigned foreground, unsigned daemon_check)
178 exit(0);
179 }
180
181- if (pipe(start_pipefd) < 0) {
182+ if (open_pipe(start_pipefd) < 0) {
183 fprintf(stderr, "%s: failed to create start_pipefd.\n",
184 program);
185 exit(0);
186diff --git a/daemon/direct.c b/daemon/direct.c
187index 98fcc07..c0243c4 100644
188--- a/daemon/direct.c
189+++ b/daemon/direct.c
190@@ -21,12 +21,10 @@
191
192 #include <dirent.h>
193 #include <libgen.h>
194-#include <fcntl.h>
195 #include <signal.h>
196 #include <stdio.h>
197 #include <stdlib.h>
198 #include <string.h>
199-#include <unistd.h>
200 #include <sys/ioctl.h>
201 #include <sys/types.h>
202 #include <sys/wait.h>
203diff --git a/daemon/flag.c b/daemon/flag.c
204index d8ca61b..e43cece 100644
205--- a/daemon/flag.c
206+++ b/daemon/flag.c
207@@ -21,15 +21,15 @@
208 #include <sys/time.h>
209 #include <sys/types.h>
210 #include <sys/stat.h>
211-#include <fcntl.h>
212 #include <time.h>
213-#include <unistd.h>
214 #include <string.h>
215 #include <alloca.h>
216 #include <stdio.h>
217 #include <signal.h>
218 #include <errno.h>
219
220+#include "automount.h"
221+
222 #define MAX_PIDSIZE 20
223 #define FLAG_FILE AUTOFS_FLAG_DIR "/autofs-running"
224
225@@ -129,7 +129,7 @@ int aquire_flag_file(void)
226 while (!we_created_flagfile) {
227 int errsv, i, j;
228
229- i = open(linkf, O_WRONLY|O_CREAT, 0);
230+ i = open_fd_mode(linkf, O_WRONLY|O_CREAT, 0);
231 if (i < 0) {
232 release_flag_file();
233 return 0;
234@@ -146,7 +146,7 @@ int aquire_flag_file(void)
235 return 0;
236 }
237
238- fd = open(FLAG_FILE, O_RDWR);
239+ fd = open_fd(FLAG_FILE, O_RDWR);
240 if (fd < 0) {
241 /* Maybe the file was just deleted? */
242 if (errno == ENOENT)
243diff --git a/daemon/indirect.c b/daemon/indirect.c
244index 1232810..9d3745c 100644
245--- a/daemon/indirect.c
246+++ b/daemon/indirect.c
247@@ -21,12 +21,10 @@
248
249 #include <dirent.h>
250 #include <libgen.h>
251-#include <fcntl.h>
252 #include <signal.h>
253 #include <stdio.h>
254 #include <stdlib.h>
255 #include <string.h>
256-#include <unistd.h>
257 #include <sys/ioctl.h>
258 #include <sys/types.h>
259 #include <sys/wait.h>
260diff --git a/daemon/lookup.c b/daemon/lookup.c
261index 0cf6e3f..741d846 100644
262--- a/daemon/lookup.c
263+++ b/daemon/lookup.c
264@@ -22,7 +22,6 @@
265 #include <stdio.h>
266 #include <string.h>
267 #include <sys/stat.h>
268-#include <unistd.h>
269 #include "automount.h"
270 #include "nsswitch.h"
271
272diff --git a/daemon/module.c b/daemon/module.c
273index 36eca00..e593d75 100644
274--- a/daemon/module.c
275+++ b/daemon/module.c
276@@ -31,7 +31,7 @@ int load_autofs4_module(void)
277 * is an older version we will catch it at mount
278 * time.
279 */
280- fp = fopen("/proc/filesystems", "r");
281+ fp = open_fopen_r("/proc/filesystems");
282 if (!fp) {
283 logerr("cannot open /proc/filesystems\n");
284 return 0;
285diff --git a/daemon/spawn.c b/daemon/spawn.c
286index 17f92f4..4ddf46f 100644
287--- a/daemon/spawn.c
288+++ b/daemon/spawn.c
289@@ -13,7 +13,6 @@
290 *
291 * ----------------------------------------------------------------------- */
292
293-#include <fcntl.h>
294 #include <signal.h>
295 #include <stdarg.h>
296 #include <stdio.h>
297@@ -21,7 +20,6 @@
298 #include <string.h>
299 #include <sys/types.h>
300 #include <dirent.h>
301-#include <unistd.h>
302 #include <time.h>
303 #include <sys/wait.h>
304 #include <sys/stat.h>
305@@ -125,7 +123,7 @@ static int do_spawn(unsigned logopt, unsigned int wait,
306 int ret, status, pipefd[2];
307 char errbuf[ERRBUFSIZ + 1], *p, *sp;
308 int errp, errn;
309- int flags, cancel_state;
310+ int cancel_state;
311 unsigned int use_lock = options & SPAWN_OPT_LOCK;
312 unsigned int use_access = options & SPAWN_OPT_ACCESS;
313 sigset_t allsigs, tmpsig, oldsig;
314@@ -133,7 +131,7 @@ static int do_spawn(unsigned logopt, unsigned int wait,
315 pid_t euid = 0;
316 gid_t egid = 0;
317
318- if (pipe(pipefd))
319+ if (open_pipe(pipefd))
320 return -1;
321
322 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
323@@ -213,11 +211,6 @@ static int do_spawn(unsigned logopt, unsigned int wait,
324 return -1;
325 }
326
327- if ((flags = fcntl(pipefd[0], F_GETFD, 0)) != -1) {
328- flags |= FD_CLOEXEC;
329- fcntl(pipefd[0], F_SETFD, flags);
330- }
331-
332 errp = 0;
333 do {
334 errn = timed_read(pipefd[0],
335diff --git a/include/automount.h b/include/automount.h
336index 1ba0d3c..a55ddbc 100644
337--- a/include/automount.h
338+++ b/include/automount.h
339@@ -17,6 +17,8 @@
340 #include <pthread.h>
341 #include <sched.h>
342 #include <errno.h>
343+#include <unistd.h>
344+#include <fcntl.h>
345 #include "config.h"
346 #include "list.h"
347
348@@ -475,5 +477,109 @@ int alarm_start_handler(void);
349 int alarm_add(struct autofs_point *ap, time_t seconds);
350 void alarm_delete(struct autofs_point *ap);
351
352+/*
353+ * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
354+ * socket() if possible.
355+ */
356+static int cloexec_works;
357+
358+static inline void check_cloexec(int fd)
359+{
360+ if (cloexec_works == 0) {
361+ int fl = fcntl(fd, F_GETFD);
362+ cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
363+ }
364+ if (cloexec_works > 0)
365+ return;
366+ fcntl(fd, F_SETFD, FD_CLOEXEC);
367+ return;
368+}
369+
370+static inline int open_fd(const char *path, int flags)
371+{
372+ int fd;
373+
374+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
375+ if (cloexec_works != -1)
376+ flags |= O_CLOEXEC;
377+#endif
378+ fd = open(path, flags);
379+ if (fd == -1)
380+ return -1;
381+ check_cloexec(fd);
382+ return fd;
383+}
384+
385+static inline int open_fd_mode(const char *path, int flags, int mode)
386+{
387+ int fd;
388+
389+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
390+ if (cloexec_works != -1)
391+ flags |= O_CLOEXEC;
392+#endif
393+ fd = open(path, flags, mode);
394+ if (fd == -1)
395+ return -1;
396+ check_cloexec(fd);
397+ return fd;
398+}
399+
400+static inline int open_pipe(int pipefd[2])
401+{
402+ int ret;
403+
404+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(__have_pipe2)
405+ if (cloexec_works != -1) {
406+ ret = pipe2(pipefd, O_CLOEXEC);
407+ if (ret != -1)
408+ return 0;
409+ if (errno != EINVAL)
410+ return -1;
411+ }
412+#endif
413+ ret = pipe(pipefd);
414+ if (ret == -1)
415+ return -1;
416+ check_cloexec(pipefd[0]);
417+ check_cloexec(pipefd[1]);
418+ return 0;
419+}
420+
421+static inline int open_sock(int domain, int type, int protocol)
422+{
423+ int fd;
424+
425+#ifdef SOCK_CLOEXEC
426+ if (cloexec_works != -1)
427+ type |= SOCK_CLOEXEC;
428+#endif
429+ fd = socket(domain, type, protocol);
430+ if (fd == -1)
431+ return -1;
432+ check_cloexec(fd);
433+ return fd;
434+}
435+
436+static inline FILE *open_fopen_r(const char *path)
437+{
438+ FILE *f;
439+
440+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
441+ if (cloexec_works != -1) {
442+ f = fopen(path, "re");
443+ if (f != NULL) {
444+ check_cloexec(fileno(f));
445+ return f;
446+ }
447+ }
448+#endif
449+ f = fopen(path, "r");
450+ if (f == NULL)
451+ return NULL;
452+ check_cloexec(fileno(f));
453+ return f;
454+}
455+
456 #endif
457
458diff --git a/include/state.h b/include/state.h
459index d7349d9..b44a353 100644
460--- a/include/state.h
461+++ b/include/state.h
462@@ -20,7 +20,6 @@
463 #ifndef STATE_H
464 #define STATE_H
465
466-#include <unistd.h>
467 #include <string.h>
468 #include <stdlib.h>
469 #include <signal.h>
470diff --git a/lib/cache.c b/lib/cache.c
471index ce47e04..4a00367 100644
472--- a/lib/cache.c
473+++ b/lib/cache.c
474@@ -17,10 +17,8 @@
475 #include <malloc.h>
476 #include <stdlib.h>
477 #include <string.h>
478-#include <unistd.h>
479 #include <ctype.h>
480 #include <stdio.h>
481-#include <fcntl.h>
482 #include <sys/param.h>
483 #include <sys/types.h>
484 #include <sys/stat.h>
485diff --git a/lib/defaults.c b/lib/defaults.c
486index 21d76d2..ff653e3 100644
487--- a/lib/defaults.c
488+++ b/lib/defaults.c
489@@ -21,6 +21,7 @@
490 #include "defaults.h"
491 #include "lookup_ldap.h"
492 #include "log.h"
493+#include "automount.h"
494
495 #define DEFAULTS_CONFIG_FILE AUTOFS_CONF_DIR "/autofs"
496 #define MAX_LINE_LEN 256
497@@ -255,7 +256,7 @@ struct list_head *defaults_get_uris(void)
498 char *res;
499 struct list_head *list;
500
501- f = fopen(DEFAULTS_CONFIG_FILE, "r");
502+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
503 if (!f)
504 return NULL;
505
506@@ -298,7 +299,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
507 char buf[MAX_LINE_LEN];
508 char *res;
509
510- f = fopen(DEFAULTS_CONFIG_FILE, "r");
511+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
512 if (!f)
513 return 0;
514
515@@ -544,7 +545,7 @@ struct ldap_searchdn *defaults_get_searchdns(void)
516 char *res;
517 struct ldap_searchdn *sdn, *last;
518
519- f = fopen(DEFAULTS_CONFIG_FILE, "r");
520+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
521 if (!f)
522 return NULL;
523
524diff --git a/lib/dev-ioctl-lib.c b/lib/dev-ioctl-lib.c
525index 57af785..056a0a9 100644
526--- a/lib/dev-ioctl-lib.c
527+++ b/lib/dev-ioctl-lib.c
528@@ -121,17 +121,12 @@ void init_ioctl_ctl(void)
529 if (ctl.ops)
530 return;
531
532- devfd = open(CONTROL_DEVICE, O_RDONLY);
533+ devfd = open_fd(CONTROL_DEVICE, O_RDONLY);
534 if (devfd == -1)
535 ctl.ops = &ioctl_ops;
536 else {
537 struct autofs_dev_ioctl param;
538
539- int cl_flags = fcntl(devfd, F_GETFD, 0);
540- if (cl_flags != -1) {
541- cl_flags |= FD_CLOEXEC;
542- fcntl(devfd, F_SETFD, cl_flags);
543- }
544 /*
545 * Check compile version against kernel.
546 * Selinux may allow us to open the device but not
547@@ -378,20 +373,14 @@ static int ioctl_open(unsigned int logopt,
548 int *ioctlfd, dev_t devid, const char *path)
549 {
550 struct statfs sfs;
551- int save_errno, fd, cl_flags;
552+ int save_errno, fd;
553
554 *ioctlfd = -1;
555
556- fd = open(path, O_RDONLY);
557+ fd = open_fd(path, O_RDONLY);
558 if (fd == -1)
559 return -1;
560
561- cl_flags = fcntl(fd, F_GETFD, 0);
562- if (cl_flags != -1) {
563- cl_flags |= FD_CLOEXEC;
564- fcntl(fd, F_SETFD, cl_flags);
565- }
566-
567 if (fstatfs(fd, &sfs) == -1) {
568 save_errno = errno;
569 goto err;
570diff --git a/lib/log.c b/lib/log.c
571index 65e8ad2..46220fd 100644
572--- a/lib/log.c
573+++ b/lib/log.c
574@@ -20,8 +20,6 @@
575
576 #include <stdarg.h>
577 #include <stdio.h>
578-#include <unistd.h>
579-#include <fcntl.h>
580 #include <stdlib.h>
581 #include <string.h>
582
583diff --git a/lib/macros.c b/lib/macros.c
584index fa6db8e..85f9cd3 100644
585--- a/lib/macros.c
586+++ b/lib/macros.c
587@@ -14,7 +14,6 @@
588 * ----------------------------------------------------------------------- */
589
590 #include <malloc.h>
591-#include <unistd.h>
592 #include <stdlib.h>
593 #include <string.h>
594 #include <limits.h>
595diff --git a/lib/mounts.c b/lib/mounts.c
596index 6d0a69c..ce4691b 100644
597--- a/lib/mounts.c
598+++ b/lib/mounts.c
599@@ -14,13 +14,11 @@
600
601 #include <stdlib.h>
602 #include <string.h>
603-#include <unistd.h>
604 #include <mntent.h>
605 #include <limits.h>
606 #include <sys/types.h>
607 #include <sys/stat.h>
608 #include <sys/ioctl.h>
609-#include <fcntl.h>
610 #include <sys/mount.h>
611 #include <stdio.h>
612 #include <dirent.h>
613diff --git a/lib/nss_parse.y b/lib/nss_parse.y
614index fa6958a..3bda6b3 100644
615--- a/lib/nss_parse.y
616+++ b/lib/nss_parse.y
617@@ -22,8 +22,6 @@
618 #include <stdlib.h>
619 #include <string.h>
620 #include <memory.h>
621-#include <unistd.h>
622-#include <fcntl.h>
623 #include <limits.h>
624
625 #include "automount.h"
626@@ -164,9 +162,9 @@ static void parse_close_nsswitch(void *arg)
627 int nsswitch_parse(struct list_head *list)
628 {
629 FILE *nsswitch;
630- int fd, cl_flags, status;
631+ int status;
632
633- nsswitch = fopen(NSSWITCH_FILE, "r");
634+ nsswitch = open_fopen_r(NSSWITCH_FILE);
635 if (!nsswitch) {
636 logerr("couldn't open %s\n", NSSWITCH_FILE);
637 return 1;
638@@ -174,13 +172,6 @@ int nsswitch_parse(struct list_head *list)
639
640 pthread_cleanup_push(parse_close_nsswitch, nsswitch);
641
642- fd = fileno(nsswitch);
643-
644- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
645- cl_flags |= FD_CLOEXEC;
646- fcntl(fd, F_SETFD, cl_flags);
647- }
648-
649 parse_mutex_lock();
650 pthread_cleanup_push(parse_mutex_unlock, NULL);
651
652diff --git a/lib/parse_subs.c b/lib/parse_subs.c
653index 3a04dd6..8a032e8 100644
654--- a/lib/parse_subs.c
655+++ b/lib/parse_subs.c
656@@ -18,7 +18,6 @@
657 #include <stdlib.h>
658 #include <string.h>
659 #include <ctype.h>
660-#include <unistd.h>
661 #include "automount.h"
662
663 /*
664diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
665index 6be86c6..9ac3657 100644
666--- a/lib/rpc_subs.c
667+++ b/lib/rpc_subs.c
668@@ -21,13 +21,11 @@
669 #include <rpc/rpc.h>
670 #include <rpc/pmap_prot.h>
671
672-#include <unistd.h>
673 #include <sys/socket.h>
674 #include <netdb.h>
675 #include <net/if.h>
676 #include <netinet/in.h>
677 #include <arpa/inet.h>
678-#include <sys/fcntl.h>
679 #include <rpcsvc/ypclnt.h>
680 #include <errno.h>
681 #include <sys/ioctl.h>
682@@ -36,6 +34,7 @@
683
684 #include "mount.h"
685 #include "rpc_subs.h"
686+#include "automount.h"
687
688 /* #define STANDALONE */
689 #ifdef STANDALONE
690@@ -59,7 +58,7 @@ inline void dump_core(void);
691 */
692 static CLIENT *create_udp_client(struct conn_info *info)
693 {
694- int fd, cl_flags, ret, ghn_errno;
695+ int fd, ret, ghn_errno;
696 CLIENT *client;
697 struct sockaddr_in laddr, raddr;
698 struct hostent hp;
699@@ -115,15 +114,10 @@ got_addr:
700 * layer, it would bind to a reserved port, which has been shown
701 * to exhaust the reserved port range in some situations.
702 */
703- fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
704+ fd = open_sock(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
705 if (fd < 0)
706 return NULL;
707
708- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
709- cl_flags |= FD_CLOEXEC;
710- fcntl(fd, F_SETFD, cl_flags);
711- }
712-
713 laddr.sin_family = AF_INET;
714 laddr.sin_port = 0;
715 laddr.sin_addr.s_addr = htonl(INADDR_ANY);
716@@ -274,7 +268,7 @@ done:
717 */
718 static CLIENT *create_tcp_client(struct conn_info *info)
719 {
720- int fd, cl_flags, ghn_errno;
721+ int fd, ghn_errno;
722 CLIENT *client;
723 struct sockaddr_in addr;
724 struct hostent hp;
725@@ -324,15 +318,10 @@ got_addr:
726 addr.sin_port = htons(info->port);
727
728 if (!info->client) {
729- fd = socket(PF_INET, SOCK_STREAM, info->proto->p_proto);
730+ fd = open_sock(PF_INET, SOCK_STREAM, info->proto->p_proto);
731 if (fd < 0)
732 return NULL;
733
734- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
735- cl_flags |= FD_CLOEXEC;
736- fcntl(fd, F_SETFD, cl_flags);
737- }
738-
739 ret = connect_nb(fd, &addr, &info->timeout);
740 if (ret < 0)
741 goto out_close;
742diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c
743index 902d9aa..286af15 100644
744--- a/modules/cyrus-sasl.c
745+++ b/modules/cyrus-sasl.c
746@@ -51,7 +51,6 @@
747 #include <stdio.h>
748 #include <stdlib.h>
749 #include <string.h>
750-#include <unistd.h>
751 #include <ldap.h>
752 #include <sasl/sasl.h>
753
754diff --git a/modules/lookup_file.c b/modules/lookup_file.c
755index 9e34b72..95b9f6f 100644
756--- a/modules/lookup_file.c
757+++ b/modules/lookup_file.c
758@@ -17,8 +17,6 @@
759 #include <malloc.h>
760 #include <stdlib.h>
761 #include <string.h>
762-#include <unistd.h>
763-#include <fcntl.h>
764 #include <time.h>
765 #include <ctype.h>
766 #include <signal.h>
767@@ -395,7 +393,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
768 char *ent;
769 struct stat st;
770 FILE *f;
771- int fd, cl_flags;
772+ int fd;
773 unsigned int path_len, ent_len;
774 int entry, cur_state;
775
776@@ -422,7 +420,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
777 return NSS_STATUS_UNAVAIL;
778 }
779
780- f = fopen(ctxt->mapname, "r");
781+ f = open_fopen_r(ctxt->mapname);
782 if (!f) {
783 error(logopt,
784 MODPREFIX "could not open master map file %s",
785@@ -432,11 +430,6 @@ int lookup_read_master(struct master *master, time_t age, void *context)
786
787 fd = fileno(f);
788
789- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
790- cl_flags |= FD_CLOEXEC;
791- fcntl(fd, F_SETFD, cl_flags);
792- }
793-
794 while(1) {
795 entry = read_one(logopt, f, path, &path_len, ent, &ent_len);
796 if (!entry) {
797@@ -651,7 +644,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
798 char *mapent;
799 struct stat st;
800 FILE *f;
801- int fd, cl_flags;
802+ int fd;
803 unsigned int k_len, m_len;
804 int entry;
805
806@@ -684,7 +677,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
807 return NSS_STATUS_UNAVAIL;
808 }
809
810- f = fopen(ctxt->mapname, "r");
811+ f = open_fopen_r(ctxt->mapname);
812 if (!f) {
813 error(ap->logopt,
814 MODPREFIX "could not open map file %s", ctxt->mapname);
815@@ -693,11 +686,6 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
816
817 fd = fileno(f);
818
819- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
820- cl_flags |= FD_CLOEXEC;
821- fcntl(fd, F_SETFD, cl_flags);
822- }
823-
824 while(1) {
825 entry = read_one(ap->logopt, f, key, &k_len, mapent, &m_len);
826 if (!entry) {
827@@ -784,7 +772,6 @@ static int lookup_one(struct autofs_point *ap,
828 char mapent[MAPENT_MAX_LEN + 1];
829 time_t age = time(NULL);
830 FILE *f;
831- int fd, cl_flags;
832 unsigned int k_len, m_len;
833 int entry, ret;
834
835@@ -794,20 +781,13 @@ static int lookup_one(struct autofs_point *ap,
836
837 mc = source->mc;
838
839- f = fopen(ctxt->mapname, "r");
840+ f = open_fopen_r(ctxt->mapname);
841 if (!f) {
842 error(ap->logopt,
843 MODPREFIX "could not open map file %s", ctxt->mapname);
844 return CHE_FAIL;
845 }
846
847- fd = fileno(f);
848-
849- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
850- cl_flags |= FD_CLOEXEC;
851- fcntl(fd, F_SETFD, cl_flags);
852- }
853-
854 while(1) {
855 entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
856 if (entry) {
857@@ -897,7 +877,6 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
858 char mapent[MAPENT_MAX_LEN + 1];
859 time_t age = time(NULL);
860 FILE *f;
861- int fd, cl_flags;
862 unsigned int k_len, m_len;
863 int entry, ret;
864
865@@ -907,20 +886,13 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
866
867 mc = source->mc;
868
869- f = fopen(ctxt->mapname, "r");
870+ f = open_fopen_r(ctxt->mapname);
871 if (!f) {
872 error(ap->logopt,
873 MODPREFIX "could not open map file %s", ctxt->mapname);
874 return CHE_FAIL;
875 }
876
877- fd = fileno(f);
878-
879- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
880- cl_flags |= FD_CLOEXEC;
881- fcntl(fd, F_SETFD, cl_flags);
882- }
883-
884 while(1) {
885 entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
886 if (entry) {
887diff --git a/modules/lookup_hesiod.c b/modules/lookup_hesiod.c
888index 737a47e..0a2ee44 100644
889--- a/modules/lookup_hesiod.c
890+++ b/modules/lookup_hesiod.c
891@@ -10,7 +10,6 @@
892 #include <ctype.h>
893 #include <limits.h>
894 #include <string.h>
895-#include <unistd.h>
896 #include <stdlib.h>
897 #include <netinet/in.h>
898 #include <arpa/nameser.h>
899diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
900index f8d4269..93b975a 100644
901--- a/modules/lookup_hosts.c
902+++ b/modules/lookup_hosts.c
903@@ -15,7 +15,6 @@
904
905 #include <stdio.h>
906 #include <malloc.h>
907-#include <unistd.h>
908 #include <sys/param.h>
909 #include <sys/types.h>
910 #include <sys/stat.h>
911diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
912index 42c3235..6ba80eb 100644
913--- a/modules/lookup_ldap.c
914+++ b/modules/lookup_ldap.c
915@@ -21,7 +21,6 @@
916 #include <sys/stat.h>
917 #include <ctype.h>
918 #include <string.h>
919-#include <unistd.h>
920 #include <stdlib.h>
921 #include <time.h>
922 #include <signal.h>
923diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c
924index 601d48e..1bf2e0a 100644
925--- a/modules/lookup_multi.c
926+++ b/modules/lookup_multi.c
927@@ -18,7 +18,6 @@
928 #include <malloc.h>
929 #include <stdio.h>
930 #include <string.h>
931-#include <unistd.h>
932 #include <sys/stat.h>
933
934 #define MODULE_LOOKUP
935diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
936index f15465f..4c3ce60 100644
937--- a/modules/lookup_nisplus.c
938+++ b/modules/lookup_nisplus.c
939@@ -6,7 +6,6 @@
940
941 #include <stdio.h>
942 #include <malloc.h>
943-#include <unistd.h>
944 #include <sys/param.h>
945 #include <sys/types.h>
946 #include <signal.h>
947diff --git a/modules/lookup_program.c b/modules/lookup_program.c
948index bf32d3b..6f4e2a3 100644
949--- a/modules/lookup_program.c
950+++ b/modules/lookup_program.c
951@@ -18,7 +18,6 @@
952 #include <malloc.h>
953 #include <stdio.h>
954 #include <string.h>
955-#include <unistd.h>
956 #include <signal.h>
957 #include <sys/param.h>
958 #include <sys/stat.h>
959@@ -212,12 +211,12 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
960 * want to send stderr to the syslog, and we don't use spawnl()
961 * because we need the pipe hooks
962 */
963- if (pipe(pipefd)) {
964+ if (open_pipe(pipefd)) {
965 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
966 logerr(MODPREFIX "pipe: %s", estr);
967 goto out_free;
968 }
969- if (pipe(epipefd)) {
970+ if (open_pipe(epipefd)) {
971 close(pipefd[0]);
972 close(pipefd[1]);
973 goto out_free;
974diff --git a/modules/lookup_userhome.c b/modules/lookup_userhome.c
975index 680ddaf..fb3caaa 100644
976--- a/modules/lookup_userhome.c
977+++ b/modules/lookup_userhome.c
978@@ -16,7 +16,6 @@
979 #include <stdio.h>
980 #include <malloc.h>
981 #include <pwd.h>
982-#include <unistd.h>
983 #include <string.h>
984 #include <sys/param.h>
985 #include <sys/types.h>
986diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
987index 1b62f57..ce438e8 100644
988--- a/modules/lookup_yp.c
989+++ b/modules/lookup_yp.c
990@@ -16,7 +16,6 @@
991
992 #include <stdio.h>
993 #include <malloc.h>
994-#include <unistd.h>
995 #include <time.h>
996 #include <signal.h>
997 #include <ctype.h>
998diff --git a/modules/mount_afs.c b/modules/mount_afs.c
999index 96a1367..50628ce 100644
1000--- a/modules/mount_afs.c
1001+++ b/modules/mount_afs.c
1002@@ -9,8 +9,6 @@
1003
1004 #include <stdio.h>
1005 #include <malloc.h>
1006-#include <fcntl.h>
1007-#include <unistd.h>
1008 #include <string.h>
1009 #include <sys/param.h>
1010 #include <sys/types.h>
1011diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
1012index eb63d8e..82a5ef3 100644
1013--- a/modules/mount_autofs.c
1014+++ b/modules/mount_autofs.c
1015@@ -16,8 +16,6 @@
1016 #include <stdio.h>
1017 #include <stdlib.h>
1018 #include <malloc.h>
1019-#include <fcntl.h>
1020-#include <unistd.h>
1021 #include <string.h>
1022 #include <signal.h>
1023 #include <alloca.h>
1024diff --git a/modules/mount_bind.c b/modules/mount_bind.c
1025index 022d183..361f0c2 100644
1026--- a/modules/mount_bind.c
1027+++ b/modules/mount_bind.c
1028@@ -15,8 +15,6 @@
1029
1030 #include <stdio.h>
1031 #include <malloc.h>
1032-#include <fcntl.h>
1033-#include <unistd.h>
1034 #include <string.h>
1035 #include <stdlib.h>
1036 #include <sys/param.h>
1037diff --git a/modules/mount_changer.c b/modules/mount_changer.c
1038index 43b8355..92bb72b 100644
1039--- a/modules/mount_changer.c
1040+++ b/modules/mount_changer.c
1041@@ -19,8 +19,6 @@
1042
1043 #include <stdio.h>
1044 #include <malloc.h>
1045-#include <fcntl.h>
1046-#include <unistd.h>
1047 #include <string.h>
1048 #include <sys/param.h>
1049 #include <sys/types.h>
1050@@ -145,25 +143,19 @@ int swapCD(const char *device, const char *slotName)
1051 {
1052 int fd; /* file descriptor for CD-ROM device */
1053 int status; /* return status for system calls */
1054- int cl_flags;
1055 int slot = -1;
1056 int total_slots_available;
1057
1058 slot = atoi(slotName) - 1;
1059
1060 /* open device */
1061- fd = open(device, O_RDONLY | O_NONBLOCK);
1062+ fd = open_fd(device, O_RDONLY | O_NONBLOCK);
1063 if (fd < 0) {
1064 logerr(MODPREFIX "Opening device %s failed : %s",
1065 device, strerror(errno));
1066 return 1;
1067 }
1068
1069- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
1070- cl_flags |= FD_CLOEXEC;
1071- fcntl(fd, F_SETFD, cl_flags);
1072- }
1073-
1074 /* Check CD player status */
1075 total_slots_available = ioctl(fd, CDROM_CHANGER_NSLOTS);
1076 if (total_slots_available <= 1) {
1077diff --git a/modules/mount_ext2.c b/modules/mount_ext2.c
1078index 4c5b271..192ec04 100644
1079--- a/modules/mount_ext2.c
1080+++ b/modules/mount_ext2.c
1081@@ -15,8 +15,6 @@
1082
1083 #include <stdio.h>
1084 #include <malloc.h>
1085-#include <fcntl.h>
1086-#include <unistd.h>
1087 #include <string.h>
1088 #include <stdlib.h>
1089 #include <sys/param.h>
1090diff --git a/modules/mount_generic.c b/modules/mount_generic.c
1091index f094d07..6d7b4b3 100644
1092--- a/modules/mount_generic.c
1093+++ b/modules/mount_generic.c
1094@@ -15,8 +15,6 @@
1095
1096 #include <stdio.h>
1097 #include <malloc.h>
1098-#include <fcntl.h>
1099-#include <unistd.h>
1100 #include <string.h>
1101 #include <stdlib.h>
1102 #include <sys/param.h>
1103diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
1104index c747078..20732f8 100644
1105--- a/modules/mount_nfs.c
1106+++ b/modules/mount_nfs.c
1107@@ -17,8 +17,6 @@
1108 #include <stdio.h>
1109 #include <malloc.h>
1110 #include <netdb.h>
1111-#include <fcntl.h>
1112-#include <unistd.h>
1113 #include <stdlib.h>
1114 #include <string.h>
1115 #include <sys/param.h>
1116diff --git a/modules/parse_hesiod.c b/modules/parse_hesiod.c
1117index ff1f0a5..d5bb0f4 100644
1118--- a/modules/parse_hesiod.c
1119+++ b/modules/parse_hesiod.c
1120@@ -7,7 +7,6 @@
1121 #include <sys/types.h>
1122 #include <ctype.h>
1123 #include <string.h>
1124-#include <unistd.h>
1125 #include <stdlib.h>
1126 #include <netinet/in.h>
1127 #include <arpa/nameser.h>
1128diff --git a/modules/parse_sun.c b/modules/parse_sun.c
1129index 2c4f8b2..72e51e2 100644
1130--- a/modules/parse_sun.c
1131+++ b/modules/parse_sun.c
1132@@ -18,8 +18,6 @@
1133 #include <stdio.h>
1134 #include <malloc.h>
1135 #include <netdb.h>
1136-#include <fcntl.h>
1137-#include <unistd.h>
1138 #include <stdlib.h>
1139 #include <string.h>
1140 #include <ctype.h>
1141diff --git a/modules/replicated.c b/modules/replicated.c
1142index b435f4b..63829a2 100644
1143--- a/modules/replicated.c
1144+++ b/modules/replicated.c
1145@@ -52,8 +52,6 @@
1146 #include <net/if.h>
1147 #include <netinet/in.h>
1148 #include <netdb.h>
1149-#include <unistd.h>
1150-#include <fcntl.h>
1151
1152 #include "rpc_subs.h"
1153 #include "replicated.h"
1154@@ -82,7 +80,7 @@ void seed_random(void)
1155 int fd;
1156 unsigned int seed;
1157
1158- fd = open("/dev/urandom", O_RDONLY);
1159+ fd = open_fd("/dev/urandom", O_RDONLY);
1160 if (fd < 0) {
1161 srandom(time(NULL));
1162 return;
1163@@ -145,7 +143,7 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
1164 char tmp[20], buf[MAX_ERR_BUF], *ptr;
1165 struct ifconf ifc;
1166 struct ifreq *ifr, nmptr;
1167- int sock, cl_flags, ret, i;
1168+ int sock, ret, i;
1169 uint32_t mask, ha, ia;
1170
1171 memcpy(tmp, host_addr, addr_len);
1172@@ -153,18 +151,13 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
1173
1174 ha = ntohl((uint32_t) hst_addr->s_addr);
1175
1176- sock = socket(AF_INET, SOCK_DGRAM, 0);
1177+ sock = open_sock(AF_INET, SOCK_DGRAM, 0);
1178 if (sock < 0) {
1179 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1180 logerr("socket creation failed: %s", estr);
1181 return PROXIMITY_ERROR;
1182 }
1183
1184- if ((cl_flags = fcntl(sock, F_GETFD, 0)) != -1) {
1185- cl_flags |= FD_CLOEXEC;
1186- fcntl(sock, F_SETFD, cl_flags);
1187- }
1188-
1189 if (!alloc_ifreq(&ifc, sock)) {
1190 close(sock);
1191 return PROXIMITY_ERROR;
This page took 0.521779 seconds and 4 git commands to generate.