summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2014-10-19 23:05:18 +0000
committerneel <neel@FreeBSD.org>2014-10-19 23:05:18 +0000
commit53c23ba9a2104ef3682a2b22cb1ab9269ca0745d (patch)
tree5660ad82f8ccde1ac8cad42c5caa05dc307f1c94 /usr.sbin
parent13e9198693c3c4ccfd604fbab375f3b96aa149dc (diff)
parent0486efbb500e4ad95f421a2b8786764022256893 (diff)
downloadFreeBSD-src-53c23ba9a2104ef3682a2b22cb1ab9269ca0745d.zip
FreeBSD-src-53c23ba9a2104ef3682a2b22cb1ab9269ca0745d.tar.gz
IFC @r273206
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/autofs/automountd.c62
-rw-r--r--usr.sbin/autofs/common.c29
-rw-r--r--usr.sbin/autofs/common.h4
-rw-r--r--usr.sbin/autofs/token.l2
-rwxr-xr-xusr.sbin/bsdconfig/includes/includes8
-rw-r--r--usr.sbin/bsdconfig/share/device.subr5
-rw-r--r--usr.sbin/bsdconfig/share/packages/index.subr8
7 files changed, 98 insertions, 20 deletions
diff --git a/usr.sbin/autofs/automountd.c b/usr.sbin/autofs/automountd.c
index b511103..44143e5 100644
--- a/usr.sbin/autofs/automountd.c
+++ b/usr.sbin/autofs/automountd.c
@@ -68,13 +68,14 @@ static int autofs_fd;
static int request_id;
static void
-done(int request_error)
+done(int request_error, bool wildcards)
{
struct autofs_daemon_done add;
int error;
memset(&add, 0, sizeof(add));
add.add_id = request_id;
+ add.add_wildcards = wildcards;
add.add_error = request_error;
log_debugx("completing request %d with error %d",
@@ -172,7 +173,7 @@ static void
exit_callback(void)
{
- done(EIO);
+ done(EIO, true);
}
static void
@@ -184,6 +185,7 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
FILE *f;
char *options, *fstype, *nobrowse, *retrycnt, *tmp;
int error;
+ bool wildcards;
log_debugx("got request %d: from %s, path %s, prefix \"%s\", "
"key \"%s\", options \"%s\"", adr->adr_id, adr->adr_from,
@@ -209,9 +211,26 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
checked_strdup(adr->adr_options), checked_strdup(map),
checked_strdup("[kernel request]"), lineno);
}
- parse_map(parent, map, adr->adr_key[0] != '\0' ? adr->adr_key : NULL);
+
+ /*
+ * "Wildcards" here actually means "make autofs(4) request
+ * automountd(8) action if the node being looked up does not
+ * exist, even though the parent is marked as cached". This
+ * needs to be done for maps with wildcard entries, but also
+ * for special and executable maps.
+ */
+ parse_map(parent, map, adr->adr_key[0] != '\0' ? adr->adr_key : NULL,
+ &wildcards);
+ if (!wildcards)
+ wildcards = node_has_wildcards(parent);
+ if (wildcards)
+ log_debugx("map may contain wildcard entries");
+ else
+ log_debugx("map does not contain wildcard entries");
+
if (adr->adr_key[0] != '\0')
node_expand_wildcard(root, adr->adr_key);
+
node = node_find(root, adr->adr_path);
if (node == NULL) {
log_errx(1, "map %s does not contain key for \"%s\"; "
@@ -236,7 +255,7 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
if (nobrowse != NULL && adr->adr_key[0] == '\0') {
log_debugx("skipping map %s due to \"nobrowse\" "
"option; exiting", map);
- done(0);
+ done(0, true);
/*
* Exit without calling exit_callback().
@@ -263,7 +282,7 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
}
log_debugx("nothing to mount; exiting");
- done(0);
+ done(0, wildcards);
/*
* Exit without calling exit_callback().
@@ -337,7 +356,7 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
log_errx(1, "mount failed");
log_debugx("mount done; exiting");
- done(0);
+ done(0, wildcards);
/*
* Exit without calling exit_callback().
@@ -345,6 +364,33 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
quick_exit(0);
}
+static void
+sigchld_handler(int dummy __unused)
+{
+
+ /*
+ * The only purpose of this handler is to make SIGCHLD
+ * interrupt the AUTOFSREQUEST ioctl(2), so we can call
+ * wait_for_children().
+ */
+}
+
+static void
+register_sigchld(void)
+{
+ struct sigaction sa;
+ int error;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = sigchld_handler;
+ sigfillset(&sa.sa_mask);
+ error = sigaction(SIGCHLD, &sa, NULL);
+ if (error != 0)
+ log_err(1, "sigaction");
+
+}
+
+
static int
wait_for_children(bool block)
{
@@ -366,7 +412,7 @@ wait_for_children(bool block)
log_warnx("child process %d terminated with signal %d",
pid, WTERMSIG(status));
} else if (WEXITSTATUS(status) != 0) {
- log_warnx("child process %d terminated with exit status %d",
+ log_debugx("child process %d terminated with exit status %d",
pid, WEXITSTATUS(status));
} else {
log_debugx("child process %d terminated gracefully", pid);
@@ -477,6 +523,8 @@ main_automountd(int argc, char **argv)
pidfile_write(pidfh);
+ register_sigchld();
+
for (;;) {
log_debugx("waiting for request from the kernel");
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c
index e6db682..6fd8a05 100644
--- a/usr.sbin/autofs/common.c
+++ b/usr.sbin/autofs/common.c
@@ -498,6 +498,19 @@ node_is_direct_map(const struct node *n)
return (true);
}
+bool
+node_has_wildcards(const struct node *n)
+{
+ const struct node *child;
+
+ TAILQ_FOREACH(child, &n->n_children, n_next) {
+ if (strcmp(child->n_key, "*") == 0)
+ return (true);
+ }
+
+ return (false);
+}
+
static void
node_expand_maps(struct node *n, bool indirect)
{
@@ -526,7 +539,7 @@ node_expand_maps(struct node *n, bool indirect)
log_debugx("map \"%s\" is a direct map, parsing",
child->n_map);
}
- parse_map(child, child->n_map, NULL);
+ parse_map(child, child->n_map, NULL, NULL);
}
}
@@ -996,7 +1009,8 @@ parse_included_map(struct node *parent, const char *map)
}
void
-parse_map(struct node *parent, const char *map, const char *key)
+parse_map(struct node *parent, const char *map, const char *key,
+ bool *wildcards)
{
char *path = NULL;
int error, ret;
@@ -1007,8 +1021,14 @@ parse_map(struct node *parent, const char *map, const char *key)
log_debugx("parsing map \"%s\"", map);
- if (map[0] == '-')
+ if (wildcards != NULL)
+ *wildcards = false;
+
+ if (map[0] == '-') {
+ if (wildcards != NULL)
+ *wildcards = true;
return (parse_special_map(parent, map, key));
+ }
if (map[0] == '/') {
path = checked_strdup(map);
@@ -1035,6 +1055,9 @@ parse_map(struct node *parent, const char *map, const char *key)
if (executable) {
log_debugx("map \"%s\" is executable", map);
+ if (wildcards != NULL)
+ *wildcards = true;
+
if (key != NULL) {
yyin = auto_popen(path, key, NULL);
} else {
diff --git a/usr.sbin/autofs/common.h b/usr.sbin/autofs/common.h
index bc0b6f6..16a8d73 100644
--- a/usr.sbin/autofs/common.h
+++ b/usr.sbin/autofs/common.h
@@ -80,6 +80,7 @@ struct node *node_new_map(struct node *parent, char *key, char *options,
char *map, const char *config_file, int config_line);
struct node *node_find(struct node *root, const char *mountpoint);
bool node_is_direct_map(const struct node *n);
+bool node_has_wildcards(const struct node *n);
char *node_path(const struct node *n);
char *node_options(const struct node *n);
void node_expand_ampersand(struct node *root, const char *key);
@@ -88,7 +89,8 @@ int node_expand_defined(struct node *root);
void node_expand_indirect_maps(struct node *n);
void node_print(const struct node *n);
void parse_master(struct node *root, const char *path);
-void parse_map(struct node *parent, const char *map, const char *args);
+void parse_map(struct node *parent, const char *map, const char *args,
+ bool *wildcards);
char *defined_expand(const char *string);
void defined_init(void);
void defined_parse_and_add(char *def);
diff --git a/usr.sbin/autofs/token.l b/usr.sbin/autofs/token.l
index 5062a13..6a92b7f 100644
--- a/usr.sbin/autofs/token.l
+++ b/usr.sbin/autofs/token.l
@@ -49,7 +49,7 @@ extern int yylex(void);
%%
\"[^"]+\" { yytext++; yytext[strlen(yytext) - 1] = '\0'; return STR; };
-[a-zA-Z0-9\.\+-_/\:\[\]$&{}]+ { return STR; }
+[a-zA-Z0-9\.\+-_/\:\[\]$&%{}]+ { return STR; }
#.*\n { lineno++; return NEWLINE; };
\\\n { lineno++; };
\n { lineno++; return NEWLINE; }
diff --git a/usr.sbin/bsdconfig/includes/includes b/usr.sbin/bsdconfig/includes/includes
index d831649..6e9906f 100755
--- a/usr.sbin/bsdconfig/includes/includes
+++ b/usr.sbin/bsdconfig/includes/includes
@@ -69,10 +69,12 @@ show_include()
-v use_color=${USE_COLOR:-0} \
-v re="$pattern" \
-v show_desc=${SHOW_DESC:-0} '
- function asorti(src, dest)
+ function _asorti(src, dest)
{
+ k = nitems = 0;
+
# Copy src indices to dest and calculate array length
- nitems = 0; for (i in src) dest[++nitems] = i
+ for (i in src) dest[++nitems] = i
# Sort the array of indices (dest) using insertion sort method
for (i = 1; i <= nitems; k = i++)
@@ -118,7 +120,7 @@ show_include()
}
}
END {
- n = asorti(syntax, sorted_indices)
+ n = _asorti(syntax, sorted_indices)
for (i = 1; i <= n; i++)
printf "%s", syntax[sorted_indices[i]]
}' "$file" )
diff --git a/usr.sbin/bsdconfig/share/device.subr b/usr.sbin/bsdconfig/share/device.subr
index d93cd9b..d95684d 100644
--- a/usr.sbin/bsdconfig/share/device.subr
+++ b/usr.sbin/bsdconfig/share/device.subr
@@ -1116,8 +1116,9 @@ f_device_shutdown()
f_device_sort_by_awk='
# Variables that should be defined on the invocation line:
# -v prop="property"
-function asorti(src, dest)
+function _asorti(src, dest)
{
+ k = nitems = 0
for (i in src) dest[++nitems] = i
for (i = 1; i <= nitems; k = i++) {
idx = dest[i]
@@ -1136,7 +1137,7 @@ function asorti(src, dest)
}
}
END {
- nitems = asorti(devices, devices_sorted)
+ nitems = _asorti(devices, devices_sorted)
for (i = 1; i <= nitems; i++) print devices[devices_sorted[i]]
}
'
diff --git a/usr.sbin/bsdconfig/share/packages/index.subr b/usr.sbin/bsdconfig/share/packages/index.subr
index 35ef0da..f3c1713 100644
--- a/usr.sbin/bsdconfig/share/packages/index.subr
+++ b/usr.sbin/bsdconfig/share/packages/index.subr
@@ -241,10 +241,12 @@ f_index_read()
export msg_packages
eval "$( debug= f_getvar "$var_to_get" | awk -F'|' '
- function asorti(src, dest)
+ function _asorti(src, dest)
{
+ k = nitems = 0
+
# Copy src indices to dest and calculate array length
- nitems = 0; for (i in src) dest[++nitems] = i
+ for (i in src) dest[++nitems] = i
# Sort the array of indices (dest) using insertion sort method
for (i = 1; i <= nitems; k = i++)
@@ -290,7 +292,7 @@ f_index_read()
END {
print "_npkgs=" tpkgs # For convenience, total package count
- n = asorti(categories, categories_sorted)
+ n = _asorti(categories, categories_sorted)
# Produce package counts for each category
for (i = 1; i <= n; i++)
OpenPOWER on IntegriCloud