diff options
author | Roy Marples <roy@marples.name> | 2007-07-11 17:27:46 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-07-11 17:27:46 +0000 |
commit | 5257ba51b9524b101533308024862e4344c8b6f6 (patch) | |
tree | 71c5eab595f685a02f2ab2a8adfcac304406c4e4 /src | |
parent | e778dcbfb0ef9cb8101ac7e51c88c322f7ccbd22 (diff) |
Don't unmount network filesystems in localmount or halt.sh, #175602.
Diffstat (limited to 'src')
-rw-r--r-- | src/mountinfo.c | 144 |
1 files changed, 84 insertions, 60 deletions
diff --git a/src/mountinfo.c b/src/mountinfo.c index 18243fb3..9a44466a 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -31,7 +31,8 @@ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) -static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, +static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex, + regex_t *fstype_regex, regex_t *skip_fstype_regex, char **mounts, bool list_nodes, bool list_fstype) { struct statfs *mnts; @@ -46,9 +47,15 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, if (node_regex && regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0) continue; + if (skip_node_regex && + regexec (skip_node_regex, mnts[i].f_mntfromname, 0, NULL, 0) == 0) + continue; if (fstype_regex && regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0) continue; + if (skip_fstype_regex && + regexec (skip_fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) == 0) + continue; if (mounts) { bool found = false; @@ -73,7 +80,8 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, } #elif defined (__linux__) -static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, +static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex, + regex_t *fstype_regex, regex_t *skip_fstype_regex, char **mounts, bool list_nodes, bool list_fstype) { FILE *fp; @@ -93,6 +101,9 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, if (node_regex && regexec (node_regex, from, 0, NULL, 0) != 0) continue; + if (skip_node_regex && + regexec (skip_node_regex, from, 0, NULL, 0) == 0) + continue; to = strsep (&p, " "); fstype = strsep (&p, " "); @@ -102,6 +113,9 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, if (fstype_regex && regexec (fstype_regex, fstype, 0, NULL, 0) != 0) continue; + if (skip_fstype_regex && + regexec (skip_fstype_regex, fstype, 0, NULL, 0) == 0) + continue; if (mounts) { bool found = false; @@ -130,15 +144,32 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, # error "Operating system not supported!" #endif +static regex_t *get_regex (char *string) +{ + regex_t *reg = rc_xmalloc (sizeof (regex_t)); + int result; + char buffer[256]; + + if ((result = regcomp (reg, string, REG_EXTENDED | REG_NOSUB)) != 0) + { + regerror (result, reg, buffer, sizeof (buffer)); + eerrorx ("%s: invalid regex `%s'", APPLET, buffer); + } + + return (reg); +} + #include "_usage.h" -#define getoptstring "F:N:S:fnrV" getoptstring_COMMON +#define getoptstring "f:F:n:N:p:P:os" getoptstring_COMMON static struct option longopts[] = { - { "fstype-regex", 1, NULL, 'F'}, - { "node-regex", 1, NULL, 'N'}, - { "skip-regex", 1, NULL, 'S'}, - { "fstype", 0, NULL, 'f'}, - { "node", 0, NULL, 'n'}, - { "reverse", 0, NULL, 'r'}, + { "fstype-regex", 1, NULL, 'f'}, + { "skip-fstype-regex", 1, NULL, 'F'}, + { "node-regex", 1, NULL, 'n'}, + { "skip-node-regex", 1, NULL, 'N'}, + { "point-regex", 1, NULL, 'p'}, + { "skip-point-regex", 1, NULL, 'P'}, + { "list-nodes", 0, NULL, 'o'}, + { "list-fstype", 0, NULL, 's'}, longopts_COMMON { NULL, 0, NULL, 0} }; @@ -149,100 +180,93 @@ int main (int argc, char **argv) int i; regex_t *fstype_regex = NULL; regex_t *node_regex = NULL; - regex_t *skip_regex = NULL; + regex_t *point_regex = NULL; + regex_t *skip_fstype_regex = NULL; + regex_t *skip_node_regex = NULL; + regex_t *skip_point_regex = NULL; char **nodes = NULL; char *node; - int result; - char buffer[256]; bool list_nodes = false; bool list_fstype = false; - bool reverse = false; char **mounts = NULL; int opt; + int result; + +#define DO_REG(_var) \ + if (_var) free (_var); \ + _var = get_regex (optarg); while ((opt = getopt_long (argc, argv, getoptstring, longopts, (int *) 0)) != -1) + { switch (opt) { + case 'f': + DO_REG (fstype_regex); + break; case 'F': - if (fstype_regex) - free (fstype_regex); - fstype_regex = rc_xmalloc (sizeof (regex_t)); - if ((result = regcomp (fstype_regex, optarg, - REG_EXTENDED | REG_NOSUB)) != 0) - { - regerror (result, fstype_regex, buffer, sizeof (buffer)); - eerrorx ("%s: invalid regex `%s'", argv[0], buffer); - } + DO_REG (skip_fstype_regex); + break; + case 'n': + DO_REG (node_regex); break; - case 'N': - if (node_regex) - free (node_regex); - node_regex = rc_xmalloc (sizeof (regex_t)); - if ((result = regcomp (node_regex, optarg, - REG_EXTENDED | REG_NOSUB)) != 0) - { - regerror (result, node_regex, buffer, sizeof (buffer)); - eerrorx ("%s: invalid regex `%s'", argv[0], buffer); - } + DO_REG (skip_node_regex); break; - - case 'S': - if (skip_regex) - free (skip_regex); - skip_regex = rc_xmalloc (sizeof (regex_t)); - if ((result = regcomp (skip_regex, optarg, - REG_EXTENDED | REG_NOSUB)) != 0) - { - regerror (result, skip_regex, buffer, sizeof (buffer)); - eerrorx ("%s: invalid regex `%s'", argv[0], buffer); - } + case 'p': + DO_REG (point_regex); break; - - case 'f': - list_fstype = true; - list_nodes = false; + case 'P': + DO_REG (skip_point_regex); break; - - case 'n': + case 'o': list_nodes = true; list_fstype = false; break; - - case 'r': - reverse = true; + case 's': + list_nodes = false; + list_fstype = true; break; - case_RC_COMMON_GETOPT + case_RC_COMMON_GETOPT } + } while (optind < argc) { if (argv[optind][0] != '/') eerrorx ("%s: `%s' is not a mount point", argv[0], argv[optind]); mounts = rc_strlist_add (mounts, argv[optind++]); } - nodes = find_mounts (node_regex, fstype_regex, mounts, - list_nodes, list_fstype); + + nodes = find_mounts (node_regex, skip_node_regex, + fstype_regex, skip_fstype_regex, + mounts, list_nodes, list_fstype); if (node_regex) regfree (node_regex); + if (skip_node_regex) + regfree (skip_node_regex); if (fstype_regex) regfree (fstype_regex); + if (skip_fstype_regex) + regfree (skip_fstype_regex); - if (reverse) - rc_strlist_reverse (nodes); + rc_strlist_reverse (nodes); result = EXIT_FAILURE; STRLIST_FOREACH (nodes, node, i) { - if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0) + if (point_regex && regexec (point_regex, node, 0, NULL, 0) != 0) + continue; + if (skip_point_regex && regexec (skip_point_regex, node, 0, NULL, 0) == 0) continue; printf ("%s\n", node); result = EXIT_SUCCESS; } rc_strlist_free (nodes); - if (skip_regex) - free (skip_regex); + if (point_regex) + regfree (point_regex); + if (skip_point_regex) + regfree (skip_point_regex); exit (result); } |