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