mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 04:13:33 +02:00
Exit when no devices are in use
When no actions are happening on any of the devices, make the daemon exit after 30 seconds.
This commit is contained in:
committed by
Daniel Drake
parent
e29806cd88
commit
b0f2060628
@ -24,8 +24,10 @@
|
|||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
|
|
||||||
/* General */
|
/* General */
|
||||||
|
#define TIMEOUT 30
|
||||||
#define FPRINT_SERVICE_NAME "net.reactivated.Fprint"
|
#define FPRINT_SERVICE_NAME "net.reactivated.Fprint"
|
||||||
extern DBusGConnection *fprintd_dbus_conn;
|
extern DBusGConnection *fprintd_dbus_conn;
|
||||||
|
extern gboolean no_timeout;
|
||||||
GQuark fprint_error_quark(void);
|
GQuark fprint_error_quark(void);
|
||||||
|
|
||||||
/* Errors */
|
/* Errors */
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
#include "file_storage.h"
|
#include "file_storage.h"
|
||||||
|
|
||||||
DBusGConnection *fprintd_dbus_conn = NULL;
|
DBusGConnection *fprintd_dbus_conn = NULL;
|
||||||
|
gboolean no_timeout = FALSE;
|
||||||
static gboolean g_fatal_warnings = FALSE;
|
static gboolean g_fatal_warnings = FALSE;
|
||||||
|
|
||||||
GQuark fprint_error_quark(void)
|
GQuark fprint_error_quark(void)
|
||||||
@ -287,6 +288,7 @@ bail:
|
|||||||
|
|
||||||
static const GOptionEntry entries[] = {
|
static const GOptionEntry entries[] = {
|
||||||
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
|
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
|
||||||
|
{"no-timeout", 't', 0, G_OPTION_ARG_NONE, &no_timeout, "Do not exit after unused for a while", NULL},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <dbus/dbus-glib-bindings.h>
|
#include <dbus/dbus-glib-bindings.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
@ -38,6 +40,8 @@ typedef struct
|
|||||||
{
|
{
|
||||||
GError *last_error;
|
GError *last_error;
|
||||||
GSList *dev_registry;
|
GSList *dev_registry;
|
||||||
|
guint timeout_id;
|
||||||
|
volatile int num_device_used;
|
||||||
} FprintManagerPrivate;
|
} FprintManagerPrivate;
|
||||||
|
|
||||||
#define FPRINT_MANAGER_GET_PRIVATE(o) \
|
#define FPRINT_MANAGER_GET_PRIVATE(o) \
|
||||||
@ -71,6 +75,35 @@ static gchar *get_device_path(FprintDevice *rdev)
|
|||||||
_fprint_device_get_id(rdev));
|
_fprint_device_get_id(rdev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
fprint_manager_timeout_cb (FprintManager *manager)
|
||||||
|
{
|
||||||
|
g_message ("No devices in use, exit");
|
||||||
|
//FIXME kill all the devices
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fprint_manager_action_notified (FprintDevice *rdev, GParamSpec *spec, FprintManager *manager)
|
||||||
|
{
|
||||||
|
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||||
|
int action;
|
||||||
|
|
||||||
|
g_object_get (G_OBJECT(rdev), "action", &action, NULL);
|
||||||
|
if (priv->timeout_id > 0) {
|
||||||
|
g_source_remove (priv->timeout_id);
|
||||||
|
priv->timeout_id = 0;
|
||||||
|
}
|
||||||
|
if (action == 0) {
|
||||||
|
if (g_atomic_int_dec_and_test (&priv->num_device_used)) {
|
||||||
|
if (!no_timeout)
|
||||||
|
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g_atomic_int_add (&priv->num_device_used, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fprint_manager_init (FprintManager *manager)
|
fprint_manager_init (FprintManager *manager)
|
||||||
{
|
{
|
||||||
@ -79,6 +112,8 @@ fprint_manager_init (FprintManager *manager)
|
|||||||
struct fp_dscv_dev *ddev;
|
struct fp_dscv_dev *ddev;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
priv->num_device_used = 0;
|
||||||
|
|
||||||
if (!discovered_devs) {
|
if (!discovered_devs) {
|
||||||
priv->last_error = g_error_new (FPRINT_ERROR, FPRINT_ERROR_INTERNAL,
|
priv->last_error = g_error_new (FPRINT_ERROR, FPRINT_ERROR_INTERNAL,
|
||||||
_("An internal error occurred in libfprint"));
|
_("An internal error occurred in libfprint"));
|
||||||
@ -92,12 +127,18 @@ fprint_manager_init (FprintManager *manager)
|
|||||||
FprintDevice *rdev = fprint_device_new(ddev);
|
FprintDevice *rdev = fprint_device_new(ddev);
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT(rdev), "notify::action",
|
||||||
|
G_CALLBACK (fprint_manager_action_notified), manager);
|
||||||
|
|
||||||
priv->dev_registry = g_slist_prepend(priv->dev_registry, rdev);
|
priv->dev_registry = g_slist_prepend(priv->dev_registry, rdev);
|
||||||
path = get_device_path(rdev);
|
path = get_device_path(rdev);
|
||||||
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
||||||
G_OBJECT(rdev));
|
G_OBJECT(rdev));
|
||||||
g_free(path);
|
g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!no_timeout)
|
||||||
|
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
FprintManager *fprint_manager_new(void)
|
FprintManager *fprint_manager_new(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user