From: Lucas De Marchi <lucas.de.marchi@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>,
Oleg Nesterov <oleg@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 1/3] argv_split(): Allow extra params
Date: Fri, 10 May 2013 01:15:14 -0300 [thread overview]
Message-ID: <1368159316-31744-1-git-send-email-lucas.de.marchi@gmail.com> (raw)
Add an argument allowing argv_split to leave room for parameters to be
filled by the caller. This is useful in situations we want to split the
command and add a options as the last arguments.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
---
fs/coredump.c | 2 +-
include/linux/string.h | 3 ++-
kernel/sys.c | 2 +-
kernel/trace/trace_events_filter.c | 2 +-
kernel/trace/trace_probe.c | 2 +-
lib/argv_split.c | 13 +++++++------
6 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/fs/coredump.c b/fs/coredump.c
index d52f6bd..08697cf 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -565,7 +565,7 @@ void do_coredump(siginfo_t *siginfo)
goto fail_dropcount;
}
- helper_argv = argv_split(GFP_KERNEL, cn.corename+1, NULL);
+ helper_argv = argv_split(GFP_KERNEL, cn.corename+1, NULL, 0);
if (!helper_argv) {
printk(KERN_WARNING "%s failed to allocate memory\n",
__func__);
diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..e2245e5 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -116,7 +116,8 @@ extern char *kstrdup(const char *s, gfp_t gfp);
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
-extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
+extern char **argv_split(gfp_t gfp, const char *str, int *argcp,
+ unsigned int extra);
extern void argv_free(char **argv);
extern bool sysfs_streq(const char *s1, const char *s2);
diff --git a/kernel/sys.c b/kernel/sys.c
index 0da73cf..d363325 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2196,7 +2196,7 @@ static int __orderly_poweroff(bool force)
};
int ret;
- argv = argv_split(GFP_KERNEL, poweroff_cmd, NULL);
+ argv = argv_split(GFP_KERNEL, poweroff_cmd, NULL, 0);
if (argv) {
ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
argv_free(argv);
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index e5b0ca8..3c107b2 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1981,7 +1981,7 @@ ftrace_function_filter_re(char *buf, int len, int *count)
while ((sep = strchr(str, ',')))
*sep = ' ';
- re = argv_split(GFP_KERNEL, str, count);
+ re = argv_split(GFP_KERNEL, str, count, 0);
kfree(str);
return re;
}
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 412e959..29128dd 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -770,7 +770,7 @@ int traceprobe_command(const char *buf, int (*createfn)(int, char **))
argc = 0;
ret = 0;
- argv = argv_split(GFP_KERNEL, buf, &argc);
+ argv = argv_split(GFP_KERNEL, buf, &argc, 0);
if (!argv)
return -ENOMEM;
diff --git a/lib/argv_split.c b/lib/argv_split.c
index e927ed0..9ebcbb0 100644
--- a/lib/argv_split.c
+++ b/lib/argv_split.c
@@ -43,20 +43,21 @@ EXPORT_SYMBOL(argv_free);
* argv_split - split a string at whitespace, returning an argv
* @gfp: the GFP mask used to allocate memory
* @str: the string to be split
- * @argcp: returned argument count
+ * @argcp: returned argument count without counting extras
+ * @extra: room left for extra arguments to be filled by caller
*
* Returns an array of pointers to strings which are split out from
* @str. This is performed by strictly splitting on white-space; no
* quote processing is performed. Multiple whitespace characters are
* considered to be a single argument separator. The returned array
- * is always NULL-terminated. Returns NULL on memory allocation
- * failure.
+ * is always NULL-terminated, after any possible extra argument.
+ * Returns NULL on memory allocation failure.
*
* The source string at `str' may be undergoing concurrent alteration via
* userspace sysctl activity (at least). The argv_split() implementation
* attempts to handle this gracefully by taking a local copy to work on.
*/
-char **argv_split(gfp_t gfp, const char *str, int *argcp)
+char **argv_split(gfp_t gfp, const char *str, int *argcp, unsigned int extra)
{
char *argv_str;
bool was_space;
@@ -68,7 +69,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
return NULL;
argc = count_argc(argv_str);
- argv = kmalloc(sizeof(*argv) * (argc + 2), gfp);
+ argv = kmalloc(sizeof(*argv) * (argc + 2 + extra), gfp);
if (!argv) {
kfree(argv_str);
return NULL;
@@ -85,7 +86,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
*argv++ = argv_str;
}
}
- *argv = NULL;
+ argv[extra] = NULL;
if (argcp)
*argcp = argc;
--
1.8.2.2
next reply other threads:[~2013-05-10 4:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-10 4:15 Lucas De Marchi [this message]
2013-05-10 4:15 ` [PATCH 2/3] kmod: Use argv_split(), passing module as extra param Lucas De Marchi
2013-05-10 4:15 ` [PATCH 3/3] init/Kconfig: Add option to set modprobe command Lucas De Marchi
2013-05-10 12:58 ` Oleg Nesterov
2013-05-10 13:12 ` Oleg Nesterov
2013-05-10 13:15 ` Lucas De Marchi
2013-05-10 15:36 ` Oleg Nesterov
2013-05-10 16:03 ` Lucas De Marchi
2013-05-10 17:10 ` Oleg Nesterov
2013-05-10 17:35 ` Oleg Nesterov
2013-05-10 17:44 ` Lucas De Marchi
2013-05-13 13:59 ` Oleg Nesterov
2013-05-11 20:10 ` Lucas De Marchi
2013-05-13 14:16 ` Oleg Nesterov
2013-05-13 14:35 ` [RFC] teach argv_split() to ignore the spaces surrounded by \e Oleg Nesterov
2013-05-13 16:06 ` Colin Walters
2013-05-13 17:13 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1368159316-31744-1-git-send-email-lucas.de.marchi@gmail.com \
--to=lucas.de.marchi@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®