Messages in this thread Patch in this message |  | | | From | Nigel Cunningham <> | | Subject | [Suspend2][ 11/13] [Suspend2] Launch a userspace helper. | | Date | Tue, 27 Jun 2006 14:40:01 +1000 |
| |
Launch a userspace helper. The usermodehelper function can't take a simple string with args, so we split the arguments up into words (as required) before invoking usermodehelper.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/netlink.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/kernel/power/netlink.c b/kernel/power/netlink.c index 7b75f4f..d7a3a90 100644 --- a/kernel/power/netlink.c +++ b/kernel/power/netlink.c @@ -290,3 +290,57 @@ void suspend_netlink_close(struct user_h } } +int suspend2_launch_userspace_program(char *command, int channel_no) +{ + int retval; + static char *envp[] = { + "HOME=/", + "TERM=linux", + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", + NULL }; + static char *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + char *channel = kmalloc(6, GFP_KERNEL); + int arg = 0, size; + char test_read[255]; + char *orig_posn = command; + + if (!strlen(orig_posn)) + return 1; + + /* Up to 7 args supported */ + while (arg < 7) { + sscanf(orig_posn, "%s", test_read); + size = strlen(test_read); + if (!(size)) + break; + argv[arg] = kmalloc(size + 1, GFP_ATOMIC); + strcpy(argv[arg], test_read); + orig_posn += size + 1; + *test_read = 0; + arg++; + } + + if (channel_no) { + sprintf(channel, "-c%d", channel_no); + argv[arg] = channel; + } else + arg--; + + retval = call_usermodehelper(argv[0], argv, envp, 0); + + if (retval) + printk("Failed to launch userspace program '%s': Error %d\n", + command, retval); + + { + int i; + for (i = 0; i < arg; i++) + if (argv[i] && argv[i] != channel) + kfree(argv[i]); + } + + kfree(channel); + + return retval; +} + -- Nigel Cunningham nigel at suspend2 dot net - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|  |