gspawn.h

Go to the documentation of this file.
00001 /* gspawn.h - Process launching
00002  *
00003  *  Copyright 2000 Red Hat, Inc.
00004  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00005  *
00006  * GLib is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * GLib is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with GLib; see the file COPYING.LIB.  If not, write
00018  * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef __G_SPAWN_H__
00023 #define __G_SPAWN_H__
00024 
00025 #include <_ansi.h>
00026 #include <glib/gerror.h>
00027 
00028 G_BEGIN_DECLS
00029 
00030 /* I'm not sure I remember our proposed naming convention here. */
00031 #define G_SPAWN_ERROR g_spawn_error_quark ()
00032 
00033 typedef enum
00034 {
00035   G_SPAWN_ERROR_FORK,   /* fork failed due to lack of memory */
00036   G_SPAWN_ERROR_READ,   /* read or select on pipes failed */
00037   G_SPAWN_ERROR_CHDIR,  /* changing to working dir failed */
00038   G_SPAWN_ERROR_ACCES,  /* execv() returned EACCES */
00039   G_SPAWN_ERROR_PERM,   /* execv() returned EPERM */
00040   G_SPAWN_ERROR_2BIG,   /* execv() returned E2BIG */
00041   G_SPAWN_ERROR_NOEXEC, /* execv() returned ENOEXEC */
00042   G_SPAWN_ERROR_NAMETOOLONG, /* ""  "" ENAMETOOLONG */
00043   G_SPAWN_ERROR_NOENT,       /* ""  "" ENOENT */
00044   G_SPAWN_ERROR_NOMEM,       /* ""  "" ENOMEM */
00045   G_SPAWN_ERROR_NOTDIR,      /* ""  "" ENOTDIR */
00046   G_SPAWN_ERROR_LOOP,        /* ""  "" ELOOP   */
00047   G_SPAWN_ERROR_TXTBUSY,     /* ""  "" ETXTBUSY */
00048   G_SPAWN_ERROR_IO,          /* ""  "" EIO */
00049   G_SPAWN_ERROR_NFILE,       /* ""  "" ENFILE */
00050   G_SPAWN_ERROR_MFILE,       /* ""  "" EMFLE */
00051   G_SPAWN_ERROR_INVAL,       /* ""  "" EINVAL */
00052   G_SPAWN_ERROR_ISDIR,       /* ""  "" EISDIR */
00053   G_SPAWN_ERROR_LIBBAD,      /* ""  "" ELIBBAD */
00054   G_SPAWN_ERROR_FAILED       /* other fatal failure, error->message
00055                               * should explain
00056                               */
00057 } GSpawnError;
00058 
00059 typedef void (* GSpawnChildSetupFunc) (gpointer user_data);
00060 
00061 typedef enum
00062 {
00063   G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0,
00064   G_SPAWN_DO_NOT_REAP_CHILD      = 1 << 1,
00065   /* look for argv[0] in the path i.e. use execvp() */
00066   G_SPAWN_SEARCH_PATH            = 1 << 2,
00067   /* Dump output to /dev/null */
00068   G_SPAWN_STDOUT_TO_DEV_NULL     = 1 << 3,
00069   G_SPAWN_STDERR_TO_DEV_NULL     = 1 << 4,
00070   G_SPAWN_CHILD_INHERITS_STDIN   = 1 << 5,
00071   G_SPAWN_FILE_AND_ARGV_ZERO     = 1 << 6
00072 } GSpawnFlags;
00073 
00074 IMPORT_C GQuark g_spawn_error_quark (void);
00075 
00076 #ifdef G_OS_WIN32
00077 #define g_spawn_async g_spawn_async_utf8
00078 #define g_spawn_async_with_pipes g_spawn_async_with_pipes_utf8
00079 #define g_spawn_sync g_spawn_sync_utf8
00080 #define g_spawn_command_line_sync g_spawn_command_line_sync_utf8
00081 #define g_spawn_command_line_async g_spawn_command_line_async_utf8
00082 #endif
00083 
00084 IMPORT_C gboolean g_spawn_async (const gchar           *working_directory,
00085                         gchar                **argv,
00086                         gchar                **envp,
00087                         GSpawnFlags            flags,
00088                         GSpawnChildSetupFunc   child_setup,
00089                         gpointer               user_data,
00090                         GPid                  *child_pid,
00091                         GError               **error);
00092 
00093 
00094 /* Opens pipes for non-NULL standard_output, standard_input, standard_error,
00095  * and returns the parent's end of the pipes.
00096  */
00097 IMPORT_C gboolean g_spawn_async_with_pipes (const gchar          *working_directory,
00098                                    gchar               **argv,
00099                                    gchar               **envp,
00100                                    GSpawnFlags           flags,
00101                                    GSpawnChildSetupFunc  child_setup,
00102                                    gpointer              user_data,
00103                                    GPid                 *child_pid,
00104                                    gint                 *standard_input,
00105                                    gint                 *standard_output,
00106                                    gint                 *standard_error,
00107                                    GError              **error);
00108 
00109 
00110 /* If standard_output or standard_error are non-NULL, the full
00111  * standard output or error of the command will be placed there.
00112  */
00113 
00114 IMPORT_C gboolean g_spawn_sync         (const gchar          *working_directory,
00115                                gchar               **argv,
00116                                gchar               **envp,
00117                                GSpawnFlags           flags,
00118                                GSpawnChildSetupFunc  child_setup,
00119                                gpointer              user_data,
00120                                gchar               **standard_output,
00121                                gchar               **standard_error,
00122                                gint                 *exit_status,
00123                                GError              **error);
00124 
00125 IMPORT_C gboolean g_spawn_command_line_sync  (const gchar          *command_line,
00126                                      gchar               **standard_output,
00127                                      gchar               **standard_error,
00128                                      gint                 *exit_status,
00129                                      GError              **error);
00130 IMPORT_C gboolean g_spawn_command_line_async (const gchar          *command_line,
00131                                      GError              **error);
00132 
00133 IMPORT_C void g_spawn_close_pid (GPid pid);
00134 
00135 
00136 G_END_DECLS
00137 
00138 #endif /* __G_SPAWN_H__ */
00139 
00140 

Copyright © Nokia Corporation 2001-2008
Back to top