Debian Codegraph @

src/libsysprof/sysprof-util.c

raw
1 /*
2 * sysprof-util.c
3 *
4 * Copyright 2025 Christian Hergert <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GPL-3.0-or-later
20 */
21
22 #include "config.h"
23
24 #include "sysprof-util-private.h"
25
26 DexFuture *
27 sysprof_get_proc_file_bytes (GDBusConnection *connection,
28 const char *path)
29 {
30 g_autoptr(GError) error = NULL;
31
32 dex_return_error_if_fail (!connection || G_IS_DBUS_CONNECTION (connection));
33 dex_return_error_if_fail (path != NULL);
34
35 if (connection != NULL)
36 {
37 g_autoptr(GVariant) reply = NULL;
38 g_autoptr(GBytes) bytes = NULL;
39 const char *contents = NULL;
40
41 if (!(reply = dex_await_variant (dex_dbus_connection_call (connection,
42 "org.gnome.Sysprof3",
43 "/org/gnome/Sysprof3",
44 "org.gnome.Sysprof3.Service",
45 "GetProcFile",
46 g_variant_new ("(^ay)", path),
47 G_VARIANT_TYPE ("(ay)"),
48 G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
49 G_MAXINT),
50 &error)))
51 return dex_future_new_for_error (g_steal_pointer (&error));
52
53 g_variant_get (reply, "(^&ay)", &contents);
54
55 g_assert (contents != NULL);
56
57 return dex_future_new_take_boxed (G_TYPE_BYTES,
58 g_bytes_new_with_free_func (contents, strlen (contents),
59 (GDestroyNotify) g_variant_unref,
60 g_steal_pointer (&reply)));
61 }
62 else
63 {
64 g_autoptr(GFile) file = g_file_new_for_path (path);
65 return dex_file_load_contents_bytes (file);
66 }
67 }