]>
Commit | Line | Data |
---|---|---|
e5fd101c PS |
1 | autofs-5.0.4 - use CLOEXEC flag for setmntent |
2 | ||
3 | From: Ian Kent <raven@themaw.net> | |
4 | ||
5 | Update use of CLOEXEC functionality to cover setmntent(3) | |
6 | calls as well. | |
7 | --- | |
8 | ||
9 | CHANGELOG | 1 + | |
10 | include/automount.h | 20 ++++++++++++++++++++ | |
11 | lib/mounts.c | 8 ++++---- | |
12 | 3 files changed, 25 insertions(+), 4 deletions(-) | |
13 | ||
14 | ||
15 | diff --git a/CHANGELOG b/CHANGELOG | |
16 | index af77b55..eb4a189 100644 | |
17 | --- a/CHANGELOG | |
18 | +++ b/CHANGELOG | |
19 | @@ -8,6 +8,7 @@ | |
20 | - make hash table scale to thousands of entries (Paul Wankadia, | |
21 | Valerie Aurora Henson). | |
22 | - clear the quoted flag after each character from program map input. | |
23 | +- use CLOEXEC flag for setmntent also. | |
24 | ||
25 | 4/11/2008 autofs-5.0.4 | |
26 | ----------------------- | |
27 | diff --git a/include/automount.h b/include/automount.h | |
28 | index 005d209..46cb6c6 100644 | |
29 | --- a/include/automount.h | |
30 | +++ b/include/automount.h | |
31 | @@ -581,5 +581,25 @@ static inline FILE *open_fopen_r(const char *path) | |
32 | return f; | |
33 | } | |
34 | ||
35 | +static inline FILE *open_setmntent_r(const char *table) | |
36 | +{ | |
37 | + FILE *tab; | |
38 | + | |
39 | +#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) | |
40 | + if (cloexec_works != -1) { | |
41 | + tab = setmntent(table, "re"); | |
42 | + if (tab != NULL) { | |
43 | + check_cloexec(fileno(tab)); | |
44 | + return tab; | |
45 | + } | |
46 | + } | |
47 | +#endif | |
48 | + tab = fopen(table, "r"); | |
49 | + if (tab == NULL) | |
50 | + return NULL; | |
51 | + check_cloexec(fileno(tab)); | |
52 | + return tab; | |
53 | +} | |
54 | + | |
55 | #endif | |
56 | ||
57 | diff --git a/lib/mounts.c b/lib/mounts.c | |
58 | index ce4691b..b98e1a4 100644 | |
59 | --- a/lib/mounts.c | |
60 | +++ b/lib/mounts.c | |
61 | @@ -218,7 +218,7 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include) | |
62 | if (!path || !pathlen || pathlen > PATH_MAX) | |
63 | return NULL; | |
64 | ||
65 | - tab = setmntent(table, "r"); | |
66 | + tab = open_setmntent_r(table); | |
67 | if (!tab) { | |
68 | char *estr = strerror_r(errno, buf, PATH_MAX - 1); | |
69 | logerr("setmntent: %s", estr); | |
70 | @@ -415,7 +415,7 @@ static int table_is_mounted(const char *table, const char *path, unsigned int ty | |
71 | if (!path || !pathlen || pathlen >= PATH_MAX) | |
72 | return 0; | |
73 | ||
74 | - tab = setmntent(table, "r"); | |
75 | + tab = open_setmntent_r(table); | |
76 | if (!tab) { | |
77 | char *estr = strerror_r(errno, buf, PATH_MAX - 1); | |
78 | logerr("setmntent: %s", estr); | |
79 | @@ -489,7 +489,7 @@ int has_fstab_option(const char *opt) | |
80 | if (!opt) | |
81 | return 0; | |
82 | ||
83 | - tab = setmntent(_PATH_MNTTAB, "r"); | |
84 | + tab = open_setmntent_r(_PATH_MNTTAB); | |
85 | if (!tab) { | |
86 | char *estr = strerror_r(errno, buf, PATH_MAX - 1); | |
87 | logerr("setmntent: %s", estr); | |
88 | @@ -668,7 +668,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path) | |
89 | size_t plen; | |
90 | int eq; | |
91 | ||
92 | - tab = setmntent(table, "r"); | |
93 | + tab = open_setmntent_r(table); | |
94 | if (!tab) { | |
95 | char *estr = strerror_r(errno, buf, PATH_MAX - 1); | |
96 | logerr("setmntent: %s", estr); |