1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 01UPSTREAM_autofs-5.0.4-use-CLOEXEC-flag.dpatch
7
autofs-5.0.4 - use CLOEXEC flag
9
From: Ian Kent <raven@themaw.net>
11
Update autofs to use the new CLOEXEC flag if present.
12
This allows us to set close on exec atomically flag when opening files,
13
hopefully avoiding selinux complaining about leaked file handles.
17
daemon/automount.c | 42 ++++--------------
20
daemon/indirect.c | 2 -
23
daemon/spawn.c | 11 +----
24
include/automount.h | 106 +++++++++++++++++++++++++++++++++++++++++++++
27
lib/defaults.c | 7 ++-
28
lib/dev-ioctl-lib.c | 17 +------
32
lib/nss_parse.y | 13 +-----
34
lib/rpc_subs.c | 21 ++-------
35
modules/cyrus-sasl.c | 1
36
modules/lookup_file.c | 40 +++--------------
37
modules/lookup_hesiod.c | 1
38
modules/lookup_hosts.c | 1
39
modules/lookup_ldap.c | 1
40
modules/lookup_multi.c | 1
41
modules/lookup_nisplus.c | 1
42
modules/lookup_program.c | 5 +-
43
modules/lookup_userhome.c | 1
44
modules/lookup_yp.c | 1
45
modules/mount_afs.c | 2 -
46
modules/mount_autofs.c | 2 -
47
modules/mount_bind.c | 2 -
48
modules/mount_changer.c | 10 ----
49
modules/mount_ext2.c | 2 -
50
modules/mount_generic.c | 2 -
51
modules/mount_nfs.c | 2 -
52
modules/parse_hesiod.c | 1
53
modules/parse_sun.c | 2 -
54
modules/replicated.c | 13 +-----
55
39 files changed, 149 insertions(+), 184 deletions(-)
58
diff --git a/CHANGELOG b/CHANGELOG
59
index bd35b00..43f3205 100644
63
- fix dumb libxml2 check
64
- fix nested submount expire deadlock.
65
- fix negative caching for non-existent map keys.
68
4/11/2008 autofs-5.0.4
69
-----------------------
70
diff --git a/daemon/automount.c b/daemon/automount.c
71
index 6f078c1..e120f50 100644
72
--- a/daemon/automount.c
73
+++ b/daemon/automount.c
75
* ----------------------------------------------------------------------- */
85
#include <sys/ioctl.h>
87
#include <sys/types.h>
88
@@ -68,6 +66,9 @@ static pthread_t state_mach_thid;
89
/* Pre-calculated kernel packet length */
90
static size_t kpkt_len;
92
+/* Does kernel know about SOCK_CLOEXEC and friends */
93
+static int cloexec_works = 0;
95
/* Attribute to create detached thread */
96
pthread_attr_t thread_attr;
98
@@ -671,7 +672,7 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
99
static int create_logpri_fifo(struct autofs_point *ap)
105
char buf[MAX_ERR_BUF];
107
@@ -697,7 +698,7 @@ static int create_logpri_fifo(struct autofs_point *ap)
111
- fd = open(fifo_name, O_RDWR|O_NONBLOCK);
112
+ fd = open_fd(fifo_name, O_RDWR|O_NONBLOCK);
114
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
116
@@ -707,11 +708,6 @@ static int create_logpri_fifo(struct autofs_point *ap)
120
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
121
- cl_flags |= FD_CLOEXEC;
122
- fcntl(fd, F_SETFD, cl_flags);
125
ap->logpri_fifo = fd;
128
@@ -963,7 +959,7 @@ int do_expire(struct autofs_point *ap, const char *name, int namelen)
130
static int autofs_init_ap(struct autofs_point *ap)
132
- int pipefd[2], cl_flags;
135
if ((ap->state != ST_INIT)) {
136
/* This can happen if an autofs process is already running*/
137
@@ -974,7 +970,7 @@ static int autofs_init_ap(struct autofs_point *ap)
138
ap->pipefd = ap->kpipefd = ap->ioctlfd = -1;
140
/* Pipe for kernel communications */
141
- if (pipe(pipefd) < 0) {
142
+ if (open_pipe(pipefd) < 0) {
144
"failed to create commumication pipe for autofs path %s",
146
@@ -984,18 +980,8 @@ static int autofs_init_ap(struct autofs_point *ap)
147
ap->pipefd = pipefd[0];
148
ap->kpipefd = pipefd[1];
150
- if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
151
- cl_flags |= FD_CLOEXEC;
152
- fcntl(ap->pipefd, F_SETFD, cl_flags);
155
- if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
156
- cl_flags |= FD_CLOEXEC;
157
- fcntl(ap->kpipefd, F_SETFD, cl_flags);
160
/* Pipe state changes from signal handler to main loop */
161
- if (pipe(ap->state_pipe) < 0) {
162
+ if (open_pipe(ap->state_pipe) < 0) {
164
"failed create state pipe for autofs path %s", ap->path);
166
@@ -1003,16 +989,6 @@ static int autofs_init_ap(struct autofs_point *ap)
170
- if ((cl_flags = fcntl(ap->state_pipe[0], F_GETFD, 0)) != -1) {
171
- cl_flags |= FD_CLOEXEC;
172
- fcntl(ap->state_pipe[0], F_SETFD, cl_flags);
175
- if ((cl_flags = fcntl(ap->state_pipe[1], F_GETFD, 0)) != -1) {
176
- cl_flags |= FD_CLOEXEC;
177
- fcntl(ap->state_pipe[1], F_SETFD, cl_flags);
180
if (create_logpri_fifo(ap) < 0) {
181
logmsg("could not create FIFO for path %s\n", ap->path);
182
logmsg("dynamic log level changes not available for %s", ap->path);
183
@@ -1080,7 +1056,7 @@ static void become_daemon(unsigned foreground, unsigned daemon_check)
187
- if (pipe(start_pipefd) < 0) {
188
+ if (open_pipe(start_pipefd) < 0) {
189
fprintf(stderr, "%s: failed to create start_pipefd.\n",
192
diff --git a/daemon/direct.c b/daemon/direct.c
193
index 98fcc07..c0243c4 100644
194
--- a/daemon/direct.c
195
+++ b/daemon/direct.c
206
#include <sys/ioctl.h>
207
#include <sys/types.h>
208
#include <sys/wait.h>
209
diff --git a/daemon/flag.c b/daemon/flag.c
210
index d8ca61b..e43cece 100644
214
#include <sys/time.h>
215
#include <sys/types.h>
216
#include <sys/stat.h>
226
+#include "automount.h"
228
#define MAX_PIDSIZE 20
229
#define FLAG_FILE AUTOFS_FLAG_DIR "/autofs-running"
231
@@ -129,7 +129,7 @@ int aquire_flag_file(void)
232
while (!we_created_flagfile) {
235
- i = open(linkf, O_WRONLY|O_CREAT, 0);
236
+ i = open_fd_mode(linkf, O_WRONLY|O_CREAT, 0);
240
@@ -146,7 +146,7 @@ int aquire_flag_file(void)
244
- fd = open(FLAG_FILE, O_RDWR);
245
+ fd = open_fd(FLAG_FILE, O_RDWR);
247
/* Maybe the file was just deleted? */
249
diff --git a/daemon/indirect.c b/daemon/indirect.c
250
index 1232810..9d3745c 100644
251
--- a/daemon/indirect.c
252
+++ b/daemon/indirect.c
263
#include <sys/ioctl.h>
264
#include <sys/types.h>
265
#include <sys/wait.h>
266
diff --git a/daemon/lookup.c b/daemon/lookup.c
267
index 0cf6e3f..741d846 100644
268
--- a/daemon/lookup.c
269
+++ b/daemon/lookup.c
273
#include <sys/stat.h>
275
#include "automount.h"
276
#include "nsswitch.h"
278
diff --git a/daemon/module.c b/daemon/module.c
279
index 36eca00..e593d75 100644
280
--- a/daemon/module.c
281
+++ b/daemon/module.c
282
@@ -31,7 +31,7 @@ int load_autofs4_module(void)
283
* is an older version we will catch it at mount
286
- fp = fopen("/proc/filesystems", "r");
287
+ fp = open_fopen_r("/proc/filesystems");
289
logerr("cannot open /proc/filesystems\n");
291
diff --git a/daemon/spawn.c b/daemon/spawn.c
292
index 17f92f4..4ddf46f 100644
297
* ----------------------------------------------------------------------- */
305
#include <sys/types.h>
309
#include <sys/wait.h>
310
#include <sys/stat.h>
311
@@ -125,7 +123,7 @@ static int do_spawn(unsigned logopt, unsigned int wait,
312
int ret, status, pipefd[2];
313
char errbuf[ERRBUFSIZ + 1], *p, *sp;
315
- int flags, cancel_state;
317
unsigned int use_lock = options & SPAWN_OPT_LOCK;
318
unsigned int use_access = options & SPAWN_OPT_ACCESS;
319
sigset_t allsigs, tmpsig, oldsig;
320
@@ -133,7 +131,7 @@ static int do_spawn(unsigned logopt, unsigned int wait,
325
+ if (open_pipe(pipefd))
328
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
329
@@ -213,11 +211,6 @@ static int do_spawn(unsigned logopt, unsigned int wait,
333
- if ((flags = fcntl(pipefd[0], F_GETFD, 0)) != -1) {
334
- flags |= FD_CLOEXEC;
335
- fcntl(pipefd[0], F_SETFD, flags);
340
errn = timed_read(pipefd[0],
341
diff --git a/include/automount.h b/include/automount.h
342
index 1ba0d3c..a55ddbc 100644
343
--- a/include/automount.h
344
+++ b/include/automount.h
354
@@ -475,5 +477,109 @@ int alarm_start_handler(void);
355
int alarm_add(struct autofs_point *ap, time_t seconds);
356
void alarm_delete(struct autofs_point *ap);
359
+ * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
360
+ * socket() if possible.
362
+static int cloexec_works;
364
+static inline void check_cloexec(int fd)
366
+ if (cloexec_works == 0) {
367
+ int fl = fcntl(fd, F_GETFD);
368
+ cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
370
+ if (cloexec_works > 0)
372
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
376
+static inline int open_fd(const char *path, int flags)
380
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
381
+ if (cloexec_works != -1)
382
+ flags |= O_CLOEXEC;
384
+ fd = open(path, flags);
391
+static inline int open_fd_mode(const char *path, int flags, int mode)
395
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
396
+ if (cloexec_works != -1)
397
+ flags |= O_CLOEXEC;
399
+ fd = open(path, flags, mode);
406
+static inline int open_pipe(int pipefd[2])
410
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(__have_pipe2)
411
+ if (cloexec_works != -1) {
412
+ ret = pipe2(pipefd, O_CLOEXEC);
415
+ if (errno != EINVAL)
419
+ ret = pipe(pipefd);
422
+ check_cloexec(pipefd[0]);
423
+ check_cloexec(pipefd[1]);
427
+static inline int open_sock(int domain, int type, int protocol)
432
+ if (cloexec_works != -1)
433
+ type |= SOCK_CLOEXEC;
435
+ fd = socket(domain, type, protocol);
442
+static inline FILE *open_fopen_r(const char *path)
446
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
447
+ if (cloexec_works != -1) {
448
+ f = fopen(path, "re");
450
+ check_cloexec(fileno(f));
455
+ f = fopen(path, "r");
458
+ check_cloexec(fileno(f));
464
diff --git a/include/state.h b/include/state.h
465
index d7349d9..b44a353 100644
466
--- a/include/state.h
467
+++ b/include/state.h
476
diff --git a/lib/cache.c b/lib/cache.c
477
index ce47e04..4a00367 100644
488
#include <sys/param.h>
489
#include <sys/types.h>
490
#include <sys/stat.h>
491
diff --git a/lib/defaults.c b/lib/defaults.c
492
index 21d76d2..ff653e3 100644
496
#include "defaults.h"
497
#include "lookup_ldap.h"
499
+#include "automount.h"
501
#define DEFAULTS_CONFIG_FILE AUTOFS_CONF_DIR "/autofs"
502
#define MAX_LINE_LEN 256
503
@@ -255,7 +256,7 @@ struct list_head *defaults_get_uris(void)
505
struct list_head *list;
507
- f = fopen(DEFAULTS_CONFIG_FILE, "r");
508
+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
512
@@ -298,7 +299,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
513
char buf[MAX_LINE_LEN];
516
- f = fopen(DEFAULTS_CONFIG_FILE, "r");
517
+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
521
@@ -544,7 +545,7 @@ struct ldap_searchdn *defaults_get_searchdns(void)
523
struct ldap_searchdn *sdn, *last;
525
- f = fopen(DEFAULTS_CONFIG_FILE, "r");
526
+ f = open_fopen_r(DEFAULTS_CONFIG_FILE);
530
diff --git a/lib/dev-ioctl-lib.c b/lib/dev-ioctl-lib.c
531
index 57af785..056a0a9 100644
532
--- a/lib/dev-ioctl-lib.c
533
+++ b/lib/dev-ioctl-lib.c
534
@@ -121,17 +121,12 @@ void init_ioctl_ctl(void)
538
- devfd = open(CONTROL_DEVICE, O_RDONLY);
539
+ devfd = open_fd(CONTROL_DEVICE, O_RDONLY);
541
ctl.ops = &ioctl_ops;
543
struct autofs_dev_ioctl param;
545
- int cl_flags = fcntl(devfd, F_GETFD, 0);
546
- if (cl_flags != -1) {
547
- cl_flags |= FD_CLOEXEC;
548
- fcntl(devfd, F_SETFD, cl_flags);
551
* Check compile version against kernel.
552
* Selinux may allow us to open the device but not
553
@@ -378,20 +373,14 @@ static int ioctl_open(unsigned int logopt,
554
int *ioctlfd, dev_t devid, const char *path)
557
- int save_errno, fd, cl_flags;
558
+ int save_errno, fd;
562
- fd = open(path, O_RDONLY);
563
+ fd = open_fd(path, O_RDONLY);
567
- cl_flags = fcntl(fd, F_GETFD, 0);
568
- if (cl_flags != -1) {
569
- cl_flags |= FD_CLOEXEC;
570
- fcntl(fd, F_SETFD, cl_flags);
573
if (fstatfs(fd, &sfs) == -1) {
576
diff --git a/lib/log.c b/lib/log.c
577
index 65e8ad2..46220fd 100644
589
diff --git a/lib/macros.c b/lib/macros.c
590
index fa6db8e..85f9cd3 100644
594
* ----------------------------------------------------------------------- */
601
diff --git a/lib/mounts.c b/lib/mounts.c
602
index 6d0a69c..ce4691b 100644
612
#include <sys/types.h>
613
#include <sys/stat.h>
614
#include <sys/ioctl.h>
616
#include <sys/mount.h>
619
diff --git a/lib/nss_parse.y b/lib/nss_parse.y
620
index fa6958a..3bda6b3 100644
621
--- a/lib/nss_parse.y
622
+++ b/lib/nss_parse.y
631
#include "automount.h"
632
@@ -164,9 +162,9 @@ static void parse_close_nsswitch(void *arg)
633
int nsswitch_parse(struct list_head *list)
636
- int fd, cl_flags, status;
639
- nsswitch = fopen(NSSWITCH_FILE, "r");
640
+ nsswitch = open_fopen_r(NSSWITCH_FILE);
642
logerr("couldn't open %s\n", NSSWITCH_FILE);
644
@@ -174,13 +172,6 @@ int nsswitch_parse(struct list_head *list)
646
pthread_cleanup_push(parse_close_nsswitch, nsswitch);
648
- fd = fileno(nsswitch);
650
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
651
- cl_flags |= FD_CLOEXEC;
652
- fcntl(fd, F_SETFD, cl_flags);
656
pthread_cleanup_push(parse_mutex_unlock, NULL);
658
diff --git a/lib/parse_subs.c b/lib/parse_subs.c
659
index 3a04dd6..8a032e8 100644
660
--- a/lib/parse_subs.c
661
+++ b/lib/parse_subs.c
667
#include "automount.h"
670
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
671
index 6be86c6..9ac3657 100644
676
#include <rpc/pmap_prot.h>
679
#include <sys/socket.h>
682
#include <netinet/in.h>
683
#include <arpa/inet.h>
684
-#include <sys/fcntl.h>
685
#include <rpcsvc/ypclnt.h>
687
#include <sys/ioctl.h>
691
#include "rpc_subs.h"
692
+#include "automount.h"
694
/* #define STANDALONE */
696
@@ -59,7 +58,7 @@ inline void dump_core(void);
698
static CLIENT *create_udp_client(struct conn_info *info)
700
- int fd, cl_flags, ret, ghn_errno;
701
+ int fd, ret, ghn_errno;
703
struct sockaddr_in laddr, raddr;
705
@@ -115,15 +114,10 @@ got_addr:
706
* layer, it would bind to a reserved port, which has been shown
707
* to exhaust the reserved port range in some situations.
709
- fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
710
+ fd = open_sock(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
714
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
715
- cl_flags |= FD_CLOEXEC;
716
- fcntl(fd, F_SETFD, cl_flags);
719
laddr.sin_family = AF_INET;
721
laddr.sin_addr.s_addr = htonl(INADDR_ANY);
722
@@ -274,7 +268,7 @@ done:
724
static CLIENT *create_tcp_client(struct conn_info *info)
726
- int fd, cl_flags, ghn_errno;
729
struct sockaddr_in addr;
731
@@ -324,15 +318,10 @@ got_addr:
732
addr.sin_port = htons(info->port);
735
- fd = socket(PF_INET, SOCK_STREAM, info->proto->p_proto);
736
+ fd = open_sock(PF_INET, SOCK_STREAM, info->proto->p_proto);
740
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
741
- cl_flags |= FD_CLOEXEC;
742
- fcntl(fd, F_SETFD, cl_flags);
745
ret = connect_nb(fd, &addr, &info->timeout);
748
diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c
749
index 902d9aa..286af15 100644
750
--- a/modules/cyrus-sasl.c
751
+++ b/modules/cyrus-sasl.c
758
#include <sasl/sasl.h>
760
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
761
index 9e34b72..95b9f6f 100644
762
--- a/modules/lookup_file.c
763
+++ b/modules/lookup_file.c
773
@@ -395,7 +393,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
779
unsigned int path_len, ent_len;
780
int entry, cur_state;
782
@@ -422,7 +420,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
783
return NSS_STATUS_UNAVAIL;
786
- f = fopen(ctxt->mapname, "r");
787
+ f = open_fopen_r(ctxt->mapname);
790
MODPREFIX "could not open master map file %s",
791
@@ -432,11 +430,6 @@ int lookup_read_master(struct master *master, time_t age, void *context)
795
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
796
- cl_flags |= FD_CLOEXEC;
797
- fcntl(fd, F_SETFD, cl_flags);
801
entry = read_one(logopt, f, path, &path_len, ent, &ent_len);
803
@@ -651,7 +644,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
809
unsigned int k_len, m_len;
812
@@ -684,7 +677,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
813
return NSS_STATUS_UNAVAIL;
816
- f = fopen(ctxt->mapname, "r");
817
+ f = open_fopen_r(ctxt->mapname);
820
MODPREFIX "could not open map file %s", ctxt->mapname);
821
@@ -693,11 +686,6 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
825
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
826
- cl_flags |= FD_CLOEXEC;
827
- fcntl(fd, F_SETFD, cl_flags);
831
entry = read_one(ap->logopt, f, key, &k_len, mapent, &m_len);
833
@@ -784,7 +772,6 @@ static int lookup_one(struct autofs_point *ap,
834
char mapent[MAPENT_MAX_LEN + 1];
835
time_t age = time(NULL);
838
unsigned int k_len, m_len;
841
@@ -794,20 +781,13 @@ static int lookup_one(struct autofs_point *ap,
845
- f = fopen(ctxt->mapname, "r");
846
+ f = open_fopen_r(ctxt->mapname);
849
MODPREFIX "could not open map file %s", ctxt->mapname);
855
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
856
- cl_flags |= FD_CLOEXEC;
857
- fcntl(fd, F_SETFD, cl_flags);
861
entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
863
@@ -897,7 +877,6 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
864
char mapent[MAPENT_MAX_LEN + 1];
865
time_t age = time(NULL);
868
unsigned int k_len, m_len;
871
@@ -907,20 +886,13 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
875
- f = fopen(ctxt->mapname, "r");
876
+ f = open_fopen_r(ctxt->mapname);
879
MODPREFIX "could not open map file %s", ctxt->mapname);
885
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
886
- cl_flags |= FD_CLOEXEC;
887
- fcntl(fd, F_SETFD, cl_flags);
891
entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
893
diff --git a/modules/lookup_hesiod.c b/modules/lookup_hesiod.c
894
index 737a47e..0a2ee44 100644
895
--- a/modules/lookup_hesiod.c
896
+++ b/modules/lookup_hesiod.c
903
#include <netinet/in.h>
904
#include <arpa/nameser.h>
905
diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
906
index f8d4269..93b975a 100644
907
--- a/modules/lookup_hosts.c
908
+++ b/modules/lookup_hosts.c
914
#include <sys/param.h>
915
#include <sys/types.h>
916
#include <sys/stat.h>
917
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
918
index 42c3235..6ba80eb 100644
919
--- a/modules/lookup_ldap.c
920
+++ b/modules/lookup_ldap.c
922
#include <sys/stat.h>
929
diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c
930
index 601d48e..1bf2e0a 100644
931
--- a/modules/lookup_multi.c
932
+++ b/modules/lookup_multi.c
938
#include <sys/stat.h>
940
#define MODULE_LOOKUP
941
diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
942
index f15465f..4c3ce60 100644
943
--- a/modules/lookup_nisplus.c
944
+++ b/modules/lookup_nisplus.c
950
#include <sys/param.h>
951
#include <sys/types.h>
953
diff --git a/modules/lookup_program.c b/modules/lookup_program.c
954
index bf32d3b..6f4e2a3 100644
955
--- a/modules/lookup_program.c
956
+++ b/modules/lookup_program.c
963
#include <sys/param.h>
964
#include <sys/stat.h>
965
@@ -212,12 +211,12 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
966
* want to send stderr to the syslog, and we don't use spawnl()
967
* because we need the pipe hooks
969
- if (pipe(pipefd)) {
970
+ if (open_pipe(pipefd)) {
971
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
972
logerr(MODPREFIX "pipe: %s", estr);
975
- if (pipe(epipefd)) {
976
+ if (open_pipe(epipefd)) {
980
diff --git a/modules/lookup_userhome.c b/modules/lookup_userhome.c
981
index 680ddaf..fb3caaa 100644
982
--- a/modules/lookup_userhome.c
983
+++ b/modules/lookup_userhome.c
990
#include <sys/param.h>
991
#include <sys/types.h>
992
diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
993
index 1b62f57..ce438e8 100644
994
--- a/modules/lookup_yp.c
995
+++ b/modules/lookup_yp.c
1000
-#include <unistd.h>
1004
diff --git a/modules/mount_afs.c b/modules/mount_afs.c
1005
index 96a1367..50628ce 100644
1006
--- a/modules/mount_afs.c
1007
+++ b/modules/mount_afs.c
1013
-#include <unistd.h>
1015
#include <sys/param.h>
1016
#include <sys/types.h>
1017
diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
1018
index eb63d8e..82a5ef3 100644
1019
--- a/modules/mount_autofs.c
1020
+++ b/modules/mount_autofs.c
1026
-#include <unistd.h>
1030
diff --git a/modules/mount_bind.c b/modules/mount_bind.c
1031
index 022d183..361f0c2 100644
1032
--- a/modules/mount_bind.c
1033
+++ b/modules/mount_bind.c
1039
-#include <unistd.h>
1042
#include <sys/param.h>
1043
diff --git a/modules/mount_changer.c b/modules/mount_changer.c
1044
index 43b8355..92bb72b 100644
1045
--- a/modules/mount_changer.c
1046
+++ b/modules/mount_changer.c
1052
-#include <unistd.h>
1054
#include <sys/param.h>
1055
#include <sys/types.h>
1056
@@ -145,25 +143,19 @@ int swapCD(const char *device, const char *slotName)
1058
int fd; /* file descriptor for CD-ROM device */
1059
int status; /* return status for system calls */
1062
int total_slots_available;
1064
slot = atoi(slotName) - 1;
1067
- fd = open(device, O_RDONLY | O_NONBLOCK);
1068
+ fd = open_fd(device, O_RDONLY | O_NONBLOCK);
1070
logerr(MODPREFIX "Opening device %s failed : %s",
1071
device, strerror(errno));
1075
- if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
1076
- cl_flags |= FD_CLOEXEC;
1077
- fcntl(fd, F_SETFD, cl_flags);
1080
/* Check CD player status */
1081
total_slots_available = ioctl(fd, CDROM_CHANGER_NSLOTS);
1082
if (total_slots_available <= 1) {
1083
diff --git a/modules/mount_ext2.c b/modules/mount_ext2.c
1084
index 4c5b271..192ec04 100644
1085
--- a/modules/mount_ext2.c
1086
+++ b/modules/mount_ext2.c
1092
-#include <unistd.h>
1095
#include <sys/param.h>
1096
diff --git a/modules/mount_generic.c b/modules/mount_generic.c
1097
index f094d07..6d7b4b3 100644
1098
--- a/modules/mount_generic.c
1099
+++ b/modules/mount_generic.c
1105
-#include <unistd.h>
1108
#include <sys/param.h>
1109
diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
1110
index c747078..20732f8 100644
1111
--- a/modules/mount_nfs.c
1112
+++ b/modules/mount_nfs.c
1118
-#include <unistd.h>
1121
#include <sys/param.h>
1122
diff --git a/modules/parse_hesiod.c b/modules/parse_hesiod.c
1123
index ff1f0a5..d5bb0f4 100644
1124
--- a/modules/parse_hesiod.c
1125
+++ b/modules/parse_hesiod.c
1127
#include <sys/types.h>
1130
-#include <unistd.h>
1132
#include <netinet/in.h>
1133
#include <arpa/nameser.h>
1134
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
1135
index 2c4f8b2..72e51e2 100644
1136
--- a/modules/parse_sun.c
1137
+++ b/modules/parse_sun.c
1143
-#include <unistd.h>
1147
diff --git a/modules/replicated.c b/modules/replicated.c
1148
index b435f4b..63829a2 100644
1149
--- a/modules/replicated.c
1150
+++ b/modules/replicated.c
1153
#include <netinet/in.h>
1155
-#include <unistd.h>
1158
#include "rpc_subs.h"
1159
#include "replicated.h"
1160
@@ -82,7 +80,7 @@ void seed_random(void)
1164
- fd = open("/dev/urandom", O_RDONLY);
1165
+ fd = open_fd("/dev/urandom", O_RDONLY);
1167
srandom(time(NULL));
1169
@@ -145,7 +143,7 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
1170
char tmp[20], buf[MAX_ERR_BUF], *ptr;
1172
struct ifreq *ifr, nmptr;
1173
- int sock, cl_flags, ret, i;
1175
uint32_t mask, ha, ia;
1177
memcpy(tmp, host_addr, addr_len);
1178
@@ -153,18 +151,13 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
1180
ha = ntohl((uint32_t) hst_addr->s_addr);
1182
- sock = socket(AF_INET, SOCK_DGRAM, 0);
1183
+ sock = open_sock(AF_INET, SOCK_DGRAM, 0);
1185
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1186
logerr("socket creation failed: %s", estr);
1187
return PROXIMITY_ERROR;
1190
- if ((cl_flags = fcntl(sock, F_GETFD, 0)) != -1) {
1191
- cl_flags |= FD_CLOEXEC;
1192
- fcntl(sock, F_SETFD, cl_flags);
1195
if (!alloc_ifreq(&ifc, sock)) {
1197
return PROXIMITY_ERROR;