215
233
gint fd = g_open (process->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
217
235
if (chown (process->priv->log_file, process->priv->uid, process->priv->gid) != 0)
218
g_warning ("Failed to set greeter log file ownership: %s", strerror (errno));
236
g_warning ("Failed to set process log file ownership: %s", strerror (errno));
242
int to_child_pipe[2];
243
int from_child_pipe[2];
245
if (pipe (to_child_pipe) != 0 ||
246
pipe (from_child_pipe) != 0)
248
g_warning ("Failed to create pipes: %s", strerror (errno));
252
process->priv->to_child_channel = g_io_channel_unix_new (to_child_pipe[1]);
253
g_io_channel_set_encoding (process->priv->to_child_channel, NULL, NULL);
255
/* Watch for data from the child process */
256
process->priv->from_child_channel = g_io_channel_unix_new (from_child_pipe[0]);
257
g_io_channel_set_encoding (process->priv->from_child_channel, NULL, NULL);
258
g_io_add_watch (process->priv->from_child_channel, G_IO_IN, from_child_cb, process);
260
to_server_fd = from_child_pipe[1];
261
from_server_fd = to_child_pipe[0];
263
fd = g_strdup_printf ("%d", to_server_fd);
264
child_process_set_env (process, "LDM_TO_SERVER_FD", fd);
266
fd = g_strdup_printf ("%d", from_server_fd);
267
child_process_set_env (process, "LDM_FROM_SERVER_FD", fd);
271
result = g_shell_parse_argv (command, &argc, &argv, error);
278
g_warning ("Failed to fork: %s", strerror (errno));
285
// TEMP: Remove this when have more generic file closing
286
if (process->priv->to_child_channel)
287
close (g_io_channel_unix_get_fd (process->priv->to_child_channel));
288
if (process->priv->from_child_channel)
289
close (g_io_channel_unix_get_fd (process->priv->from_child_channel));
291
run_child_process (process, argv);
292
_exit (EXIT_FAILURE);
294
close (from_server_fd);
295
close (to_server_fd);
221
297
string = g_string_new ("");
222
298
g_hash_table_iter_init (&iter, process->priv->env);
223
if (g_hash_table_iter_next (&iter, &key, &value))
299
while (g_hash_table_iter_next (&iter, &key, &value))
224
300
g_string_append_printf (string, "%s=%s ", (gchar *)key, (gchar *)value);
225
301
g_string_append (string, command);
226
g_debug ("Launching process: %s", string->str);
302
g_debug ("Launching process %d: %s", pid, string->str);
227
303
g_string_free (string, TRUE);
229
result = g_shell_parse_argv (command, &argc, &argv, error);
305
process->priv->pid = pid;
233
process->priv->pid = 0;
234
result = g_spawn_async (working_dir,
237
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
238
child_process_fork_cb, process,
241
307
g_strfreev (argv);
262
328
kill (process->priv->pid, signum);
332
child_process_read_int (ChildProcess *process)
335
g_io_channel_read_chars (process->priv->from_child_channel, (gchar *) &value, sizeof (value), NULL, NULL);
340
child_process_read_string (ChildProcess *process)
345
length = child_process_read_int (process);
346
value = g_malloc (sizeof (gchar *) * (length + 1));
347
g_io_channel_read_chars (process->priv->from_child_channel, value, length, NULL, NULL);
348
value[length] = '\0';
354
child_process_write_int (ChildProcess *process, guint32 value)
356
g_io_channel_write_chars (process->priv->to_child_channel, (const gchar *) &value, sizeof (value), NULL, NULL);
360
child_process_write_string (ChildProcess *process, const gchar *value)
362
child_process_write_int (process, strlen (value));
363
g_io_channel_write_chars (process->priv->to_child_channel, value, -1, NULL, NULL);
367
child_process_flush (ChildProcess *process)
369
g_io_channel_flush (process->priv->to_child_channel, NULL);
266
373
child_process_init (ChildProcess *process)
324
431
g_type_class_add_private (klass, sizeof (ChildProcessPrivate));
434
g_signal_new ("got-data",
435
G_TYPE_FROM_CLASS (klass),
437
G_STRUCT_OFFSET (ChildProcessClass, got_data),
439
g_cclosure_marshal_VOID__VOID,
326
441
signals[GOT_SIGNAL] =
327
442
g_signal_new ("got-signal",
328
443
G_TYPE_FROM_CLASS (klass),