|
|
cef8f8 |
autofs-5.1.3 - add function construct_argv()
|
|
|
cef8f8 |
|
|
|
cef8f8 |
From: Ian Kent <raven@themaw.net>
|
|
|
cef8f8 |
|
|
|
cef8f8 |
Add a function to decompose a string into a program path and an
|
|
|
cef8f8 |
arguments vector ready for an execv(3) invocation.
|
|
|
cef8f8 |
|
|
|
cef8f8 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
cef8f8 |
---
|
|
|
cef8f8 |
CHANGELOG | 1
|
|
|
cef8f8 |
include/parse_subs.h | 1
|
|
|
cef8f8 |
lib/parse_subs.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
cef8f8 |
3 files changed, 82 insertions(+)
|
|
|
cef8f8 |
|
|
|
cef8f8 |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
cef8f8 |
+++ autofs-5.0.7/CHANGELOG
|
|
|
cef8f8 |
@@ -280,6 +280,7 @@
|
|
|
cef8f8 |
- remove path restriction of amd external mount.
|
|
|
cef8f8 |
- add function umount_amd_ext_mount().
|
|
|
cef8f8 |
- add function ext_mount_inuse().
|
|
|
cef8f8 |
+- add function construct_argv().
|
|
|
cef8f8 |
|
|
|
cef8f8 |
25/07/2012 autofs-5.0.7
|
|
|
cef8f8 |
=======================
|
|
|
cef8f8 |
--- autofs-5.0.7.orig/include/parse_subs.h
|
|
|
cef8f8 |
+++ autofs-5.0.7/include/parse_subs.h
|
|
|
cef8f8 |
@@ -125,6 +125,7 @@ char *sanitize_path(const char *, int, u
|
|
|
cef8f8 |
char *merge_options(const char *, const char *);
|
|
|
cef8f8 |
int expandamdent(const char *, char *, const struct substvar *);
|
|
|
cef8f8 |
int expand_selectors(struct autofs_point *, const char *, char **, struct substvar *);
|
|
|
cef8f8 |
+int construct_argv(char *, char **, char ***);
|
|
|
cef8f8 |
void free_map_type_info(struct map_type_info *);
|
|
|
cef8f8 |
struct map_type_info *parse_map_type_info(const char *);
|
|
|
cef8f8 |
|
|
|
cef8f8 |
--- autofs-5.0.7.orig/lib/parse_subs.c
|
|
|
cef8f8 |
+++ autofs-5.0.7/lib/parse_subs.c
|
|
|
cef8f8 |
@@ -1191,6 +1191,86 @@ int expand_selectors(struct autofs_point
|
|
|
cef8f8 |
return len;
|
|
|
cef8f8 |
}
|
|
|
cef8f8 |
|
|
|
cef8f8 |
+/* Get next space seperated argument, arguments containing
|
|
|
cef8f8 |
+ * space characters may be single quoted.
|
|
|
cef8f8 |
+ */
|
|
|
cef8f8 |
+static char *next_arg(char *str, char **next)
|
|
|
cef8f8 |
+{
|
|
|
cef8f8 |
+ char *start;
|
|
|
cef8f8 |
+ char *ptr;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ if (!*str)
|
|
|
cef8f8 |
+ return NULL;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ start = ptr = str;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ /* The amd map format parser should ensure there
|
|
|
cef8f8 |
+ * are matching single quotes.
|
|
|
cef8f8 |
+ */
|
|
|
cef8f8 |
+ if (*start == 39) {
|
|
|
cef8f8 |
+ start++;
|
|
|
cef8f8 |
+ ptr++;
|
|
|
cef8f8 |
+ while (*ptr && *ptr != 39)
|
|
|
cef8f8 |
+ ptr++;
|
|
|
cef8f8 |
+ } else {
|
|
|
cef8f8 |
+ while (*ptr && *ptr != ' ')
|
|
|
cef8f8 |
+ ptr++;
|
|
|
cef8f8 |
+ }
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ if (*ptr)
|
|
|
cef8f8 |
+ *ptr++ = 0;
|
|
|
cef8f8 |
+ *next = ptr;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ return start;
|
|
|
cef8f8 |
+}
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+/* Construct program path name plus argument array for use with
|
|
|
cef8f8 |
+ * execv(3).
|
|
|
cef8f8 |
+ */
|
|
|
cef8f8 |
+int construct_argv(char *str, char **prog, char ***argv)
|
|
|
cef8f8 |
+{
|
|
|
cef8f8 |
+ char *program = NULL;
|
|
|
cef8f8 |
+ char *start, *next;
|
|
|
cef8f8 |
+ char **args, *arg;
|
|
|
cef8f8 |
+ int argc;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ start = str;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ args = malloc(sizeof(char *));
|
|
|
cef8f8 |
+ if (!args)
|
|
|
cef8f8 |
+ return -1;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ args[0] = NULL;
|
|
|
cef8f8 |
+ argc = 0;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ next = NULL;
|
|
|
cef8f8 |
+ program = next_arg(str, &next;;
|
|
|
cef8f8 |
+ if (!program) {
|
|
|
cef8f8 |
+ free(args);
|
|
|
cef8f8 |
+ return -1;
|
|
|
cef8f8 |
+ }
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ start = next;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ while (1) {
|
|
|
cef8f8 |
+ if (!*next)
|
|
|
cef8f8 |
+ break;
|
|
|
cef8f8 |
+ arg = next_arg(start, &next;;
|
|
|
cef8f8 |
+ if (arg) {
|
|
|
cef8f8 |
+ argc++;
|
|
|
cef8f8 |
+ args = add_argv(argc, args, arg);
|
|
|
cef8f8 |
+ if (!args)
|
|
|
cef8f8 |
+ return -1;
|
|
|
cef8f8 |
+ }
|
|
|
cef8f8 |
+ start = next;
|
|
|
cef8f8 |
+ }
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ *prog = program;
|
|
|
cef8f8 |
+ *argv = args;
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
+ return argc;
|
|
|
cef8f8 |
+}
|
|
|
cef8f8 |
+
|
|
|
cef8f8 |
void free_map_type_info(struct map_type_info *info)
|
|
|
cef8f8 |
{
|
|
|
cef8f8 |
if (info->type)
|