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