mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
sysprofd: make sysprofd exit after 120 seconds of inactivity
This commit is contained in:
@ -39,6 +39,13 @@ struct _IpcServiceImpl
|
||||
IpcServiceSkeleton parent_instance;
|
||||
};
|
||||
|
||||
enum {
|
||||
ACTIVITY,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
static guint signals [N_SIGNALS];
|
||||
|
||||
static gboolean
|
||||
ipc_service_impl_handle_list_processes (IpcService *service,
|
||||
GDBusMethodInvocation *invocation)
|
||||
@ -210,17 +217,19 @@ ipc_service_impl_g_authorize_method (GDBusInterfaceSkeleton *skeleton,
|
||||
g_assert (IPC_IS_SERVICE_IMPL (skeleton));
|
||||
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
||||
|
||||
g_signal_emit (skeleton, signals [ACTIVITY], 0);
|
||||
|
||||
peer_name = g_dbus_method_invocation_get_sender (invocation);
|
||||
|
||||
if (!(authority = polkit_authority_get_sync (NULL, NULL)) ||
|
||||
!(subject = polkit_system_bus_name_new (peer_name)) ||
|
||||
!(res = polkit_authority_check_authorization_sync (authority,
|
||||
POLKIT_SUBJECT (subject),
|
||||
"org.gnome.sysprof3.profile",
|
||||
NULL,
|
||||
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
||||
NULL,
|
||||
NULL)) ||
|
||||
POLKIT_SUBJECT (subject),
|
||||
"org.gnome.sysprof3.profile",
|
||||
NULL,
|
||||
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
||||
NULL,
|
||||
NULL)) ||
|
||||
!polkit_authorization_result_get_is_authorized (res))
|
||||
{
|
||||
g_dbus_method_invocation_return_error (g_steal_pointer (&invocation),
|
||||
@ -273,6 +282,17 @@ ipc_service_impl_class_init (IpcServiceImplClass *klass)
|
||||
GDBusInterfaceSkeletonClass *skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);
|
||||
|
||||
skeleton_class->g_authorize_method = ipc_service_impl_g_authorize_method;
|
||||
|
||||
signals [ACTIVITY] =
|
||||
g_signal_new ("activity",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
g_signal_set_va_marshaller (signals [ACTIVITY],
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
g_cclosure_marshal_VOID__VOIDv);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -31,11 +31,36 @@
|
||||
#define BUS_NAME "org.gnome.Sysprof3"
|
||||
#define OBJECT_PATH "/org/gnome/Sysprof3"
|
||||
#define NAME_ACQUIRE_DELAY_SECS 3
|
||||
#define INACTIVITY_TIMEOUT_SECS 120
|
||||
|
||||
static GMainLoop *main_loop;
|
||||
static gboolean name_acquired;
|
||||
static gint exit_status = EXIT_SUCCESS;
|
||||
|
||||
static guint inactivity;
|
||||
static G_LOCK_DEFINE (activity);
|
||||
|
||||
static gboolean
|
||||
inactivity_cb (gpointer data)
|
||||
{
|
||||
inactivity = 0;
|
||||
g_main_loop_quit (main_loop);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
activity_cb (IpcService *service,
|
||||
gpointer user_data)
|
||||
{
|
||||
G_LOCK (activity);
|
||||
if (inactivity)
|
||||
g_source_remove (inactivity);
|
||||
inactivity = g_timeout_add_seconds (INACTIVITY_TIMEOUT_SECS,
|
||||
inactivity_cb,
|
||||
NULL);
|
||||
G_UNLOCK (activity);
|
||||
}
|
||||
|
||||
static void
|
||||
name_acquired_cb (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
@ -93,6 +118,13 @@ main (gint argc,
|
||||
{
|
||||
g_autoptr(IpcService) service = ipc_service_impl_new ();
|
||||
|
||||
g_signal_connect (service,
|
||||
"activity",
|
||||
G_CALLBACK (activity_cb),
|
||||
NULL);
|
||||
|
||||
activity_cb (service, NULL);
|
||||
|
||||
if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (service),
|
||||
bus,
|
||||
OBJECT_PATH,
|
||||
|
||||
Reference in New Issue
Block a user