mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof: abstract subprocess usage
For embedding cases, we need a bit more control here so that the application can be in control of how the process is spawned.
This commit is contained in:
@ -21,6 +21,7 @@ libsysprof_public_sources = [
|
|||||||
'sysprof-proxy-source.c',
|
'sysprof-proxy-source.c',
|
||||||
'sysprof-selection.c',
|
'sysprof-selection.c',
|
||||||
'sysprof-source.c',
|
'sysprof-source.c',
|
||||||
|
'sysprof-spawnable.c',
|
||||||
'sysprof-symbol-dirs.c',
|
'sysprof-symbol-dirs.c',
|
||||||
'sysprof-symbol-resolver.c',
|
'sysprof-symbol-resolver.c',
|
||||||
'sysprof-symbols-source.c',
|
'sysprof-symbols-source.c',
|
||||||
@ -46,6 +47,7 @@ libsysprof_public_headers = [
|
|||||||
'sysprof-proxy-source.h',
|
'sysprof-proxy-source.h',
|
||||||
'sysprof-selection.h',
|
'sysprof-selection.h',
|
||||||
'sysprof-source.h',
|
'sysprof-source.h',
|
||||||
|
'sysprof-spawnable.h',
|
||||||
'sysprof-symbol-dirs.h',
|
'sysprof-symbol-dirs.h',
|
||||||
'sysprof-symbol-resolver.h',
|
'sysprof-symbol-resolver.h',
|
||||||
'sysprof-symbols-source.h',
|
'sysprof-symbols-source.h',
|
||||||
|
|||||||
@ -32,12 +32,11 @@ struct _SysprofGjsSource
|
|||||||
static SysprofSourceInterface *parent_iface;
|
static SysprofSourceInterface *parent_iface;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_gjs_source_modify_spawn (SysprofSource *source,
|
sysprof_gjs_source_modify_spawn (SysprofSource *source,
|
||||||
GSubprocessLauncher *launcher,
|
SysprofSpawnable *spawnable)
|
||||||
GPtrArray *argv)
|
|
||||||
{
|
{
|
||||||
g_subprocess_launcher_setenv (launcher, "GJS_ENABLE_PROFILER", "1", FALSE);
|
sysprof_spawnable_setenv (spawnable, "GJS_ENABLE_PROFILER", "1");
|
||||||
parent_iface->modify_spawn (source, launcher, argv);
|
parent_iface->modify_spawn (source, spawnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -587,8 +587,7 @@ sysprof_local_profiler_authorize_cb (GObject *object,
|
|||||||
if (priv->spawn && priv->spawn_argv && priv->spawn_argv[0])
|
if (priv->spawn && priv->spawn_argv && priv->spawn_argv[0])
|
||||||
{
|
{
|
||||||
g_autoptr(GPtrArray) env = g_ptr_array_new_with_free_func (g_free);
|
g_autoptr(GPtrArray) env = g_ptr_array_new_with_free_func (g_free);
|
||||||
g_autoptr(GPtrArray) argv = g_ptr_array_new_with_free_func (g_free);
|
g_autoptr(SysprofSpawnable) spawnable = sysprof_spawnable_new ();
|
||||||
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
|
||||||
g_autoptr(GSubprocess) subprocess = NULL;
|
g_autoptr(GSubprocess) subprocess = NULL;
|
||||||
GPid pid;
|
GPid pid;
|
||||||
|
|
||||||
@ -612,34 +611,25 @@ sysprof_local_profiler_authorize_cb (GObject *object,
|
|||||||
|
|
||||||
g_ptr_array_add (env, NULL);
|
g_ptr_array_add (env, NULL);
|
||||||
|
|
||||||
launcher = g_subprocess_launcher_new (0);
|
sysprof_spawnable_set_environ (spawnable, (const gchar * const *)env->pdata);
|
||||||
g_subprocess_launcher_set_environ (launcher, (gchar **)env->pdata);
|
sysprof_spawnable_append_args (spawnable, (const gchar * const *)priv->spawn_argv);
|
||||||
g_subprocess_launcher_set_cwd (launcher, g_get_home_dir ());
|
|
||||||
|
|
||||||
if (priv->spawn_argv)
|
|
||||||
{
|
|
||||||
for (guint i = 0; priv->spawn_argv[i]; i++)
|
|
||||||
g_ptr_array_add (argv, g_strdup (priv->spawn_argv[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save argv before modifying */
|
/* Save argv before modifying */
|
||||||
g_key_file_set_string_list (keyfile,
|
if (priv->spawn_argv != NULL)
|
||||||
"profiler",
|
g_key_file_set_string_list (keyfile,
|
||||||
"spawn-argv",
|
"profiler",
|
||||||
(const gchar * const *)argv->pdata,
|
"spawn-argv",
|
||||||
argv->len);
|
(const gchar * const *)priv->spawn_argv,
|
||||||
|
g_strv_length (priv->spawn_argv));
|
||||||
|
|
||||||
for (guint i = 0; i < priv->sources->len; i++)
|
for (guint i = 0; i < priv->sources->len; i++)
|
||||||
{
|
{
|
||||||
SysprofSource *source = g_ptr_array_index (priv->sources, i);
|
SysprofSource *source = g_ptr_array_index (priv->sources, i);
|
||||||
sysprof_source_modify_spawn (source, launcher, argv);
|
|
||||||
|
sysprof_source_modify_spawn (source, spawnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ptr_array_add (argv, NULL);
|
if (!(subprocess = sysprof_spawnable_spawn (spawnable, &error)))
|
||||||
|
|
||||||
if (!(subprocess = g_subprocess_launcher_spawnv (launcher,
|
|
||||||
(const gchar * const *)argv->pdata,
|
|
||||||
&error)))
|
|
||||||
{
|
{
|
||||||
g_ptr_array_add (priv->failures, g_steal_pointer (&error));
|
g_ptr_array_add (priv->failures, g_steal_pointer (&error));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,16 +141,14 @@ sysprof_source_stop (SysprofSource *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sysprof_source_modify_spawn (SysprofSource *self,
|
sysprof_source_modify_spawn (SysprofSource *self,
|
||||||
GSubprocessLauncher *launcher,
|
SysprofSpawnable *spawnable)
|
||||||
GPtrArray *argv)
|
|
||||||
{
|
{
|
||||||
g_return_if_fail (SYSPROF_IS_SOURCE (self));
|
g_return_if_fail (SYSPROF_IS_SOURCE (self));
|
||||||
g_return_if_fail (G_IS_SUBPROCESS_LAUNCHER (launcher));
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (spawnable));
|
||||||
g_return_if_fail (argv != NULL);
|
|
||||||
|
|
||||||
if (SYSPROF_SOURCE_GET_IFACE (self)->modify_spawn)
|
if (SYSPROF_SOURCE_GET_IFACE (self)->modify_spawn)
|
||||||
SYSPROF_SOURCE_GET_IFACE (self)->modify_spawn (self, launcher, argv);
|
SYSPROF_SOURCE_GET_IFACE (self)->modify_spawn (self, spawnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
#include <sysprof-capture.h>
|
||||||
|
|
||||||
#include "sysprof-capture-writer.h"
|
#include "sysprof-spawnable.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -123,15 +124,13 @@ struct _SysprofSourceInterface
|
|||||||
/**
|
/**
|
||||||
* SysprofSource::modify-spawn:
|
* SysprofSource::modify-spawn:
|
||||||
* @self: a #SysprofSource
|
* @self: a #SysprofSource
|
||||||
* @launcher: a #GSubprocessLauncher
|
* @spawnable: a #SysprofSpawnable
|
||||||
* @argv: (element-type utf8): arguments for spawning
|
|
||||||
*
|
*
|
||||||
* Allows the source to modify the launcher or argv before the
|
* Allows the source to modify the launcher or argv before the
|
||||||
* process is spawned.
|
* process is spawned.
|
||||||
*/
|
*/
|
||||||
void (*modify_spawn) (SysprofSource *self,
|
void (*modify_spawn) (SysprofSource *self,
|
||||||
GSubprocessLauncher *launcher,
|
SysprofSpawnable *spawnable);
|
||||||
GPtrArray *argv);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SysprofSource::supplement:
|
* SysprofSource::supplement:
|
||||||
@ -196,8 +195,7 @@ SYSPROF_AVAILABLE_IN_ALL
|
|||||||
void sysprof_source_stop (SysprofSource *self);
|
void sysprof_source_stop (SysprofSource *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_source_modify_spawn (SysprofSource *self,
|
void sysprof_source_modify_spawn (SysprofSource *self,
|
||||||
GSubprocessLauncher *launcher,
|
SysprofSpawnable *spawnable);
|
||||||
GPtrArray *argv);
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_source_serialize (SysprofSource *self,
|
void sysprof_source_serialize (SysprofSource *self,
|
||||||
GKeyFile *keyfile,
|
GKeyFile *keyfile,
|
||||||
|
|||||||
286
src/libsysprof/sysprof-spawnable.c
Normal file
286
src/libsysprof/sysprof-spawnable.c
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/* sysprof-spawnable.c
|
||||||
|
*
|
||||||
|
* Copyright 2019 Christian Hergert <chergert@redhat.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define G_LOG_DOMAIN "sysprof-spawnable"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "sysprof-spawnable.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
gint dest_fd;
|
||||||
|
gint fd;
|
||||||
|
} FDMapping;
|
||||||
|
|
||||||
|
struct _SysprofSpawnable
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
GArray *fds;
|
||||||
|
GPtrArray *argv;
|
||||||
|
gchar **environ;
|
||||||
|
gint next_fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (SysprofSpawnable, sysprof_spawnable, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_spawnable_new:
|
||||||
|
*
|
||||||
|
* Create a new #SysprofSpawnable.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a newly created #SysprofSpawnable
|
||||||
|
*/
|
||||||
|
SysprofSpawnable *
|
||||||
|
sysprof_spawnable_new (void)
|
||||||
|
{
|
||||||
|
return g_object_new (SYSPROF_TYPE_SPAWNABLE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fd_mapping_clear (gpointer data)
|
||||||
|
{
|
||||||
|
FDMapping *map = data;
|
||||||
|
|
||||||
|
if (map->fd != -1)
|
||||||
|
close (map->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_spawnable_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
SysprofSpawnable *self = (SysprofSpawnable *)object;
|
||||||
|
|
||||||
|
g_clear_pointer (&self->fds, g_array_unref);
|
||||||
|
g_clear_pointer (&self->argv, g_ptr_array_unref);
|
||||||
|
g_clear_pointer (&self->environ, g_strfreev);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (sysprof_spawnable_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_spawnable_class_init (SysprofSpawnableClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
object_class->finalize = sysprof_spawnable_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_spawnable_init (SysprofSpawnable *self)
|
||||||
|
{
|
||||||
|
self->next_fd = 3;
|
||||||
|
|
||||||
|
self->argv = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
g_ptr_array_add (self->argv, NULL);
|
||||||
|
|
||||||
|
self->fds = g_array_new (FALSE, FALSE, sizeof (FDMapping));
|
||||||
|
g_array_set_clear_func (self->fds, fd_mapping_clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_prepend_argv (SysprofSpawnable *self,
|
||||||
|
const gchar *argv)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
|
||||||
|
if (argv != NULL)
|
||||||
|
g_ptr_array_insert (self->argv, 0, g_strdup (argv));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_append_argv (SysprofSpawnable *self,
|
||||||
|
const gchar *argv)
|
||||||
|
{
|
||||||
|
gint pos;
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
|
||||||
|
if (argv == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pos = self->argv->len - 1;
|
||||||
|
g_ptr_array_add (self->argv, NULL);
|
||||||
|
g_ptr_array_index (self->argv, pos) = g_strdup (argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_append_args (SysprofSpawnable *self,
|
||||||
|
const gchar * const *args)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
|
||||||
|
if (args == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (guint i = 0; args[i]; i++)
|
||||||
|
sysprof_spawnable_append_argv (self, args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar * const *
|
||||||
|
sysprof_spawnable_get_argv (SysprofSpawnable *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), NULL);
|
||||||
|
|
||||||
|
return (const gchar * const *)(gpointer)self->argv->pdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar * const *
|
||||||
|
sysprof_spawnable_get_environ (SysprofSpawnable *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), NULL);
|
||||||
|
|
||||||
|
return (const gchar * const *)self->environ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_setenv (SysprofSpawnable *self,
|
||||||
|
const gchar *key,
|
||||||
|
const gchar *value)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
g_return_if_fail (key != NULL);
|
||||||
|
|
||||||
|
self->environ = g_environ_setenv (self->environ, key, value, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_set_environ (SysprofSpawnable *self,
|
||||||
|
const gchar * const *environ)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
|
||||||
|
if (environ != (const gchar * const *)self->environ)
|
||||||
|
{
|
||||||
|
g_strfreev (self->environ);
|
||||||
|
self->environ = g_strdupv ((gchar **)environ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
sysprof_spawnable_getenv (SysprofSpawnable *self,
|
||||||
|
const gchar *key)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), NULL);
|
||||||
|
g_return_val_if_fail (key != NULL, NULL);
|
||||||
|
|
||||||
|
return g_environ_getenv (self->environ, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
sysprof_spawnable_take_fd (SysprofSpawnable *self,
|
||||||
|
gint fd,
|
||||||
|
gint dest_fd)
|
||||||
|
{
|
||||||
|
FDMapping map;
|
||||||
|
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), -1);
|
||||||
|
|
||||||
|
if (dest_fd < 0)
|
||||||
|
dest_fd = self->next_fd++;
|
||||||
|
|
||||||
|
map.dest_fd = dest_fd;
|
||||||
|
map.fd = fd;
|
||||||
|
|
||||||
|
if (dest_fd >= self->next_fd)
|
||||||
|
self->next_fd = dest_fd + 1;
|
||||||
|
|
||||||
|
g_array_append_val (self->fds, map);
|
||||||
|
|
||||||
|
return dest_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_spawnable_foreach_fd (SysprofSpawnable *self,
|
||||||
|
SysprofSpawnableFDForeach foreach,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
g_return_if_fail (foreach != NULL);
|
||||||
|
|
||||||
|
for (guint i = 0; i < self->fds->len; i++)
|
||||||
|
{
|
||||||
|
const FDMapping *map = &g_array_index (self->fds, FDMapping, i);
|
||||||
|
|
||||||
|
foreach (map->dest_fd, map->fd, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_spawnable_set_starting_fd:
|
||||||
|
*
|
||||||
|
* Sets the next FD number to use when mapping a child FD. This helps
|
||||||
|
* in situations where the embedder knows that some lower-numbered FDs
|
||||||
|
* will be taken and therefore unknown to the spawnable.
|
||||||
|
*
|
||||||
|
* The default for this is 2.
|
||||||
|
*
|
||||||
|
* Since: 3.34
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sysprof_spawnable_set_starting_fd (SysprofSpawnable *self,
|
||||||
|
gint starting_fd)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
|
||||||
|
|
||||||
|
if (starting_fd < 0)
|
||||||
|
starting_fd = 2;
|
||||||
|
|
||||||
|
self->next_fd = starting_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_spawnable_spawn:
|
||||||
|
*
|
||||||
|
* Creates a new subprocess using the configured options.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a #GSubprocess or %NULL on failure and
|
||||||
|
* @error is set.
|
||||||
|
*
|
||||||
|
* Since: 3.34
|
||||||
|
*/
|
||||||
|
GSubprocess *
|
||||||
|
sysprof_spawnable_spawn (SysprofSpawnable *self,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
||||||
|
const gchar * const *argv;
|
||||||
|
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), NULL);
|
||||||
|
|
||||||
|
launcher = g_subprocess_launcher_new (0);
|
||||||
|
|
||||||
|
g_subprocess_launcher_set_environ (launcher, self->environ);
|
||||||
|
g_subprocess_launcher_set_cwd (launcher, g_get_home_dir ());
|
||||||
|
|
||||||
|
for (guint i = 0; i < self->fds->len; i++)
|
||||||
|
{
|
||||||
|
FDMapping *map = &g_array_index (self->fds, FDMapping, i);
|
||||||
|
|
||||||
|
g_subprocess_launcher_take_fd (launcher, map->fd, map->dest_fd);
|
||||||
|
map->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
argv = sysprof_spawnable_get_argv (self);
|
||||||
|
|
||||||
|
return g_subprocess_launcher_spawnv (launcher, argv, error);
|
||||||
|
}
|
||||||
78
src/libsysprof/sysprof-spawnable.h
Normal file
78
src/libsysprof/sysprof-spawnable.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* sysprof-spawnable.h
|
||||||
|
*
|
||||||
|
* Copyright 2019 Christian Hergert <chergert@redhat.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
#include "sysprof-version-macros.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define SYSPROF_TYPE_SPAWNABLE (sysprof_spawnable_get_type())
|
||||||
|
|
||||||
|
typedef void (*SysprofSpawnableFDForeach) (gint dest_fd,
|
||||||
|
gint fd,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
G_DECLARE_FINAL_TYPE (SysprofSpawnable, sysprof_spawnable, SYSPROF, SPAWNABLE, GObject)
|
||||||
|
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
SysprofSpawnable *sysprof_spawnable_new (void);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_prepend_argv (SysprofSpawnable *self,
|
||||||
|
const gchar *argv);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_append_argv (SysprofSpawnable *self,
|
||||||
|
const gchar *argv);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_append_args (SysprofSpawnable *self,
|
||||||
|
const gchar * const *argv);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
const gchar * const *sysprof_spawnable_get_argv (SysprofSpawnable *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
const gchar * const *sysprof_spawnable_get_environ (SysprofSpawnable *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_set_environ (SysprofSpawnable *self,
|
||||||
|
const gchar * const *environ);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_setenv (SysprofSpawnable *self,
|
||||||
|
const gchar *key,
|
||||||
|
const gchar *value);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
const gchar *sysprof_spawnable_getenv (SysprofSpawnable *self,
|
||||||
|
const gchar *key);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
gint sysprof_spawnable_take_fd (SysprofSpawnable *self,
|
||||||
|
gint fd,
|
||||||
|
gint dest_fd);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_foreach_fd (SysprofSpawnable *self,
|
||||||
|
SysprofSpawnableFDForeach foreach,
|
||||||
|
gpointer user_data);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_spawnable_set_starting_fd (SysprofSpawnable *self,
|
||||||
|
gint starting_fd);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
GSubprocess *sysprof_spawnable_spawn (SysprofSpawnable *self,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
@ -163,18 +163,17 @@ sysprof_tracefd_source_set_envvar (SysprofTracefdSource *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_tracefd_source_modify_spawn (SysprofSource *source,
|
sysprof_tracefd_source_modify_spawn (SysprofSource *source,
|
||||||
GSubprocessLauncher *launcher,
|
SysprofSpawnable *spawnable)
|
||||||
GPtrArray *argv)
|
|
||||||
{
|
{
|
||||||
SysprofTracefdSource *self = (SysprofTracefdSource *)source;
|
SysprofTracefdSource *self = (SysprofTracefdSource *)source;
|
||||||
SysprofTracefdSourcePrivate *priv = sysprof_tracefd_source_get_instance_private (self);
|
SysprofTracefdSourcePrivate *priv = sysprof_tracefd_source_get_instance_private (self);
|
||||||
gchar fdstr[12];
|
gchar fdstr[12];
|
||||||
|
gint dest_fd;
|
||||||
gint fd;
|
gint fd;
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_TRACEFD_SOURCE (self));
|
g_assert (SYSPROF_IS_TRACEFD_SOURCE (self));
|
||||||
g_assert (G_IS_SUBPROCESS_LAUNCHER (launcher));
|
g_assert (SYSPROF_IS_SPAWNABLE (spawnable));
|
||||||
g_assert (argv != NULL);
|
|
||||||
g_assert (priv->tracefd == -1);
|
g_assert (priv->tracefd == -1);
|
||||||
|
|
||||||
if (-1 == (fd = sysprof_memfd_create ("[sysprof-proxy-capture]")))
|
if (-1 == (fd = sysprof_memfd_create ("[sysprof-proxy-capture]")))
|
||||||
@ -192,9 +191,9 @@ sysprof_tracefd_source_modify_spawn (SysprofSource *source,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_snprintf (fdstr, sizeof fdstr, "%d", fd);
|
dest_fd = sysprof_spawnable_take_fd (spawnable, fd, -1);
|
||||||
g_subprocess_launcher_setenv (launcher, priv->envvar, fdstr, TRUE);
|
g_snprintf (fdstr, sizeof fdstr, "%d", dest_fd);
|
||||||
g_subprocess_launcher_take_fd (launcher, fd, fd);
|
sysprof_spawnable_setenv (spawnable, priv->envvar, fdstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -41,6 +41,7 @@ G_BEGIN_DECLS
|
|||||||
# include "sysprof-proxy-source.h"
|
# include "sysprof-proxy-source.h"
|
||||||
# include "sysprof-selection.h"
|
# include "sysprof-selection.h"
|
||||||
# include "sysprof-source.h"
|
# include "sysprof-source.h"
|
||||||
|
# include "sysprof-spawnable.h"
|
||||||
# include "sysprof-symbol-dirs.h"
|
# include "sysprof-symbol-dirs.h"
|
||||||
# include "sysprof-symbol-resolver.h"
|
# include "sysprof-symbol-resolver.h"
|
||||||
# include "sysprof-symbols-source.h"
|
# include "sysprof-symbols-source.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user