summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2022-12-06 20:44:48 -0600
committerFederico Mena Quintero <federico@gnome.org>2022-12-06 20:50:13 -0600
commitb10fcf21b1ef49dd3d6297ac657434ece3b23578 (patch)
treed560f8449f3ae75fea343887dcb6d5f4df7b434c /bus
parentbf4d71a38b970699f63ce7b701e9bf4c9d31f717 (diff)
downloadat-spi2-core-b10fcf21b1ef49dd3d6297ac657434ece3b23578.tar.gz
Reformat all the *.[ch] files with clang-format
I ran this on each directory with C files: clang-format -i *.[ch] "-i" is the in-place option. I also adjusted the order of #includes for some files which failed to build after that: Clang-format reorders blocks of #include directives alphabetically, but they can be grouped and separated by blank lines. If there is a blank line between blocks, like #include "zork.h" #include "bar.h" #include "foo.h" then it will not put zork.h after the other two. The last two header files will be sorted alphabetically. We can adjust the formatting of chunks of code by hand with comments like these: /* clang-format off */ this code { is, formatted, by, hand; } /* clang-format on */ See https://clang.llvm.org/docs/ClangFormat.html for the general manual and https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the style options and the comments described above.
Diffstat (limited to 'bus')
-rw-r--r--bus/at-spi-bus-launcher.c315
1 files changed, 155 insertions, 160 deletions
diff --git a/bus/at-spi-bus-launcher.c b/bus/at-spi-bus-launcher.c
index 0633c303..53ae3ff1 100644
--- a/bus/at-spi-bus-launcher.c
+++ b/bus/at-spi-bus-launcher.c
@@ -1,6 +1,6 @@
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
- *
- * at-spi-bus-launcher: Manage the a11y bus as a child process
+ *
+ * at-spi-bus-launcher: Manage the a11y bus as a child process
*
* Copyright 2011-2018 Red Hat, Inc.
*
@@ -22,36 +22,38 @@
#include "config.h"
-#include <unistd.h>
-#include <string.h>
#include <signal.h>
+#include <string.h>
+#include <unistd.h>
#ifdef __linux__
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#endif
-#include <sys/wait.h>
#include <errno.h>
#include <stdio.h>
+#include <sys/wait.h>
#include <gio/gio.h>
#ifdef HAVE_X11
-#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/Xlib.h>
#endif
#ifdef DBUS_BROKER
#include <systemd/sd-login.h>
#endif
#include <sys/stat.h>
-typedef enum {
+typedef enum
+{
A11Y_BUS_STATE_IDLE = 0,
A11Y_BUS_STATE_READING_ADDRESS,
A11Y_BUS_STATE_RUNNING,
A11Y_BUS_STATE_ERROR
} A11yBusState;
-typedef struct {
+typedef struct
+{
GMainLoop *loop;
gboolean launch_immediately;
gboolean a11y_enabled;
@@ -80,17 +82,17 @@ typedef struct {
static A11yBusLauncher *_global_app = NULL;
static const gchar introspection_xml[] =
- "<node>"
- " <interface name='org.a11y.Bus'>"
- " <method name='GetAddress'>"
- " <arg type='s' name='address' direction='out'/>"
- " </method>"
- " </interface>"
- " <interface name='org.a11y.Status'>"
- " <property name='IsEnabled' type='b' access='readwrite'/>"
- " <property name='ScreenReaderEnabled' type='b' access='readwrite'/>"
- " </interface>"
- "</node>";
+ "<node>"
+ " <interface name='org.a11y.Bus'>"
+ " <method name='GetAddress'>"
+ " <arg type='s' name='address' direction='out'/>"
+ " </method>"
+ " </interface>"
+ " <interface name='org.a11y.Status'>"
+ " <property name='IsEnabled' type='b' access='readwrite'/>"
+ " <property name='ScreenReaderEnabled' type='b' access='readwrite'/>"
+ " </interface>"
+ "</node>";
static GDBusNodeInfo *introspection_data = NULL;
static void
@@ -108,10 +110,10 @@ respond_to_end_session (GDBusProxy *proxy)
static void
g_signal_cb (GDBusProxy *proxy,
- gchar *sender_name,
- gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
+ gchar *sender_name,
+ gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
@@ -124,9 +126,9 @@ g_signal_cb (GDBusProxy *proxy,
}
static void
-client_proxy_ready_cb (GObject *source_object,
+client_proxy_ready_cb (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
GError *error = NULL;
@@ -230,14 +232,13 @@ register_client (A11yBusLauncher *app)
"RegisterClient", parameters,
G_DBUS_CALL_FLAGS_NONE,
G_MAXINT, NULL, client_registered, app);
-
}
static void
name_appeared_handler (GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data)
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
@@ -250,10 +251,10 @@ name_appeared_handler (GDBusConnection *connection,
* Read all data from a file descriptor to a C string buffer.
*/
static gboolean
-unix_read_all_fd_to_string (int fd,
- char *buf,
- ssize_t max_bytes,
- char **error_msg)
+unix_read_all_fd_to_string (int fd,
+ char *buf,
+ ssize_t max_bytes,
+ char **error_msg)
{
g_assert (max_bytes > 1);
*error_msg = NULL;
@@ -293,12 +294,12 @@ unix_read_all_fd_to_string (int fd,
}
static void
-on_bus_exited (GPid pid,
- gint status,
+on_bus_exited (GPid pid,
+ gint status,
gpointer data)
{
A11yBusLauncher *app = data;
-
+
app->a11y_bus_pid = -1;
app->state = A11Y_BUS_STATE_ERROR;
if (app->a11y_launch_error_message == NULL)
@@ -347,7 +348,7 @@ ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
g_clear_pointer (&app->a11y_launch_error_message, g_free);
if (!g_spawn_async_with_pipes_and_fds (NULL,
- (const gchar * const *) argv,
+ (const gchar *const *) argv,
NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
NULL, /* child_setup */
@@ -412,7 +413,7 @@ error:
static gboolean
ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
{
- return FALSE;
+ return FALSE;
}
#endif
@@ -426,11 +427,11 @@ setup_bus_child_broker (gpointer data)
dup2 (app->listenfd, 3);
close (app->listenfd);
- g_setenv("LISTEN_FDS", "1", TRUE);
+ g_setenv ("LISTEN_FDS", "1", TRUE);
- pid_str = g_strdup_printf("%u", getpid());
- g_setenv("LISTEN_PID", pid_str, TRUE);
- g_free(pid_str);
+ pid_str = g_strdup_printf ("%u", getpid ());
+ g_setenv ("LISTEN_PID", pid_str, TRUE);
+ g_free (pid_str);
}
static gboolean
@@ -439,7 +440,7 @@ ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
char *argv[] = { DBUS_BROKER, config_path, "--scope", "user", NULL };
char *unit;
struct sockaddr_un addr = { .sun_family = AF_UNIX, "" };
- socklen_t addr_len = sizeof(addr);
+ socklen_t addr_len = sizeof (addr);
GPid pid;
GError *error = NULL;
@@ -466,15 +467,15 @@ ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
if ((app->listenfd = socket (PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0)
g_error ("Failed to create listening socket: %s", strerror (errno));
- if (bind (app->listenfd, (struct sockaddr *)&addr, addr_len) < 0)
+ if (bind (app->listenfd, (struct sockaddr *) &addr, addr_len) < 0)
g_error ("Failed to bind listening socket: %s", strerror (errno));
if (!app->socket_name &&
- getsockname (app->listenfd, (struct sockaddr *)&addr, &addr_len) < 0)
- g_error ("Failed to get socket name for listening socket: %s", strerror(errno));
+ getsockname (app->listenfd, (struct sockaddr *) &addr, &addr_len) < 0)
+ g_error ("Failed to get socket name for listening socket: %s", strerror (errno));
if (listen (app->listenfd, 1024) < 0)
- g_error ("Failed to listen on socket: %s", strerror(errno));
+ g_error ("Failed to listen on socket: %s", strerror (errno));
g_clear_pointer (&app->a11y_launch_error_message, g_free);
@@ -502,9 +503,9 @@ ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
app->state = A11Y_BUS_STATE_RUNNING;
if (app->socket_name)
- app->a11y_bus_address = g_strconcat("unix:path=", addr.sun_path, NULL);
+ app->a11y_bus_address = g_strconcat ("unix:path=", addr.sun_path, NULL);
else
- app->a11y_bus_address = g_strconcat("unix:abstract=", addr.sun_path + 1, NULL);
+ app->a11y_bus_address = g_strconcat ("unix:abstract=", addr.sun_path + 1, NULL);
g_debug ("a11y bus address: %s", app->a11y_bus_address);
return TRUE;
@@ -519,7 +520,7 @@ error:
static gboolean
ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
{
- return FALSE;
+ return FALSE;
}
#endif
@@ -533,55 +534,55 @@ ensure_a11y_bus (A11yBusLauncher *app)
if (app->a11y_bus_pid != 0)
return FALSE;
- if (g_file_test (SYSCONFDIR"/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
- config_path = "--config-file="SYSCONFDIR"/at-spi2/accessibility.conf";
+ if (g_file_test (SYSCONFDIR "/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
+ config_path = "--config-file=" SYSCONFDIR "/at-spi2/accessibility.conf";
else
- config_path = "--config-file="DATADIR"/defaults/at-spi2/accessibility.conf";
-
- xdg_runtime_dir = g_get_user_runtime_dir ();
- if (xdg_runtime_dir)
- {
- const gchar *display = g_getenv ("DISPLAY");
- gchar *at_spi_dir = g_strconcat (xdg_runtime_dir, "/at-spi", NULL);
- gchar *p;
- mkdir (xdg_runtime_dir, 0700);
- if (!g_path_is_absolute (at_spi_dir))
+ config_path = "--config-file=" DATADIR "/defaults/at-spi2/accessibility.conf";
+
+ xdg_runtime_dir = g_get_user_runtime_dir ();
+ if (xdg_runtime_dir)
+ {
+ const gchar *display = g_getenv ("DISPLAY");
+ gchar *at_spi_dir = g_strconcat (xdg_runtime_dir, "/at-spi", NULL);
+ gchar *p;
+ mkdir (xdg_runtime_dir, 0700);
+ if (!g_path_is_absolute (at_spi_dir))
{
gchar *new_dir = g_canonicalize_filename (at_spi_dir, NULL);
g_free (at_spi_dir);
at_spi_dir = new_dir;
}
- if (mkdir (at_spi_dir, 0700) == 0 || errno == EEXIST)
- {
- app->socket_name = g_strconcat (at_spi_dir, "/bus", display, NULL);
- g_free (at_spi_dir);
- p = strchr (app->socket_name, ':');
- if (p)
- *p = '_';
- if (strlen (app->socket_name) >= 100)
- {
- g_free (app->socket_name);
- app->socket_name = NULL;
- }
- }
- else
+ if (mkdir (at_spi_dir, 0700) == 0 || errno == EEXIST)
+ {
+ app->socket_name = g_strconcat (at_spi_dir, "/bus", display, NULL);
g_free (at_spi_dir);
- }
+ p = strchr (app->socket_name, ':');
+ if (p)
+ *p = '_';
+ if (strlen (app->socket_name) >= 100)
+ {
+ g_free (app->socket_name);
+ app->socket_name = NULL;
+ }
+ }
+ else
+ g_free (at_spi_dir);
+ }
#ifdef WANT_DBUS_BROKER
- success = ensure_a11y_bus_broker (app, config_path);
- if (!success)
- {
- if (!ensure_a11y_bus_daemon (app, config_path))
- return FALSE;
- }
+ success = ensure_a11y_bus_broker (app, config_path);
+ if (!success)
+ {
+ if (!ensure_a11y_bus_daemon (app, config_path))
+ return FALSE;
+ }
#else
- success = ensure_a11y_bus_daemon (app, config_path);
- if (!success)
- {
- if (!ensure_a11y_bus_broker (app, config_path))
- return FALSE;
- }
+ success = ensure_a11y_bus_daemon (app, config_path);
+ if (!success)
+ {
+ if (!ensure_a11y_bus_broker (app, config_path))
+ return FALSE;
+ }
#endif
#ifdef HAVE_X11
@@ -607,14 +608,14 @@ ensure_a11y_bus (A11yBusLauncher *app)
}
static void
-handle_method_call (GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
GDBusMethodInvocation *invocation,
- gpointer user_data)
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
@@ -632,13 +633,13 @@ handle_method_call (GDBusConnection *connection,
}
static GVariant *
-handle_get_property (GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *property_name,
- GError **error,
- gpointer user_data)
+handle_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
@@ -651,8 +652,7 @@ handle_get_property (GDBusConnection *connection,
}
static void
-handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled,
- gboolean notify_gsettings)
+handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled, gboolean notify_gsettings)
{
GVariantBuilder builder;
GVariantBuilder invalidated_builder;
@@ -687,8 +687,7 @@ handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled,
}
static void
-handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
- gboolean notify_gsettings)
+handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled, gboolean notify_gsettings)
{
GVariantBuilder builder;
GVariantBuilder invalidated_builder;
@@ -728,23 +727,23 @@ handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
}
static gboolean
-handle_set_property (GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *property_name,
- GVariant *value,
- GError **error,
- gpointer user_data)
+handle_set_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GVariant *value,
+ GError **error,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
const gchar *type = g_variant_get_type_string (value);
gboolean enabled;
-
+
if (g_strcmp0 (type, "b") != 0)
{
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
- "org.a11y.Status.%s expects a boolean but got %s", property_name, type);
+ "org.a11y.Status.%s expects a boolean but got %s", property_name, type);
return FALSE;
}
@@ -763,20 +762,18 @@ handle_set_property (GDBusConnection *connection,
else
{
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
- "Unknown property '%s'", property_name);
+ "Unknown property '%s'", property_name);
return FALSE;
}
}
-static const GDBusInterfaceVTable bus_vtable =
-{
+static const GDBusInterfaceVTable bus_vtable = {
handle_method_call,
NULL, /* handle_get_property, */
NULL /* handle_set_property */
};
-static const GDBusInterfaceVTable status_vtable =
-{
+static const GDBusInterfaceVTable status_vtable = {
NULL, /* handle_method_call */
handle_get_property,
handle_set_property
@@ -784,13 +781,13 @@ static const GDBusInterfaceVTable status_vtable =
static void
on_bus_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
GError *error;
guint registration_id;
-
+
if (connection == NULL)
{
g_main_loop_quit (app->loop);
@@ -823,21 +820,19 @@ on_bus_acquired (GDBusConnection *connection,
static void
on_name_lost (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
- if (app->session_bus == NULL
- && connection == NULL
- && app->a11y_launch_error_message == NULL)
+ if (app->session_bus == NULL && connection == NULL && app->a11y_launch_error_message == NULL)
app->a11y_launch_error_message = g_strdup ("Failed to connect to session bus");
g_main_loop_quit (app->loop);
}
static void
on_name_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
@@ -867,12 +862,12 @@ sigterm_handler (int signum)
}
static gboolean
-on_sigterm_pipe (GIOChannel *channel,
+on_sigterm_pipe (GIOChannel *channel,
GIOCondition condition,
- gpointer data)
+ gpointer data)
{
A11yBusLauncher *app = data;
-
+
g_main_loop_quit (app->loop);
return FALSE;
@@ -897,7 +892,7 @@ init_sigterm_handling (A11yBusLauncher *app)
static GSettings *
get_schema (const gchar *name)
{
-#if GLIB_CHECK_VERSION (2, 32, 0)
+#if GLIB_CHECK_VERSION(2, 32, 0)
GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
if (!source)
{
@@ -911,15 +906,15 @@ get_schema (const gchar *name)
return g_settings_new_full (schema, NULL, NULL);
#else
- const char * const *schemas = NULL;
+ const char *const *schemas = NULL;
gint i;
schemas = g_settings_list_schemas ();
for (i = 0; schemas[i]; i++)
- {
- if (!strcmp (schemas[i], name))
- return g_settings_new (schemas[i]);
- }
+ {
+ if (!strcmp (schemas[i], name))
+ return g_settings_new (schemas[i]);
+ }
return NULL;
#endif
@@ -937,7 +932,7 @@ gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
}
int
-main (int argc,
+main (int argc,
char **argv)
{
gboolean a11y_set = FALSE;
@@ -956,8 +951,8 @@ main (int argc,
else if (sscanf (argv[i], "--screen-reader=%d",
&_global_app->screen_reader_enabled) == 1)
screen_reader_set = TRUE;
- else
- g_error ("usage: %s [--launch-immediately] [--a11y=0|1] [--screen-reader=0|1]", argv[0]);
+ else
+ g_error ("usage: %s [--launch-immediately] [--a11y=0|1] [--screen-reader=0|1]", argv[0]);
}
_global_app->interface_schema = get_schema ("org.gnome.desktop.interface");
@@ -966,15 +961,15 @@ main (int argc,
if (!a11y_set)
{
_global_app->a11y_enabled = _global_app->interface_schema
- ? g_settings_get_boolean (_global_app->interface_schema, "toolkit-accessibility")
- : _global_app->launch_immediately;
+ ? g_settings_get_boolean (_global_app->interface_schema, "toolkit-accessibility")
+ : _global_app->launch_immediately;
}
if (!screen_reader_set)
{
_global_app->screen_reader_enabled = _global_app->a11y_schema
- ? g_settings_get_boolean (_global_app->a11y_schema, "screen-reader-enabled")
- : FALSE;
+ ? g_settings_get_boolean (_global_app->a11y_schema, "screen-reader-enabled")
+ : FALSE;
}
if (_global_app->interface_schema)
@@ -993,14 +988,14 @@ main (int argc,
g_assert (introspection_data != NULL);
_global_app->name_owner_id =
- g_bus_own_name (G_BUS_TYPE_SESSION,
- "org.a11y.Bus",
- G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- _global_app,
- NULL);
+ g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.a11y.Bus",
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ _global_app,
+ NULL);
g_main_loop_run (_global_app->loop);
@@ -1011,10 +1006,10 @@ main (int argc,
_global_app->a11y_bus_pid = -1;
}
- /* Clear the X property if our bus is gone; in the case where e.g.
- * GDM is launching a login on an X server it was using before,
- * we don't want early login processes to pick up the stale address.
- */
+ /* Clear the X property if our bus is gone; in the case where e.g.
+ * GDM is launching a login on an X server it was using before,
+ * we don't want early login processes to pick up the stale address.
+ */
#ifdef HAVE_X11
if (_global_app->x11_prop_set)
{