Debian Codegraph @

gdk/x11/gdkspawn-x11.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2003 Sun Microsystems Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * Authors: Mark McLoughlin <[email protected]>
20 */
21
22 #include "config.h"
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include "gdkspawn.h"
27
28 #include <glib.h>
29 #include <gdk/gdk.h>
30 #include "gdkalias.h"
31
32 typedef struct {
33 char *display;
34 GSpawnChildSetupFunc child_setup;
35 gpointer user_data;
36 } UserChildSetup;
37
38 /*
39 * Set the DISPLAY variable, and then call the user-specified child setup
40 * function. This is required so that applications can use gdk_spawn_* and
41 * call putenv() in their child_setup functions.
42 */
43 static void
44 set_environment (gpointer user_data)
45 {
46 UserChildSetup *setup = user_data;
47
48 g_setenv ("DISPLAY", setup->display, TRUE);
49
50 if (setup->child_setup)
51 setup->child_setup (setup->user_data);
52 }
53
54 /**
55 * gdk_spawn_on_screen:
56 * @screen: a #GdkScreen
57 * @working_directory: child's current working directory, or %NULL to
58 * inherit parent's
59 * @argv: child's argument vector
60 * @envp: child's environment, or %NULL to inherit parent's
61 * @flags: flags from #GSpawnFlags
62 * @child_setup: function to run in the child just before exec()
63 * @user_data: user data for @child_setup
64 * @child_pid: return location for child process ID, or %NULL
65 * @error: return location for error
66 *
67 * Like g_spawn_async(), except the child process is spawned in such
68 * an environment that on calling gdk_display_open() it would be
69 * returned a #GdkDisplay with @screen as the default screen.
70 *
71 * This is useful for applications which wish to launch an application
72 * on a specific screen.
73 *
74 * Return value: %TRUE on success, %FALSE if error is set
75 *
76 * Since: 2.4
77 *
78 * Deprecated: 2.24: This function is being removed in 3.0. Use
79 * either g_spawn_sync(), g_spawn_async(), or #GdkAppLaunchContext instead.
80 **/
81 gboolean
82 gdk_spawn_on_screen (GdkScreen *screen,
83 const gchar *working_directory,
84 gchar **argv,
85 gchar **envp,
86 GSpawnFlags flags,
87 GSpawnChildSetupFunc child_setup,
88 gpointer user_data,
89 gint *child_pid,
90 GError **error)
91 {
92 UserChildSetup setup_data;
93
94 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
95
96 setup_data.display = gdk_screen_make_display_name (screen);
97 setup_data.child_setup = child_setup;
98 setup_data.user_data = user_data;
99
100 return g_spawn_async (working_directory,
101 argv,
102 envp,
103 flags,
104 set_environment,
105 &setup_data,
106 child_pid,
107 error);
108 }
109
110 /**
111 * gdk_spawn_on_screen_with_pipes:
112 * @screen: a #GdkScreen
113 * @working_directory: child's current working directory, or %NULL to
114 * inherit parent's
115 * @argv: child's argument vector
116 * @envp: child's environment, or %NULL to inherit parent's
117 * @flags: flags from #GSpawnFlags
118 * @child_setup: function to run in the child just before exec()
119 * @user_data: user data for @child_setup
120 * @child_pid: return location for child process ID, or %NULL
121 * @standard_input: return location for file descriptor to write to
122 * child's stdin, or %NULL
123 * @standard_output: return location for file descriptor to read child's
124 * stdout, or %NULL
125 * @standard_error: return location for file descriptor to read child's
126 * stderr, or %NULL
127 * @error: return location for error
128 *
129 * Like g_spawn_async_with_pipes(), except the child process is
130 * spawned in such an environment that on calling gdk_display_open()
131 * it would be returned a #GdkDisplay with @screen as the default
132 * screen.
133 *
134 * This is useful for applications which wish to launch an application
135 * on a specific screen.
136 *
137 * Return value: %TRUE on success, %FALSE if an error was set
138 *
139 * Since: 2.4
140 *
141 * Deprecated: 2.24: This function is being removed in 3.0. Use
142 * either g_spawn_async_with_pipes() or #GdkAppLaunchContext instead.
143 **/
144 gboolean
145 gdk_spawn_on_screen_with_pipes (GdkScreen *screen,
146 const gchar *working_directory,
147 gchar **argv,
148 gchar **envp,
149 GSpawnFlags flags,
150 GSpawnChildSetupFunc child_setup,
151 gpointer user_data,
152 gint *child_pid,
153 gint *standard_input,
154 gint *standard_output,
155 gint *standard_error,
156 GError **error)
157 {
158 UserChildSetup setup_data;
159
160 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
161
162 setup_data.display = gdk_screen_make_display_name (screen);
163 setup_data.child_setup = child_setup;
164 setup_data.user_data = user_data;
165
166 return g_spawn_async_with_pipes (working_directory,
167 argv,
168 envp,
169 flags,
170 set_environment,
171 &setup_data,
172 child_pid,
173 standard_input,
174 standard_output,
175 standard_error,
176 error);
177
178 }
179
180 /**
181 * gdk_spawn_command_line_on_screen:
182 * @screen: a #GdkScreen
183 * @command_line: a command line
184 * @error: return location for errors
185 *
186 * Like g_spawn_command_line_async(), except the child process is
187 * spawned in such an environment that on calling gdk_display_open()
188 * it would be returned a #GdkDisplay with @screen as the default
189 * screen.
190 *
191 * This is useful for applications which wish to launch an application
192 * on a specific screen.
193 *
194 * Return value: %TRUE on success, %FALSE if error is set.
195 *
196 * Since: 2.4
197 *
198 * Deprecated: 2.24: This function is being removed in 3.0. Use
199 * either g_spawn_command_line_sync(), g_spawn_command_line_async() or
200 * #GdkAppLaunchContext instead.
201 **/
202 gboolean
203 gdk_spawn_command_line_on_screen (GdkScreen *screen,
204 const gchar *command_line,
205 GError **error)
206 {
207 gchar **argv = NULL;
208 gboolean retval;
209
210 g_return_val_if_fail (command_line != NULL, FALSE);
211
212 if (!g_shell_parse_argv (command_line,
213 NULL, &argv,
214 error))
215 return FALSE;
216
217 retval = gdk_spawn_on_screen (screen,
218 NULL, argv, NULL,
219 G_SPAWN_SEARCH_PATH,
220 NULL, NULL, NULL,
221 error);
222 g_strfreev (argv);
223
224 return retval;
225 }
226
227 #define __GDK_SPAWN_X11_C__
228 #include "gdkaliasdef.c"