4ae0536b61068729acd2b32853b0d6720ffc1da1
[platform/upstream/glib.git] / glib / gspawn.h
1 /* gspawn.h - Process launching
2  *
3  *  Copyright 2000 Red Hat, Inc.
4  *
5  * GLib is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * GLib is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with GLib; see the file COPYING.LIB.  If not, write
17  * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GSPAWN_H__
22 #define __GSPAWN_H__
23
24 #include <gerror.h>
25
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31 /* I'm not sure I remember our proposed naming convention here. */
32 #define G_SPAWN_ERROR g_spawn_error_quark ()
33
34 typedef enum
35 {
36   G_SPAWN_ERROR_FORK,   /* fork failed due to lack of memory */
37   G_SPAWN_ERROR_READ,   /* read or select on pipes failed */
38   G_SPAWN_ERROR_CHDIR,  /* changing to working dir failed */
39   G_SPAWN_ERROR_ACCES,  /* execv() returned EACCES */
40   G_SPAWN_ERROR_PERM,   /* execv() returned EPERM */
41   G_SPAWN_ERROR_2BIG,   /* execv() returned E2BIG */
42   G_SPAWN_ERROR_NOEXEC, /* execv() returned ENOEXEC */
43   G_SPAWN_ERROR_NAMETOOLONG, /* ""  "" ENAMETOOLONG */
44   G_SPAWN_ERROR_NOENT,       /* ""  "" ENOENT */
45   G_SPAWN_ERROR_NOMEM,       /* ""  "" ENOMEM */
46   G_SPAWN_ERROR_NOTDIR,      /* ""  "" ENOTDIR */
47   G_SPAWN_ERROR_LOOP,        /* ""  "" ELOOP   */
48   G_SPAWN_ERROR_TXTBUSY,     /* ""  "" ETXTBUSY */
49   G_SPAWN_ERROR_IO,          /* ""  "" EIO */
50   G_SPAWN_ERROR_NFILE,       /* ""  "" ENFILE */
51   G_SPAWN_ERROR_MFILE,       /* ""  "" EMFLE */
52   G_SPAWN_ERROR_INVAL,       /* ""  "" EINVAL */
53   G_SPAWN_ERROR_ISDIR,       /* ""  "" EISDIR */
54   G_SPAWN_ERROR_LIBBAD,      /* ""  "" ELIBBAD */
55   G_SPAWN_ERROR_FAILED       /* other fatal failure, error->message
56                               * should explain
57                               */
58 } GSpawnError;
59
60 typedef void (* GSpawnChildSetupFunc) (gpointer user_data);
61
62 typedef enum
63 {
64   G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0,
65   G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
66   /* look for argv[0] in the path i.e. use execvp() */
67   G_SPAWN_SEARCH_PATH = 1 << 2,
68   /* Dump output to /dev/null */
69   G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
70   G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
71   G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5
72 } GSpawnFlags;
73
74 GQuark g_spawn_error_quark (void);
75
76 gboolean g_spawn_async (const gchar           *working_directory,
77                         gchar                **argv,
78                         gchar                **envp,
79                         GSpawnFlags            flags,
80                         GSpawnChildSetupFunc   child_setup,
81                         gpointer               user_data,
82                         gint                  *child_pid,
83                         GError               **error);
84
85
86 /* Opens pipes for non-NULL standard_output, standard_input, standard_error,
87  * and returns the parent's end of the pipes.
88  */
89 gboolean g_spawn_async_with_pipes (const gchar          *working_directory,
90                                    gchar               **argv,
91                                    gchar               **envp,
92                                    GSpawnFlags           flags,
93                                    GSpawnChildSetupFunc  child_setup,
94                                    gpointer              user_data,
95                                    gint                 *child_pid,
96                                    gint                 *standard_input,
97                                    gint                 *standard_output,
98                                    gint                 *standard_error,
99                                    GError              **error);
100
101
102 /* If standard_output or standard_error are non-NULL, the full
103  * standard output or error of the command will be placed there.
104  */
105
106 gboolean g_spawn_sync         (const gchar          *working_directory,
107                                gchar               **argv,
108                                gchar               **envp,
109                                GSpawnFlags           flags,
110                                GSpawnChildSetupFunc  child_setup,
111                                gpointer              user_data,
112                                gchar               **standard_output,
113                                gchar               **standard_error,
114                                gint                 *exit_status,
115                                GError              **error);
116
117 gboolean g_spawn_command_line_sync  (const gchar          *command_line,
118                                      gchar               **standard_output,
119                                      gchar               **standard_error,
120                                      gint                 *exit_status,
121                                      GError              **error);
122 gboolean g_spawn_command_line_async (const gchar          *command_line,
123                                      GError              **error);
124
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #endif /* __GSPAWN_H__ */
131
132