summaryrefslogtreecommitdiff
path: root/src/gsystem-subprocess-context.h
blob: b8a24012a43c7017acd1e7599685ae76df78e4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 *
 * Copyright (C) 2012 Colin Walters <walters@verbum.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GSYSTEM_SUBPROCESS_CONTEXT_H__
#define __GSYSTEM_SUBPROCESS_CONTEXT_H__

#include <gio/gio.h>

#if GLIB_CHECK_VERSION(2,34,0)

G_BEGIN_DECLS

#define GS_TYPE_SUBPROCESS_CONTEXT         (gs_subprocess_context_get_type ())
#define GS_SUBPROCESS_CONTEXT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GS_TYPE_SUBPROCESS_CONTEXT, GSSubprocessContext))
#define GS_IS_SUBPROCESS_CONTEXT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GS_TYPE_SUBPROCESS_CONTEXT))

typedef struct _GSSubprocessContext GSSubprocessContext;

/**
 * GSSubprocessStreamDisposition:
 * @GS_SUBPROCESS_STREAM_DISPOSITION_NULL: Redirect to operating system's null output stream
 * @GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT: Keep the stream from the parent process
 * @GS_SUBPROCESS_STREAM_DISPOSITION_PIPE: Open a private unidirectional channel between the processes
 * @GS_SUBPROCESS_STREAM_DISPOSITION_STDERR_MERGE: Only applicable to standard error; causes it to be merged with standard output
 *
 * Flags to define the behaviour of the standard input/output/error of
 * a #GSSubprocess.
 *
 * Since: 2.36
 **/
typedef enum {
  GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
  GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
  GS_SUBPROCESS_STREAM_DISPOSITION_PIPE,
  GS_SUBPROCESS_STREAM_DISPOSITION_STDERR_MERGE
} GSSubprocessStreamDisposition;

GType            gs_subprocess_context_get_type (void) G_GNUC_CONST;

GSSubprocessContext * gs_subprocess_context_new (gchar           **argv);
GSSubprocessContext * gs_subprocess_context_newv (const gchar  *first_arg,
                                                ...);
GSSubprocessContext * gs_subprocess_context_newa (const gchar  *first_arg,
                                                va_list       args);

#ifdef G_OS_UNIX
GSSubprocessContext * gs_subprocess_context_new_argv0 (const gchar   *argv0,
                                                     gchar        **argv);
#endif

void             gs_subprocess_context_argv_append (GSSubprocessContext  *self,
                                                    const gchar          *arg);

/* Environment */

void             gs_subprocess_context_set_environment (GSSubprocessContext           *self,
						       gchar                       **environ);
void             gs_subprocess_context_set_cwd (GSSubprocessContext           *self,
					       const gchar                  *cwd);
void             gs_subprocess_context_set_keep_descriptors (GSSubprocessContext           *self,
							    gboolean                      keep_descriptors);
void             gs_subprocess_context_set_search_path (GSSubprocessContext           *self,
						       gboolean                      search_path,
						       gboolean                      search_path_from_envp);

/* Basic I/O control */

void             gs_subprocess_context_set_stdin_disposition (GSSubprocessContext           *self,
							     GSSubprocessStreamDisposition  disposition);
void             gs_subprocess_context_set_stdout_disposition (GSSubprocessContext           *self,
							      GSSubprocessStreamDisposition  disposition);
void             gs_subprocess_context_set_stderr_disposition (GSSubprocessContext           *self,
							      GSSubprocessStreamDisposition  disposition);

/* Extended I/O control, only available on UNIX */

#ifdef G_OS_UNIX
void             gs_subprocess_context_set_stdin_file_path (GSSubprocessContext           *self,
							   const gchar                  *path);
void             gs_subprocess_context_set_stdin_fd        (GSSubprocessContext           *self,
							   gint                          fd);
void             gs_subprocess_context_set_stdout_file_path (GSSubprocessContext           *self,
							    const gchar                  *path);
void             gs_subprocess_context_set_stdout_fd        (GSSubprocessContext           *self,
							    gint                          fd);
void             gs_subprocess_context_set_stderr_file_path (GSSubprocessContext           *self,
							    const gchar                  *path);
void             gs_subprocess_context_set_stderr_fd        (GSSubprocessContext           *self,
							    gint                          fd);

gboolean         gs_subprocess_context_open_pipe_read       (GSSubprocessContext         *self,
                                                             GInputStream               **out_stream,
                                                             gint                        *out_fdno,
                                                             GError                     **error);
gboolean         gs_subprocess_context_open_pipe_write      (GSSubprocessContext         *self,
                                                             GOutputStream              **out_stream,
                                                             gint                        *out_fdno,
                                                             GError                     **error);
#endif

/* Child setup, only available on UNIX */
#ifdef G_OS_UNIX
void             gs_subprocess_context_set_child_setup        (GSSubprocessContext           *self,
							      GSpawnChildSetupFunc          child_setup,
							      gpointer                      user_data);
#endif

G_END_DECLS

#endif
#endif