From 6858b5342f8811923d67f4c54213a5fd827aae3d Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 8 Jun 2001 19:41:51 +0000 Subject: [PATCH] support G_SPAWN_FILE_AND_ARGV_ZERO specifying that the vector passed in to 2001-06-08 Havoc Pennington * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that the vector passed in to g_spawn_* contains a filename to execute in argv[0] then the actual argv begins at argv + 1. Kind of a lame hack, but this isn't something you commonly want to do, and avoids adding more function arguments. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-0 | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-2 | 8 ++++++++ ChangeLog.pre-2-4 | 8 ++++++++ ChangeLog.pre-2-6 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ docs/reference/glib/tmpl/macros_misc.sgml | 1 + docs/reference/glib/tmpl/spawn.sgml | 1 + glib/gspawn.c | 16 +++++++++++++++- glib/gspawn.h | 11 ++++++----- gspawn.c | 16 +++++++++++++++- gspawn.h | 11 ++++++----- 14 files changed, 108 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 780621924..006ab4bc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 780621924..006ab4bc7 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2001-06-08 Havoc Pennington + + * gspawn.c: support G_SPAWN_FILE_AND_ARGV_ZERO specifying that + the vector passed in to g_spawn_* contains a filename to + execute in argv[0] then the actual argv begins at argv + 1. + Kind of a lame hack, but this isn't something you commonly want + to do, and avoids adding more function arguments. + 2001-06-08 Pablo Saratxaga * configure.in: Added Azeri (az) to ALL_LINGUAS diff --git a/docs/reference/glib/tmpl/macros_misc.sgml b/docs/reference/glib/tmpl/macros_misc.sgml index 7b93d0a7e..cd71ee73b 100644 --- a/docs/reference/glib/tmpl/macros_misc.sgml +++ b/docs/reference/glib/tmpl/macros_misc.sgml @@ -71,6 +71,7 @@ arrays or arrays on the stack. Portable way to copy va_list variables. + @ap1: the va_list variable to place a copy of @ap2 in. @ap2: a va_list. diff --git a/docs/reference/glib/tmpl/spawn.sgml b/docs/reference/glib/tmpl/spawn.sgml index 3cf178fdb..358cce6f7 100644 --- a/docs/reference/glib/tmpl/spawn.sgml +++ b/docs/reference/glib/tmpl/spawn.sgml @@ -58,6 +58,7 @@ Spawning Processes (fork/exec) @G_SPAWN_STDOUT_TO_DEV_NULL: @G_SPAWN_STDERR_TO_DEV_NULL: @G_SPAWN_CHILD_INHERITS_STDIN: +@G_SPAWN_FILE_AND_ARGV_ZERO: diff --git a/glib/gspawn.c b/glib/gspawn.c index c8208f6ca..fd40617b5 100644 --- a/glib/gspawn.c +++ b/glib/gspawn.c @@ -52,6 +52,7 @@ static gboolean fork_exec_with_pipes (gboolean intermediate_child, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data, gint *child_pid, @@ -237,6 +238,7 @@ g_spawn_sync (const gchar *working_directory, (flags & G_SPAWN_STDOUT_TO_DEV_NULL) != 0, (flags & G_SPAWN_STDERR_TO_DEV_NULL) != 0, (flags & G_SPAWN_CHILD_INHERITS_STDIN) != 0, + (flags & G_SPAWN_FILE_AND_ARGV_ZERO) != 0, child_setup, user_data, &pid, @@ -442,6 +444,11 @@ g_spawn_sync (const gchar *working_directory, * will be discarded. %G_SPAWN_CHILD_INHERITS_STDIN means that * the child will inherit the parent's standard input (by default, * the child's standard input is attached to /dev/null). + * %G_SPAWN_FILE_AND_ARGV_ZERO means that the first element of @argv is + * the file to execute, while the remaining elements are the + * actual argument vector to pass to the file. Normally + * g_spawn_async_with_pipes() uses @argv[0] as the file to execute, and + * passes all of @argv to the child. * * @child_setup and @user_data are a function and user data to be * called in the child after GLib has performed all the setup it plans @@ -504,6 +511,7 @@ g_spawn_async_with_pipes (const gchar *working_directory, (flags & G_SPAWN_STDOUT_TO_DEV_NULL) != 0, (flags & G_SPAWN_STDERR_TO_DEV_NULL) != 0, (flags & G_SPAWN_CHILD_INHERITS_STDIN) != 0, + (flags & G_SPAWN_FILE_AND_ARGV_ZERO) != 0, child_setup, user_data, child_pid, @@ -764,6 +772,7 @@ do_exec (gint child_err_report_fd, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data) { @@ -854,7 +863,9 @@ do_exec (gint child_err_report_fd, (* child_setup) (user_data); } - g_execute (argv[0], argv, envp, search_path); + g_execute (argv[0], + file_and_argv_zero ? argv + 1 : argv, + envp, search_path); /* Exec failed */ write_err_and_exit (child_err_report_fd, @@ -923,6 +934,7 @@ fork_exec_with_pipes (gboolean intermediate_child, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data, gint *child_pid, @@ -1021,6 +1033,7 @@ fork_exec_with_pipes (gboolean intermediate_child, stdout_to_null, stderr_to_null, child_inherits_stdin, + file_and_argv_zero, child_setup, user_data); } @@ -1049,6 +1062,7 @@ fork_exec_with_pipes (gboolean intermediate_child, stdout_to_null, stderr_to_null, child_inherits_stdin, + file_and_argv_zero, child_setup, user_data); } diff --git a/glib/gspawn.h b/glib/gspawn.h index 57530cb6d..dcebc3a8b 100644 --- a/glib/gspawn.h +++ b/glib/gspawn.h @@ -59,13 +59,14 @@ typedef void (* GSpawnChildSetupFunc) (gpointer user_data); typedef enum { G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0, - G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1, + G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1, /* look for argv[0] in the path i.e. use execvp() */ - G_SPAWN_SEARCH_PATH = 1 << 2, + G_SPAWN_SEARCH_PATH = 1 << 2, /* Dump output to /dev/null */ - G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3, - G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4, - G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5 + G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3, + G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4, + G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5, + G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6 } GSpawnFlags; GQuark g_spawn_error_quark (void); diff --git a/gspawn.c b/gspawn.c index c8208f6ca..fd40617b5 100644 --- a/gspawn.c +++ b/gspawn.c @@ -52,6 +52,7 @@ static gboolean fork_exec_with_pipes (gboolean intermediate_child, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data, gint *child_pid, @@ -237,6 +238,7 @@ g_spawn_sync (const gchar *working_directory, (flags & G_SPAWN_STDOUT_TO_DEV_NULL) != 0, (flags & G_SPAWN_STDERR_TO_DEV_NULL) != 0, (flags & G_SPAWN_CHILD_INHERITS_STDIN) != 0, + (flags & G_SPAWN_FILE_AND_ARGV_ZERO) != 0, child_setup, user_data, &pid, @@ -442,6 +444,11 @@ g_spawn_sync (const gchar *working_directory, * will be discarded. %G_SPAWN_CHILD_INHERITS_STDIN means that * the child will inherit the parent's standard input (by default, * the child's standard input is attached to /dev/null). + * %G_SPAWN_FILE_AND_ARGV_ZERO means that the first element of @argv is + * the file to execute, while the remaining elements are the + * actual argument vector to pass to the file. Normally + * g_spawn_async_with_pipes() uses @argv[0] as the file to execute, and + * passes all of @argv to the child. * * @child_setup and @user_data are a function and user data to be * called in the child after GLib has performed all the setup it plans @@ -504,6 +511,7 @@ g_spawn_async_with_pipes (const gchar *working_directory, (flags & G_SPAWN_STDOUT_TO_DEV_NULL) != 0, (flags & G_SPAWN_STDERR_TO_DEV_NULL) != 0, (flags & G_SPAWN_CHILD_INHERITS_STDIN) != 0, + (flags & G_SPAWN_FILE_AND_ARGV_ZERO) != 0, child_setup, user_data, child_pid, @@ -764,6 +772,7 @@ do_exec (gint child_err_report_fd, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data) { @@ -854,7 +863,9 @@ do_exec (gint child_err_report_fd, (* child_setup) (user_data); } - g_execute (argv[0], argv, envp, search_path); + g_execute (argv[0], + file_and_argv_zero ? argv + 1 : argv, + envp, search_path); /* Exec failed */ write_err_and_exit (child_err_report_fd, @@ -923,6 +934,7 @@ fork_exec_with_pipes (gboolean intermediate_child, gboolean stdout_to_null, gboolean stderr_to_null, gboolean child_inherits_stdin, + gboolean file_and_argv_zero, GSpawnChildSetupFunc child_setup, gpointer user_data, gint *child_pid, @@ -1021,6 +1033,7 @@ fork_exec_with_pipes (gboolean intermediate_child, stdout_to_null, stderr_to_null, child_inherits_stdin, + file_and_argv_zero, child_setup, user_data); } @@ -1049,6 +1062,7 @@ fork_exec_with_pipes (gboolean intermediate_child, stdout_to_null, stderr_to_null, child_inherits_stdin, + file_and_argv_zero, child_setup, user_data); } diff --git a/gspawn.h b/gspawn.h index 57530cb6d..dcebc3a8b 100644 --- a/gspawn.h +++ b/gspawn.h @@ -59,13 +59,14 @@ typedef void (* GSpawnChildSetupFunc) (gpointer user_data); typedef enum { G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0, - G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1, + G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1, /* look for argv[0] in the path i.e. use execvp() */ - G_SPAWN_SEARCH_PATH = 1 << 2, + G_SPAWN_SEARCH_PATH = 1 << 2, /* Dump output to /dev/null */ - G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3, - G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4, - G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5 + G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3, + G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4, + G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5, + G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6 } GSpawnFlags; GQuark g_spawn_error_quark (void);