Deleted Added
full compact
automountd.c (274548) automountd.c (279741)
1/*-
2 * Copyright (c) 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/10/usr.sbin/autofs/automountd.c 274548 2014-11-15 05:53:45Z trasz $");
32__FBSDID("$FreeBSD: stable/10/usr.sbin/autofs/automountd.c 279741 2015-03-07 19:32:19Z trasz $");
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/ioctl.h>
37#include <sys/param.h>
38#include <sys/linker.h>
39#include <sys/mount.h>
40#include <sys/socket.h>

--- 22 unchanged lines hidden (view full) ---

63
64#define AUTOMOUNTD_PIDFILE "/var/run/automountd.pid"
65
66static int nchildren = 0;
67static int autofs_fd;
68static int request_id;
69
70static void
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/ioctl.h>
37#include <sys/param.h>
38#include <sys/linker.h>
39#include <sys/mount.h>
40#include <sys/socket.h>

--- 22 unchanged lines hidden (view full) ---

63
64#define AUTOMOUNTD_PIDFILE "/var/run/automountd.pid"
65
66static int nchildren = 0;
67static int autofs_fd;
68static int request_id;
69
70static void
71done(int request_error)
71done(int request_error, bool wildcards)
72{
73 struct autofs_daemon_done add;
74 int error;
75
76 memset(&add, 0, sizeof(add));
77 add.add_id = request_id;
72{
73 struct autofs_daemon_done add;
74 int error;
75
76 memset(&add, 0, sizeof(add));
77 add.add_id = request_id;
78 add.add_wildcards = wildcards;
78 add.add_error = request_error;
79
80 log_debugx("completing request %d with error %d",
81 request_id, request_error);
82
83 error = ioctl(autofs_fd, AUTOFSDONE, &add);
84 if (error != 0) {
85 /*

--- 81 unchanged lines hidden (view full) ---

167 TAILQ_FOREACH(child, &node->n_children, n_next)
168 create_subtree(child, incomplete);
169}
170
171static void
172exit_callback(void)
173{
174
79 add.add_error = request_error;
80
81 log_debugx("completing request %d with error %d",
82 request_id, request_error);
83
84 error = ioctl(autofs_fd, AUTOFSDONE, &add);
85 if (error != 0) {
86 /*

--- 81 unchanged lines hidden (view full) ---

168 TAILQ_FOREACH(child, &node->n_children, n_next)
169 create_subtree(child, incomplete);
170}
171
172static void
173exit_callback(void)
174{
175
175 done(EIO);
176 done(EIO, true);
176}
177
178static void
179handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
180 bool incomplete_hierarchy)
181{
182 const char *map;
183 struct node *root, *parent, *node;
184 FILE *f;
185 char *options, *fstype, *nobrowse, *retrycnt, *tmp;
186 int error;
177}
178
179static void
180handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
181 bool incomplete_hierarchy)
182{
183 const char *map;
184 struct node *root, *parent, *node;
185 FILE *f;
186 char *options, *fstype, *nobrowse, *retrycnt, *tmp;
187 int error;
188 bool wildcards;
187
188 log_debugx("got request %d: from %s, path %s, prefix \"%s\", "
189 "key \"%s\", options \"%s\"", adr->adr_id, adr->adr_from,
190 adr->adr_path, adr->adr_prefix, adr->adr_key, adr->adr_options);
191
192 /*
193 * Try to notify the kernel about any problems.
194 */

--- 9 unchanged lines hidden (view full) ---

204 root = node_new_root();
205 if (adr->adr_prefix[0] == '\0' || strcmp(adr->adr_prefix, "/") == 0) {
206 parent = root;
207 } else {
208 parent = node_new_map(root, checked_strdup(adr->adr_prefix),
209 checked_strdup(adr->adr_options), checked_strdup(map),
210 checked_strdup("[kernel request]"), lineno);
211 }
189
190 log_debugx("got request %d: from %s, path %s, prefix \"%s\", "
191 "key \"%s\", options \"%s\"", adr->adr_id, adr->adr_from,
192 adr->adr_path, adr->adr_prefix, adr->adr_key, adr->adr_options);
193
194 /*
195 * Try to notify the kernel about any problems.
196 */

--- 9 unchanged lines hidden (view full) ---

206 root = node_new_root();
207 if (adr->adr_prefix[0] == '\0' || strcmp(adr->adr_prefix, "/") == 0) {
208 parent = root;
209 } else {
210 parent = node_new_map(root, checked_strdup(adr->adr_prefix),
211 checked_strdup(adr->adr_options), checked_strdup(map),
212 checked_strdup("[kernel request]"), lineno);
213 }
212 parse_map(parent, map, adr->adr_key[0] != '\0' ? adr->adr_key : NULL);
214
215 /*
216 * "Wildcards" here actually means "make autofs(4) request
217 * automountd(8) action if the node being looked up does not
218 * exist, even though the parent is marked as cached". This
219 * needs to be done for maps with wildcard entries, but also
220 * for special and executable maps.
221 */
222 parse_map(parent, map, adr->adr_key[0] != '\0' ? adr->adr_key : NULL,
223 &wildcards);
224 if (!wildcards)
225 wildcards = node_has_wildcards(parent);
226 if (wildcards)
227 log_debugx("map may contain wildcard entries");
228 else
229 log_debugx("map does not contain wildcard entries");
230
213 if (adr->adr_key[0] != '\0')
214 node_expand_wildcard(root, adr->adr_key);
231 if (adr->adr_key[0] != '\0')
232 node_expand_wildcard(root, adr->adr_key);
233
215 node = node_find(root, adr->adr_path);
216 if (node == NULL) {
217 log_errx(1, "map %s does not contain key for \"%s\"; "
218 "failing mount", map, adr->adr_path);
219 }
220
221 if (node->n_location == NULL) {
222 log_debugx("found node defined at %s:%d; not a mountpoint",

--- 8 unchanged lines hidden (view full) ---

231 options =
232 separated_concat(cmdline_options, options, ',');
233 }
234
235 nobrowse = pick_option("nobrowse", &options);
236 if (nobrowse != NULL && adr->adr_key[0] == '\0') {
237 log_debugx("skipping map %s due to \"nobrowse\" "
238 "option; exiting", map);
234 node = node_find(root, adr->adr_path);
235 if (node == NULL) {
236 log_errx(1, "map %s does not contain key for \"%s\"; "
237 "failing mount", map, adr->adr_path);
238 }
239
240 if (node->n_location == NULL) {
241 log_debugx("found node defined at %s:%d; not a mountpoint",

--- 8 unchanged lines hidden (view full) ---

250 options =
251 separated_concat(cmdline_options, options, ',');
252 }
253
254 nobrowse = pick_option("nobrowse", &options);
255 if (nobrowse != NULL && adr->adr_key[0] == '\0') {
256 log_debugx("skipping map %s due to \"nobrowse\" "
257 "option; exiting", map);
239 done(0);
258 done(0, true);
240
241 /*
242 * Exit without calling exit_callback().
243 */
244 quick_exit(0);
245 }
246
247 /*

--- 10 unchanged lines hidden (view full) ---

258 tmp = separated_concat(adr->adr_path,
259 adr->adr_key, '/');
260 node = node_find(root, tmp);
261 if (node != NULL)
262 create_subtree(node, false);
263 }
264
265 log_debugx("nothing to mount; exiting");
259
260 /*
261 * Exit without calling exit_callback().
262 */
263 quick_exit(0);
264 }
265
266 /*

--- 10 unchanged lines hidden (view full) ---

277 tmp = separated_concat(adr->adr_path,
278 adr->adr_key, '/');
279 node = node_find(root, tmp);
280 if (node != NULL)
281 create_subtree(node, false);
282 }
283
284 log_debugx("nothing to mount; exiting");
266 done(0);
285 done(0, wildcards);
267
268 /*
269 * Exit without calling exit_callback().
270 */
271 quick_exit(0);
272 }
273
274 log_debugx("found node defined at %s:%d; it is a mountpoint",

--- 57 unchanged lines hidden (view full) ---

332 f = auto_popen("mount", "-t", fstype, "-o", options,
333 node->n_location, adr->adr_path, NULL);
334 assert(f != NULL);
335 error = auto_pclose(f);
336 if (error != 0)
337 log_errx(1, "mount failed");
338
339 log_debugx("mount done; exiting");
286
287 /*
288 * Exit without calling exit_callback().
289 */
290 quick_exit(0);
291 }
292
293 log_debugx("found node defined at %s:%d; it is a mountpoint",

--- 57 unchanged lines hidden (view full) ---

351 f = auto_popen("mount", "-t", fstype, "-o", options,
352 node->n_location, adr->adr_path, NULL);
353 assert(f != NULL);
354 error = auto_pclose(f);
355 if (error != 0)
356 log_errx(1, "mount failed");
357
358 log_debugx("mount done; exiting");
340 done(0);
359 done(0, wildcards);
341
342 /*
343 * Exit without calling exit_callback().
344 */
345 quick_exit(0);
346}
347
348static void

--- 208 unchanged lines hidden ---
360
361 /*
362 * Exit without calling exit_callback().
363 */
364 quick_exit(0);
365}
366
367static void

--- 208 unchanged lines hidden ---