#include <fcntl.h>
#endif
#ifdef G_OS_WIN32
-#define _WIN32_WINNT 0x0500
#include <windows.h>
+#include <io.h>
#include "giowin32-priv.h"
#endif
N_PROPS
};
+#ifdef G_OS_UNIX
typedef struct
{
gint fds[3];
if (child_data->child_setup_func)
child_data->child_setup_func (child_data->child_setup_data);
}
+#endif
static GInputStream *
platform_input_stream_from_spawn_fd (gint fd)
GError **error)
{
GSubprocess *self = G_SUBPROCESS (initable);
+#ifdef G_OS_UNIX
ChildData child_data = { { -1, -1, -1 }, 0 };
+#endif
gint *pipe_ptrs[3] = { NULL, NULL, NULL };
gint pipe_fds[3] = { -1, -1, -1 };
gint close_fds[3] = { -1, -1, -1 };
spawn_flags |= G_SPAWN_STDERR_TO_DEV_NULL;
else if (self->flags & G_SUBPROCESS_FLAGS_STDERR_PIPE)
pipe_ptrs[2] = &pipe_fds[2];
+#ifdef G_OS_UNIX
else if (self->flags & G_SUBPROCESS_FLAGS_STDERR_MERGE)
/* This will work because stderr gets setup after stdout. */
child_data.fds[2] = 1;
-#ifdef G_OS_UNIX
else if (self->launcher)
{
if (self->launcher->stderr_fd != -1)
spawn_flags |= G_SPAWN_DO_NOT_REAP_CHILD;
spawn_flags |= G_SPAWN_CLOEXEC_PIPES;
+#ifdef G_OS_UNIX
child_data.child_setup_func = self->launcher ? self->launcher->child_setup_func : NULL;
child_data.child_setup_data = self->launcher ? self->launcher->child_setup_user_data : NULL;
+#endif
+
success = g_spawn_async_with_pipes (self->launcher ? self->launcher->cwd : NULL,
self->argv,
self->launcher ? self->launcher->envp : NULL,
spawn_flags,
+#ifdef G_OS_UNIX
child_setup, &child_data,
+#else
+ NULL, NULL,
+#endif
&self->pid,
pipe_ptrs[0], pipe_ptrs[1], pipe_ptrs[2],
error);
g_source_unref (source);
}
+#ifdef G_OS_UNIX
out:
+#endif
/* we don't need this past init... */
self->launcher = NULL;
g_return_val_if_fail (G_IS_SUBPROCESS (subprocess), FALSE);
g_return_val_if_fail (subprocess->pid == 0, FALSE);
+#ifdef G_OS_UNIX
return WIFEXITED (subprocess->status) && WEXITSTATUS (subprocess->status) == 0;
+#else
+ return subprocess->status == 0;
+#endif
}
/**
g_return_val_if_fail (G_IS_SUBPROCESS (subprocess), FALSE);
g_return_val_if_fail (subprocess->pid == 0, FALSE);
+#ifdef G_OS_UNIX
return WIFEXITED (subprocess->status);
+#else
+ return TRUE;
+#endif
}
/**
{
g_return_val_if_fail (G_IS_SUBPROCESS (subprocess), 1);
g_return_val_if_fail (subprocess->pid == 0, 1);
+
+#ifdef G_OS_UNIX
g_return_val_if_fail (WIFEXITED (subprocess->status), 1);
return WEXITSTATUS (subprocess->status);
+#else
+ return subprocess->status;
+#endif
}
/**
g_return_val_if_fail (G_IS_SUBPROCESS (subprocess), FALSE);
g_return_val_if_fail (subprocess->pid == 0, FALSE);
+#ifdef G_OS_UNIX
return WIFSIGNALED (subprocess->status);
+#else
+ return FALSE;
+#endif
}
/**
{
g_return_val_if_fail (G_IS_SUBPROCESS (subprocess), 0);
g_return_val_if_fail (subprocess->pid == 0, 0);
+
+#ifdef G_OS_UNIX
g_return_val_if_fail (WIFSIGNALED (subprocess->status), 0);
return WTERMSIG (subprocess->status);
+#else
+ g_critical ("g_subprocess_get_term_sig() called on Windows, where "
+ "g_subprocess_get_if_signaled() always returns FALSE...");
+ return 0;
+#endif
}
/*< private >*/
g_subprocess_launcher_finalize (GObject *object)
{
GSubprocessLauncher *self = G_SUBPROCESS_LAUNCHER (object);
- guint i;
-
- g_strfreev (self->envp);
- g_free (self->cwd);
#ifdef G_OS_UNIX
+ guint i;
+
g_free (self->stdin_path);
g_free (self->stdout_path);
g_free (self->stderr_path);
(void) close (g_array_index (self->needdup_fd_assignments, int, i));
g_array_unref (self->needdup_fd_assignments);
}
-#endif
if (self->child_setup_destroy_notify)
(* self->child_setup_destroy_notify) (self->child_setup_user_data);
+#endif
+
+ g_strfreev (self->envp);
+ g_free (self->cwd);
G_OBJECT_CLASS (g_subprocess_launcher_parent_class)->finalize (object);
}
{
self->envp = g_listenv ();
+#ifdef G_OS_UNIX
self->stdin_fd = -1;
self->stdout_fd = -1;
self->stderr_fd = -1;
-#ifdef G_OS_UNIX
self->basic_fd_assignments = g_array_new (FALSE, 0, sizeof (int));
self->needdup_fd_assignments = g_array_new (FALSE, 0, sizeof (int));
#endif
g_subprocess_launcher_set_flags (GSubprocessLauncher *self,
GSubprocessFlags flags)
{
- if (verify_disposition ("stdin", flags & ALL_STDIN_FLAGS, self->stdin_fd, self->stdin_path) &&
- verify_disposition ("stdout", flags & ALL_STDOUT_FLAGS, self->stdout_fd, self->stdout_path) &&
- verify_disposition ("stderr", flags & ALL_STDERR_FLAGS, self->stderr_fd, self->stderr_path))
+ const gchar *stdin_path = NULL, *stdout_path = NULL, *stderr_path = NULL;
+ gint stdin_fd = -1, stdout_fd = -1, stderr_fd = -1;
+
+#ifdef G_OS_UNIX
+ stdin_fd = self->stdin_fd;
+ stdout_fd = self->stdout_fd;
+ stderr_fd = self->stderr_fd;
+ stdin_path = self->stdin_path;
+ stdout_path = self->stdout_path;
+ stderr_path = self->stderr_path;
+#endif
+
+ if (verify_disposition ("stdin", flags & ALL_STDIN_FLAGS, stdin_fd, stdin_path) &&
+ verify_disposition ("stdout", flags & ALL_STDOUT_FLAGS, stdout_fd, stdout_path) &&
+ verify_disposition ("stderr", flags & ALL_STDERR_FLAGS, stderr_fd, stderr_path))
self->flags = flags;
}