~ubuntu-branches/ubuntu/raring/autofs5/raring

« back to all changes in this revision

Viewing changes to debian/patches/01UPSTREAM_autofs-5.0.4-use-CLOEXEC-flag.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2009-03-09 01:16:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090309011648-gjynlid883f0s2c4
Tags: 5.0.4-1
* New upstream version (5.0.4 plus patchset as of 2009/03/09).
  * Closes: #518728.
  * Remove dpatch 14, applied upstream.
* New dpatch 14 to avoid using the relatively young SOCK_CLOEXEC
  feature.
* Only invoke 'make clean' on clean target so ./configure isn't
  purged.
* Fix a typo in the postinst regarding the ucf conffile handling.
* Add 'set -e' to package maintenance scripts.
* Drop unnecessary /var/run/autofs from package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 01UPSTREAM_autofs-5.0.4-use-CLOEXEC-flag.dpatch
 
3
##
 
4
## DP: Upstream patch.
 
5
 
 
6
@DPATCH@
 
7
autofs-5.0.4 - use CLOEXEC flag
 
8
 
 
9
From: Ian Kent <raven@themaw.net>
 
10
 
 
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.
 
14
---
 
15
 
 
16
 CHANGELOG                 |    1 
 
17
 daemon/automount.c        |   42 ++++--------------
 
18
 daemon/direct.c           |    2 -
 
19
 daemon/flag.c             |    8 ++-
 
20
 daemon/indirect.c         |    2 -
 
21
 daemon/lookup.c           |    1 
 
22
 daemon/module.c           |    2 -
 
23
 daemon/spawn.c            |   11 +----
 
24
 include/automount.h       |  106 +++++++++++++++++++++++++++++++++++++++++++++
 
25
 include/state.h           |    1 
 
26
 lib/cache.c               |    2 -
 
27
 lib/defaults.c            |    7 ++-
 
28
 lib/dev-ioctl-lib.c       |   17 +------
 
29
 lib/log.c                 |    2 -
 
30
 lib/macros.c              |    1 
 
31
 lib/mounts.c              |    2 -
 
32
 lib/nss_parse.y           |   13 +-----
 
33
 lib/parse_subs.c          |    1 
 
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(-)
 
56
 
 
57
 
 
58
diff --git a/CHANGELOG b/CHANGELOG
 
59
index bd35b00..43f3205 100644
 
60
--- a/CHANGELOG
 
61
+++ b/CHANGELOG
 
62
@@ -3,6 +3,7 @@
 
63
 - fix dumb libxml2 check
 
64
 - fix nested submount expire deadlock.
 
65
 - fix negative caching for non-existent map keys.
 
66
+- use CLOEXEC flag.
 
67
 
 
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
 
74
@@ -20,13 +20,11 @@
 
75
  * ----------------------------------------------------------------------- */
 
76
 
 
77
 #include <dirent.h>
 
78
-#include <fcntl.h>
 
79
 #include <getopt.h>
 
80
 #include <signal.h>
 
81
 #include <stdio.h>
 
82
 #include <stdlib.h>
 
83
 #include <string.h>
 
84
-#include <unistd.h>
 
85
 #include <sys/ioctl.h>
 
86
 #include <ctype.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;
 
91
 
 
92
+/* Does kernel know about SOCK_CLOEXEC and friends */
 
93
+static int cloexec_works = 0;
 
94
+
 
95
 /* Attribute to create detached thread */
 
96
 pthread_attr_t thread_attr;
 
97
 
 
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)
 
100
 {
 
101
        int ret = -1;
 
102
-       int fd, cl_flags;
 
103
+       int fd;
 
104
        char *fifo_name;
 
105
        char buf[MAX_ERR_BUF];
 
106
 
 
107
@@ -697,7 +698,7 @@ static int create_logpri_fifo(struct autofs_point *ap)
 
108
                goto out_free;
 
109
        }
 
110
 
 
111
-       fd = open(fifo_name, O_RDWR|O_NONBLOCK);
 
112
+       fd = open_fd(fifo_name, O_RDWR|O_NONBLOCK);
 
113
        if (fd < 0) {
 
114
                char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 
115
                crit(ap->logopt,
 
116
@@ -707,11 +708,6 @@ static int create_logpri_fifo(struct autofs_point *ap)
 
117
                goto out_free;
 
118
        }
 
119
 
 
120
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
121
-               cl_flags |= FD_CLOEXEC;
 
122
-               fcntl(fd, F_SETFD, cl_flags);
 
123
-       }
 
124
-
 
125
        ap->logpri_fifo = fd;
 
126
 
 
127
 out_free:
 
128
@@ -963,7 +959,7 @@ int do_expire(struct autofs_point *ap, const char *name, int namelen)
 
129
 
 
130
 static int autofs_init_ap(struct autofs_point *ap)
 
131
 {
 
132
-       int pipefd[2], cl_flags;
 
133
+       int pipefd[2];
 
134
 
 
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;
 
139
 
 
140
        /* Pipe for kernel communications */
 
141
-       if (pipe(pipefd) < 0) {
 
142
+       if (open_pipe(pipefd) < 0) {
 
143
                crit(ap->logopt,
 
144
                     "failed to create commumication pipe for autofs path %s",
 
145
                     ap->path);
 
146
@@ -984,18 +980,8 @@ static int autofs_init_ap(struct autofs_point *ap)
 
147
        ap->pipefd = pipefd[0];
 
148
        ap->kpipefd = pipefd[1];
 
149
 
 
150
-       if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
 
151
-               cl_flags |= FD_CLOEXEC;
 
152
-               fcntl(ap->pipefd, F_SETFD, cl_flags);
 
153
-       }
 
154
-
 
155
-       if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
 
156
-               cl_flags |= FD_CLOEXEC;
 
157
-               fcntl(ap->kpipefd, F_SETFD, cl_flags);
 
158
-       }
 
159
-
 
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) {
 
163
                crit(ap->logopt,
 
164
                     "failed create state pipe for autofs path %s", ap->path);
 
165
                close(ap->pipefd);
 
166
@@ -1003,16 +989,6 @@ static int autofs_init_ap(struct autofs_point *ap)
 
167
                return -1;
 
168
        }
 
169
 
 
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);
 
173
-       }
 
174
-
 
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);
 
178
-       }
 
179
-
 
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)
 
184
                exit(0);
 
185
        }
 
186
 
 
187
-       if (pipe(start_pipefd) < 0) {
 
188
+       if (open_pipe(start_pipefd) < 0) {
 
189
                fprintf(stderr, "%s: failed to create start_pipefd.\n",
 
190
                        program);
 
191
                exit(0);
 
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
 
196
@@ -21,12 +21,10 @@
 
197
 
 
198
 #include <dirent.h>
 
199
 #include <libgen.h>
 
200
-#include <fcntl.h>
 
201
 #include <signal.h>
 
202
 #include <stdio.h>
 
203
 #include <stdlib.h>
 
204
 #include <string.h>
 
205
-#include <unistd.h>
 
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
 
211
--- a/daemon/flag.c
 
212
+++ b/daemon/flag.c
 
213
@@ -21,15 +21,15 @@
 
214
 #include <sys/time.h>
 
215
 #include <sys/types.h>
 
216
 #include <sys/stat.h>
 
217
-#include <fcntl.h>
 
218
 #include <time.h>
 
219
-#include <unistd.h>
 
220
 #include <string.h>
 
221
 #include <alloca.h>
 
222
 #include <stdio.h>
 
223
 #include <signal.h>
 
224
 #include <errno.h>
 
225
 
 
226
+#include "automount.h"
 
227
+
 
228
 #define MAX_PIDSIZE    20
 
229
 #define FLAG_FILE      AUTOFS_FLAG_DIR "/autofs-running"
 
230
 
 
231
@@ -129,7 +129,7 @@ int aquire_flag_file(void)
 
232
        while (!we_created_flagfile) {
 
233
                int errsv, i, j;
 
234
 
 
235
-               i = open(linkf, O_WRONLY|O_CREAT, 0);
 
236
+               i = open_fd_mode(linkf, O_WRONLY|O_CREAT, 0);
 
237
                if (i < 0) {
 
238
                        release_flag_file();
 
239
                        return 0;
 
240
@@ -146,7 +146,7 @@ int aquire_flag_file(void)
 
241
                        return 0;
 
242
                }
 
243
 
 
244
-               fd = open(FLAG_FILE, O_RDWR);
 
245
+               fd = open_fd(FLAG_FILE, O_RDWR);
 
246
                if (fd < 0) {
 
247
                        /* Maybe the file was just deleted? */
 
248
                        if (errno == ENOENT)
 
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
 
253
@@ -21,12 +21,10 @@
 
254
 
 
255
 #include <dirent.h>
 
256
 #include <libgen.h>
 
257
-#include <fcntl.h>
 
258
 #include <signal.h>
 
259
 #include <stdio.h>
 
260
 #include <stdlib.h>
 
261
 #include <string.h>
 
262
-#include <unistd.h>
 
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
 
270
@@ -22,7 +22,6 @@
 
271
 #include <stdio.h>
 
272
 #include <string.h>
 
273
 #include <sys/stat.h>
 
274
-#include <unistd.h>
 
275
 #include "automount.h"
 
276
 #include "nsswitch.h"
 
277
 
 
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
 
284
         * time.
 
285
         */
 
286
-       fp = fopen("/proc/filesystems", "r");
 
287
+       fp = open_fopen_r("/proc/filesystems");
 
288
        if (!fp) {
 
289
                logerr("cannot open /proc/filesystems\n");
 
290
                return 0;
 
291
diff --git a/daemon/spawn.c b/daemon/spawn.c
 
292
index 17f92f4..4ddf46f 100644
 
293
--- a/daemon/spawn.c
 
294
+++ b/daemon/spawn.c
 
295
@@ -13,7 +13,6 @@
 
296
  *
 
297
  * ----------------------------------------------------------------------- */
 
298
 
 
299
-#include <fcntl.h>
 
300
 #include <signal.h>
 
301
 #include <stdarg.h>
 
302
 #include <stdio.h>
 
303
@@ -21,7 +20,6 @@
 
304
 #include <string.h>
 
305
 #include <sys/types.h>
 
306
 #include <dirent.h>
 
307
-#include <unistd.h>
 
308
 #include <time.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;
 
314
        int errp, errn;
 
315
-       int flags, cancel_state;
 
316
+       int 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,
 
321
        pid_t euid = 0;
 
322
        gid_t egid = 0;
 
323
 
 
324
-       if (pipe(pipefd))
 
325
+       if (open_pipe(pipefd))
 
326
                return -1;
 
327
 
 
328
        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
 
329
@@ -213,11 +211,6 @@ static int do_spawn(unsigned logopt, unsigned int wait,
 
330
                        return -1;
 
331
                }
 
332
 
 
333
-               if ((flags = fcntl(pipefd[0], F_GETFD, 0)) != -1) {
 
334
-                       flags |= FD_CLOEXEC;
 
335
-                       fcntl(pipefd[0], F_SETFD, flags);
 
336
-               }
 
337
-
 
338
                errp = 0;
 
339
                do {
 
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
 
345
@@ -17,6 +17,8 @@
 
346
 #include <pthread.h>
 
347
 #include <sched.h>
 
348
 #include <errno.h>
 
349
+#include <unistd.h>
 
350
+#include <fcntl.h>
 
351
 #include "config.h"
 
352
 #include "list.h"
 
353
 
 
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);
 
357
 
 
358
+/*
 
359
+ * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
 
360
+ * socket() if possible.
 
361
+ */
 
362
+static int cloexec_works;
 
363
+
 
364
+static inline void check_cloexec(int fd)
 
365
+{
 
366
+       if (cloexec_works == 0) {
 
367
+               int fl = fcntl(fd, F_GETFD);
 
368
+               cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
 
369
+       }
 
370
+       if (cloexec_works > 0)
 
371
+               return;
 
372
+       fcntl(fd, F_SETFD, FD_CLOEXEC);
 
373
+       return;
 
374
+}
 
375
+
 
376
+static inline int open_fd(const char *path, int flags)
 
377
+{
 
378
+       int fd;
 
379
+
 
380
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
 
381
+       if (cloexec_works != -1)
 
382
+               flags |= O_CLOEXEC;
 
383
+#endif
 
384
+       fd = open(path, flags);
 
385
+       if (fd == -1)
 
386
+               return -1;
 
387
+       check_cloexec(fd);
 
388
+       return fd;
 
389
+}
 
390
+
 
391
+static inline int open_fd_mode(const char *path, int flags, int mode)
 
392
+{
 
393
+       int fd;
 
394
+
 
395
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
 
396
+       if (cloexec_works != -1)
 
397
+               flags |= O_CLOEXEC;
 
398
+#endif
 
399
+       fd = open(path, flags, mode);
 
400
+       if (fd == -1)
 
401
+               return -1;
 
402
+       check_cloexec(fd);
 
403
+       return fd;
 
404
+}
 
405
+
 
406
+static inline int open_pipe(int pipefd[2])
 
407
+{
 
408
+       int ret;
 
409
+
 
410
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(__have_pipe2)
 
411
+       if (cloexec_works != -1) {
 
412
+               ret = pipe2(pipefd, O_CLOEXEC);
 
413
+               if (ret != -1)
 
414
+                       return 0;
 
415
+               if (errno != EINVAL)
 
416
+                       return -1;
 
417
+       }
 
418
+#endif
 
419
+       ret = pipe(pipefd);
 
420
+       if (ret == -1)
 
421
+               return -1;
 
422
+       check_cloexec(pipefd[0]);
 
423
+       check_cloexec(pipefd[1]);
 
424
+       return 0;
 
425
+}
 
426
+
 
427
+static inline int open_sock(int domain, int type, int protocol)
 
428
+{
 
429
+       int fd;
 
430
+
 
431
+#ifdef SOCK_CLOEXEC
 
432
+       if (cloexec_works != -1)
 
433
+               type |= SOCK_CLOEXEC;
 
434
+#endif
 
435
+       fd = socket(domain, type, protocol);
 
436
+       if (fd == -1)
 
437
+               return -1;
 
438
+       check_cloexec(fd);
 
439
+       return fd;
 
440
+}
 
441
+
 
442
+static inline FILE *open_fopen_r(const char *path)
 
443
+{
 
444
+       FILE *f;
 
445
+
 
446
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
 
447
+       if (cloexec_works != -1) {
 
448
+               f = fopen(path, "re");
 
449
+               if (f != NULL) {
 
450
+                       check_cloexec(fileno(f));
 
451
+                       return f;
 
452
+               }
 
453
+       }
 
454
+#endif
 
455
+       f = fopen(path, "r");
 
456
+       if (f == NULL)
 
457
+               return NULL;
 
458
+       check_cloexec(fileno(f));
 
459
+       return f;
 
460
+}
 
461
+
 
462
 #endif
 
463
 
 
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
 
468
@@ -20,7 +20,6 @@
 
469
 #ifndef STATE_H
 
470
 #define STATE_H
 
471
 
 
472
-#include <unistd.h>
 
473
 #include <string.h>
 
474
 #include <stdlib.h>
 
475
 #include <signal.h>
 
476
diff --git a/lib/cache.c b/lib/cache.c
 
477
index ce47e04..4a00367 100644
 
478
--- a/lib/cache.c
 
479
+++ b/lib/cache.c
 
480
@@ -17,10 +17,8 @@
 
481
 #include <malloc.h>
 
482
 #include <stdlib.h>
 
483
 #include <string.h>
 
484
-#include <unistd.h>
 
485
 #include <ctype.h>
 
486
 #include <stdio.h>
 
487
-#include <fcntl.h>
 
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
 
493
--- a/lib/defaults.c
 
494
+++ b/lib/defaults.c
 
495
@@ -21,6 +21,7 @@
 
496
 #include "defaults.h"
 
497
 #include "lookup_ldap.h"
 
498
 #include "log.h"
 
499
+#include "automount.h"
 
500
 
 
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)
 
504
        char *res;
 
505
        struct list_head *list;
 
506
 
 
507
-       f = fopen(DEFAULTS_CONFIG_FILE, "r");
 
508
+       f = open_fopen_r(DEFAULTS_CONFIG_FILE);
 
509
        if (!f)
 
510
                return NULL;
 
511
 
 
512
@@ -298,7 +299,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
 
513
        char buf[MAX_LINE_LEN];
 
514
        char *res;
 
515
 
 
516
-       f = fopen(DEFAULTS_CONFIG_FILE, "r");
 
517
+       f = open_fopen_r(DEFAULTS_CONFIG_FILE);
 
518
        if (!f)
 
519
                return 0;
 
520
 
 
521
@@ -544,7 +545,7 @@ struct ldap_searchdn *defaults_get_searchdns(void)
 
522
        char *res;
 
523
        struct ldap_searchdn *sdn, *last;
 
524
 
 
525
-       f = fopen(DEFAULTS_CONFIG_FILE, "r");
 
526
+       f = open_fopen_r(DEFAULTS_CONFIG_FILE);
 
527
        if (!f)
 
528
                return NULL;
 
529
 
 
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)
 
535
        if (ctl.ops)
 
536
                return;
 
537
 
 
538
-       devfd = open(CONTROL_DEVICE, O_RDONLY);
 
539
+       devfd = open_fd(CONTROL_DEVICE, O_RDONLY);
 
540
        if (devfd == -1)
 
541
                ctl.ops = &ioctl_ops;
 
542
        else {
 
543
                struct autofs_dev_ioctl param;
 
544
 
 
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);
 
549
-               }
 
550
                /*
 
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)
 
555
 {
 
556
        struct statfs sfs;
 
557
-       int save_errno, fd, cl_flags;
 
558
+       int save_errno, fd;
 
559
 
 
560
        *ioctlfd = -1;
 
561
 
 
562
-       fd = open(path, O_RDONLY);
 
563
+       fd = open_fd(path, O_RDONLY);
 
564
        if (fd == -1)
 
565
                return -1;
 
566
 
 
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);
 
571
-       }
 
572
-
 
573
        if (fstatfs(fd, &sfs) == -1) {
 
574
                save_errno = errno;
 
575
                goto err;
 
576
diff --git a/lib/log.c b/lib/log.c
 
577
index 65e8ad2..46220fd 100644
 
578
--- a/lib/log.c
 
579
+++ b/lib/log.c
 
580
@@ -20,8 +20,6 @@
 
581
 
 
582
 #include <stdarg.h>
 
583
 #include <stdio.h>
 
584
-#include <unistd.h>
 
585
-#include <fcntl.h>
 
586
 #include <stdlib.h>
 
587
 #include <string.h>
 
588
 
 
589
diff --git a/lib/macros.c b/lib/macros.c
 
590
index fa6db8e..85f9cd3 100644
 
591
--- a/lib/macros.c
 
592
+++ b/lib/macros.c
 
593
@@ -14,7 +14,6 @@
 
594
  * ----------------------------------------------------------------------- */
 
595
 
 
596
 #include <malloc.h>
 
597
-#include <unistd.h>
 
598
 #include <stdlib.h>
 
599
 #include <string.h>
 
600
 #include <limits.h>
 
601
diff --git a/lib/mounts.c b/lib/mounts.c
 
602
index 6d0a69c..ce4691b 100644
 
603
--- a/lib/mounts.c
 
604
+++ b/lib/mounts.c
 
605
@@ -14,13 +14,11 @@
 
606
 
 
607
 #include <stdlib.h>
 
608
 #include <string.h>
 
609
-#include <unistd.h>
 
610
 #include <mntent.h>
 
611
 #include <limits.h>
 
612
 #include <sys/types.h>
 
613
 #include <sys/stat.h>
 
614
 #include <sys/ioctl.h>
 
615
-#include <fcntl.h>
 
616
 #include <sys/mount.h>
 
617
 #include <stdio.h>
 
618
 #include <dirent.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
 
623
@@ -22,8 +22,6 @@
 
624
 #include <stdlib.h>
 
625
 #include <string.h>
 
626
 #include <memory.h>
 
627
-#include <unistd.h>
 
628
-#include <fcntl.h>
 
629
 #include <limits.h>
 
630
 
 
631
 #include "automount.h"
 
632
@@ -164,9 +162,9 @@ static void parse_close_nsswitch(void *arg)
 
633
 int nsswitch_parse(struct list_head *list)
 
634
 {
 
635
        FILE *nsswitch;
 
636
-       int fd, cl_flags, status;
 
637
+       int status;
 
638
 
 
639
-       nsswitch = fopen(NSSWITCH_FILE, "r");
 
640
+       nsswitch = open_fopen_r(NSSWITCH_FILE);
 
641
        if (!nsswitch) {
 
642
                logerr("couldn't open %s\n", NSSWITCH_FILE);
 
643
                return 1;
 
644
@@ -174,13 +172,6 @@ int nsswitch_parse(struct list_head *list)
 
645
 
 
646
        pthread_cleanup_push(parse_close_nsswitch, nsswitch);
 
647
 
 
648
-       fd = fileno(nsswitch);
 
649
-
 
650
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
651
-               cl_flags |= FD_CLOEXEC;
 
652
-               fcntl(fd, F_SETFD, cl_flags);
 
653
-       }
 
654
-
 
655
        parse_mutex_lock();
 
656
        pthread_cleanup_push(parse_mutex_unlock, NULL);
 
657
 
 
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
 
662
@@ -18,7 +18,6 @@
 
663
 #include <stdlib.h>
 
664
 #include <string.h>
 
665
 #include <ctype.h>
 
666
-#include <unistd.h>
 
667
 #include "automount.h"
 
668
 
 
669
 /*
 
670
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
 
671
index 6be86c6..9ac3657 100644
 
672
--- a/lib/rpc_subs.c
 
673
+++ b/lib/rpc_subs.c
 
674
@@ -21,13 +21,11 @@
 
675
 #include <rpc/rpc.h>
 
676
 #include <rpc/pmap_prot.h>
 
677
 
 
678
-#include <unistd.h>
 
679
 #include <sys/socket.h>
 
680
 #include <netdb.h>
 
681
 #include <net/if.h>
 
682
 #include <netinet/in.h>
 
683
 #include <arpa/inet.h>
 
684
-#include <sys/fcntl.h>
 
685
 #include <rpcsvc/ypclnt.h>
 
686
 #include <errno.h>
 
687
 #include <sys/ioctl.h>
 
688
@@ -36,6 +34,7 @@
 
689
 
 
690
 #include "mount.h"
 
691
 #include "rpc_subs.h"
 
692
+#include "automount.h"
 
693
 
 
694
 /* #define STANDALONE */
 
695
 #ifdef STANDALONE
 
696
@@ -59,7 +58,7 @@ inline void dump_core(void);
 
697
  */
 
698
 static CLIENT *create_udp_client(struct conn_info *info)
 
699
 {
 
700
-       int fd, cl_flags, ret, ghn_errno;
 
701
+       int fd, ret, ghn_errno;
 
702
        CLIENT *client;
 
703
        struct sockaddr_in laddr, raddr;
 
704
        struct hostent hp;
 
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.
 
708
                 */
 
709
-               fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
710
+               fd = open_sock(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
711
                if (fd < 0)
 
712
                        return NULL;
 
713
 
 
714
-               if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
715
-                       cl_flags |= FD_CLOEXEC;
 
716
-                       fcntl(fd, F_SETFD, cl_flags);
 
717
-               }
 
718
-
 
719
                laddr.sin_family = AF_INET;
 
720
                laddr.sin_port = 0;
 
721
                laddr.sin_addr.s_addr = htonl(INADDR_ANY);
 
722
@@ -274,7 +268,7 @@ done:
 
723
  */
 
724
 static CLIENT *create_tcp_client(struct conn_info *info)
 
725
 {
 
726
-       int fd, cl_flags, ghn_errno;
 
727
+       int fd, ghn_errno;
 
728
        CLIENT *client;
 
729
        struct sockaddr_in addr;
 
730
        struct hostent hp;
 
731
@@ -324,15 +318,10 @@ got_addr:
 
732
        addr.sin_port = htons(info->port);
 
733
 
 
734
        if (!info->client) {
 
735
-               fd = socket(PF_INET, SOCK_STREAM, info->proto->p_proto);
 
736
+               fd = open_sock(PF_INET, SOCK_STREAM, info->proto->p_proto);
 
737
                if (fd < 0)
 
738
                        return NULL;
 
739
 
 
740
-               if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
741
-                       cl_flags |= FD_CLOEXEC;
 
742
-                       fcntl(fd, F_SETFD, cl_flags);
 
743
-               }
 
744
-
 
745
                ret = connect_nb(fd, &addr, &info->timeout);
 
746
                if (ret < 0)
 
747
                        goto out_close;
 
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
 
752
@@ -51,7 +51,6 @@
 
753
 #include <stdio.h>
 
754
 #include <stdlib.h>
 
755
 #include <string.h>
 
756
-#include <unistd.h>
 
757
 #include <ldap.h>
 
758
 #include <sasl/sasl.h>
 
759
 
 
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
 
764
@@ -17,8 +17,6 @@
 
765
 #include <malloc.h>
 
766
 #include <stdlib.h>
 
767
 #include <string.h>
 
768
-#include <unistd.h>
 
769
-#include <fcntl.h>
 
770
 #include <time.h>
 
771
 #include <ctype.h>
 
772
 #include <signal.h>
 
773
@@ -395,7 +393,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
 
774
        char *ent;
 
775
        struct stat st;
 
776
        FILE *f;
 
777
-       int fd, cl_flags;
 
778
+       int fd;
 
779
        unsigned int path_len, ent_len;
 
780
        int entry, cur_state;
 
781
 
 
782
@@ -422,7 +420,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
 
783
                return NSS_STATUS_UNAVAIL;
 
784
        }
 
785
 
 
786
-       f = fopen(ctxt->mapname, "r");
 
787
+       f = open_fopen_r(ctxt->mapname);
 
788
        if (!f) {
 
789
                error(logopt,
 
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)
 
792
 
 
793
        fd = fileno(f);
 
794
 
 
795
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
796
-               cl_flags |= FD_CLOEXEC;
 
797
-               fcntl(fd, F_SETFD, cl_flags);
 
798
-       }
 
799
-
 
800
        while(1) {
 
801
                entry = read_one(logopt, f, path, &path_len, ent, &ent_len);
 
802
                if (!entry) {
 
803
@@ -651,7 +644,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
 
804
        char *mapent;
 
805
        struct stat st;
 
806
        FILE *f;
 
807
-       int fd, cl_flags;
 
808
+       int fd;
 
809
        unsigned int k_len, m_len;
 
810
        int entry;
 
811
 
 
812
@@ -684,7 +677,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
 
813
                return NSS_STATUS_UNAVAIL;
 
814
        }
 
815
 
 
816
-       f = fopen(ctxt->mapname, "r");
 
817
+       f = open_fopen_r(ctxt->mapname);
 
818
        if (!f) {
 
819
                error(ap->logopt,
 
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)
 
822
 
 
823
        fd = fileno(f);
 
824
 
 
825
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
826
-               cl_flags |= FD_CLOEXEC;
 
827
-               fcntl(fd, F_SETFD, cl_flags);
 
828
-       }
 
829
-
 
830
        while(1) {
 
831
                entry = read_one(ap->logopt, f, key, &k_len, mapent, &m_len);
 
832
                if (!entry) {
 
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);
 
836
        FILE *f;
 
837
-       int fd, cl_flags;
 
838
        unsigned int k_len, m_len;
 
839
        int entry, ret;
 
840
 
 
841
@@ -794,20 +781,13 @@ static int lookup_one(struct autofs_point *ap,
 
842
 
 
843
        mc = source->mc;
 
844
 
 
845
-       f = fopen(ctxt->mapname, "r");
 
846
+       f = open_fopen_r(ctxt->mapname);
 
847
        if (!f) {
 
848
                error(ap->logopt,
 
849
                      MODPREFIX "could not open map file %s", ctxt->mapname);
 
850
                return CHE_FAIL;
 
851
        }
 
852
 
 
853
-       fd = fileno(f);
 
854
-
 
855
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
856
-               cl_flags |= FD_CLOEXEC;
 
857
-               fcntl(fd, F_SETFD, cl_flags);
 
858
-       }
 
859
-
 
860
        while(1) {
 
861
                entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
 
862
                if (entry) {
 
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);
 
866
        FILE *f;
 
867
-       int fd, cl_flags;
 
868
        unsigned int k_len, m_len;
 
869
        int entry, ret;
 
870
 
 
871
@@ -907,20 +886,13 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
 
872
 
 
873
        mc = source->mc;
 
874
 
 
875
-       f = fopen(ctxt->mapname, "r");
 
876
+       f = open_fopen_r(ctxt->mapname);
 
877
        if (!f) {
 
878
                error(ap->logopt,
 
879
                      MODPREFIX "could not open map file %s", ctxt->mapname);
 
880
                return CHE_FAIL;
 
881
        }
 
882
 
 
883
-       fd = fileno(f);
 
884
-
 
885
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
886
-               cl_flags |= FD_CLOEXEC;
 
887
-               fcntl(fd, F_SETFD, cl_flags);
 
888
-       }
 
889
-
 
890
        while(1) {
 
891
                entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
 
892
                if (entry) {
 
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
 
897
@@ -10,7 +10,6 @@
 
898
 #include <ctype.h>
 
899
 #include <limits.h>
 
900
 #include <string.h>
 
901
-#include <unistd.h>
 
902
 #include <stdlib.h>
 
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
 
909
@@ -15,7 +15,6 @@
 
910
 
 
911
 #include <stdio.h>
 
912
 #include <malloc.h>
 
913
-#include <unistd.h>
 
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
 
921
@@ -21,7 +21,6 @@
 
922
 #include <sys/stat.h>
 
923
 #include <ctype.h>
 
924
 #include <string.h>
 
925
-#include <unistd.h>
 
926
 #include <stdlib.h>
 
927
 #include <time.h>
 
928
 #include <signal.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
 
933
@@ -18,7 +18,6 @@
 
934
 #include <malloc.h>
 
935
 #include <stdio.h>
 
936
 #include <string.h>
 
937
-#include <unistd.h>
 
938
 #include <sys/stat.h>
 
939
 
 
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
 
945
@@ -6,7 +6,6 @@
 
946
 
 
947
 #include <stdio.h>
 
948
 #include <malloc.h>
 
949
-#include <unistd.h>
 
950
 #include <sys/param.h>
 
951
 #include <sys/types.h>
 
952
 #include <signal.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
 
957
@@ -18,7 +18,6 @@
 
958
 #include <malloc.h>
 
959
 #include <stdio.h>
 
960
 #include <string.h>
 
961
-#include <unistd.h>
 
962
 #include <signal.h>
 
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
 
968
         */
 
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);
 
973
                goto out_free;
 
974
        }
 
975
-       if (pipe(epipefd)) {
 
976
+       if (open_pipe(epipefd)) {
 
977
                close(pipefd[0]);
 
978
                close(pipefd[1]);
 
979
                goto out_free;
 
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
 
984
@@ -16,7 +16,6 @@
 
985
 #include <stdio.h>
 
986
 #include <malloc.h>
 
987
 #include <pwd.h>
 
988
-#include <unistd.h>
 
989
 #include <string.h>
 
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
 
996
@@ -16,7 +16,6 @@
 
997
 
 
998
 #include <stdio.h>
 
999
 #include <malloc.h>
 
1000
-#include <unistd.h>
 
1001
 #include <time.h>
 
1002
 #include <signal.h>
 
1003
 #include <ctype.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
 
1008
@@ -9,8 +9,6 @@
 
1009
 
 
1010
 #include <stdio.h>
 
1011
 #include <malloc.h>
 
1012
-#include <fcntl.h>
 
1013
-#include <unistd.h>
 
1014
 #include <string.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
 
1021
@@ -16,8 +16,6 @@
 
1022
 #include <stdio.h>
 
1023
 #include <stdlib.h>
 
1024
 #include <malloc.h>
 
1025
-#include <fcntl.h>
 
1026
-#include <unistd.h>
 
1027
 #include <string.h>
 
1028
 #include <signal.h>
 
1029
 #include <alloca.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
 
1034
@@ -15,8 +15,6 @@
 
1035
 
 
1036
 #include <stdio.h>
 
1037
 #include <malloc.h>
 
1038
-#include <fcntl.h>
 
1039
-#include <unistd.h>
 
1040
 #include <string.h>
 
1041
 #include <stdlib.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
 
1047
@@ -19,8 +19,6 @@
 
1048
 
 
1049
 #include <stdio.h>
 
1050
 #include <malloc.h>
 
1051
-#include <fcntl.h>
 
1052
-#include <unistd.h>
 
1053
 #include <string.h>
 
1054
 #include <sys/param.h>
 
1055
 #include <sys/types.h>
 
1056
@@ -145,25 +143,19 @@ int swapCD(const char *device, const char *slotName)
 
1057
 {
 
1058
        int fd;                 /* file descriptor for CD-ROM device */
 
1059
        int status;             /* return status for system calls */
 
1060
-       int cl_flags;
 
1061
        int slot = -1;
 
1062
        int total_slots_available;
 
1063
 
 
1064
        slot = atoi(slotName) - 1;
 
1065
 
 
1066
        /* open device */
 
1067
-       fd = open(device, O_RDONLY | O_NONBLOCK);
 
1068
+       fd = open_fd(device, O_RDONLY | O_NONBLOCK);
 
1069
        if (fd < 0) {
 
1070
                logerr(MODPREFIX "Opening device %s failed : %s",
 
1071
                      device, strerror(errno));
 
1072
                return 1;
 
1073
        }
 
1074
 
 
1075
-       if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
 
1076
-               cl_flags |= FD_CLOEXEC;
 
1077
-               fcntl(fd, F_SETFD, cl_flags);
 
1078
-       }
 
1079
-
 
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
 
1087
@@ -15,8 +15,6 @@
 
1088
 
 
1089
 #include <stdio.h>
 
1090
 #include <malloc.h>
 
1091
-#include <fcntl.h>
 
1092
-#include <unistd.h>
 
1093
 #include <string.h>
 
1094
 #include <stdlib.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
 
1100
@@ -15,8 +15,6 @@
 
1101
 
 
1102
 #include <stdio.h>
 
1103
 #include <malloc.h>
 
1104
-#include <fcntl.h>
 
1105
-#include <unistd.h>
 
1106
 #include <string.h>
 
1107
 #include <stdlib.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
 
1113
@@ -17,8 +17,6 @@
 
1114
 #include <stdio.h>
 
1115
 #include <malloc.h>
 
1116
 #include <netdb.h>
 
1117
-#include <fcntl.h>
 
1118
-#include <unistd.h>
 
1119
 #include <stdlib.h>
 
1120
 #include <string.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
 
1126
@@ -7,7 +7,6 @@
 
1127
 #include <sys/types.h>
 
1128
 #include <ctype.h>
 
1129
 #include <string.h>
 
1130
-#include <unistd.h>
 
1131
 #include <stdlib.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
 
1138
@@ -18,8 +18,6 @@
 
1139
 #include <stdio.h>
 
1140
 #include <malloc.h>
 
1141
 #include <netdb.h>
 
1142
-#include <fcntl.h>
 
1143
-#include <unistd.h>
 
1144
 #include <stdlib.h>
 
1145
 #include <string.h>
 
1146
 #include <ctype.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
 
1151
@@ -52,8 +52,6 @@
 
1152
 #include <net/if.h>
 
1153
 #include <netinet/in.h>
 
1154
 #include <netdb.h>
 
1155
-#include <unistd.h>
 
1156
-#include <fcntl.h>
 
1157
 
 
1158
 #include "rpc_subs.h"
 
1159
 #include "replicated.h"
 
1160
@@ -82,7 +80,7 @@ void seed_random(void)
 
1161
        int fd;
 
1162
        unsigned int seed;
 
1163
 
 
1164
-       fd = open("/dev/urandom", O_RDONLY);
 
1165
+       fd = open_fd("/dev/urandom", O_RDONLY);
 
1166
        if (fd < 0) {
 
1167
                srandom(time(NULL));
 
1168
                return;
 
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;
 
1171
        struct ifconf ifc;
 
1172
        struct ifreq *ifr, nmptr;
 
1173
-       int sock, cl_flags, ret, i;
 
1174
+       int sock, ret, i;
 
1175
        uint32_t mask, ha, ia;
 
1176
 
 
1177
        memcpy(tmp, host_addr, addr_len);
 
1178
@@ -153,18 +151,13 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
 
1179
 
 
1180
        ha = ntohl((uint32_t) hst_addr->s_addr);
 
1181
 
 
1182
-       sock = socket(AF_INET, SOCK_DGRAM, 0);
 
1183
+       sock = open_sock(AF_INET, SOCK_DGRAM, 0);
 
1184
        if (sock < 0) {
 
1185
                char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 
1186
                logerr("socket creation failed: %s", estr);
 
1187
                return PROXIMITY_ERROR;
 
1188
        }
 
1189
 
 
1190
-       if ((cl_flags = fcntl(sock, F_GETFD, 0)) != -1) {
 
1191
-               cl_flags |= FD_CLOEXEC;
 
1192
-               fcntl(sock, F_SETFD, cl_flags);
 
1193
-       }
 
1194
-
 
1195
        if (!alloc_ifreq(&ifc, sock)) {
 
1196
                close(sock);
 
1197
                return PROXIMITY_ERROR;