summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2019-03-07 14:49:19 +0100
committerAleksander Morgado <aleksander@aleksander.es>2019-03-07 14:49:19 +0100
commit3054a3eedb96517223416dbb39e2bf97e2a34d67 (patch)
tree89107615a9e7a6e4990f7cd0caf15f4f0fca47ce
parent4de29533df65537bcf46e942fd165458b6bd9ac7 (diff)
downloadlibqmi-aleksander/qmi-proxy-timing.tar.gz
qmi-proxy: new '--empty-timeout=[SECS}' optionaleksander/qmi-proxy-timing
We allow specifying how long the proxy should be kept running after the last client has exited.
-rw-r--r--src/qmi-proxy/qmi-proxy.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/qmi-proxy/qmi-proxy.c b/src/qmi-proxy/qmi-proxy.c
index 465ec5c5..1282987c 100644
--- a/src/qmi-proxy/qmi-proxy.c
+++ b/src/qmi-proxy/qmi-proxy.c
@@ -35,7 +35,7 @@
#define PROGRAM_NAME "qmi-proxy"
#define PROGRAM_VERSION PACKAGE_VERSION
-#define EMPTY_PROXY_LIFETIME_SECS 300
+#define EMPTY_TIMEOUT_DEFAULT 300
/* Globals */
static GMainLoop *loop;
@@ -46,12 +46,17 @@ static guint timeout_id;
static gboolean verbose_flag;
static gboolean version_flag;
static gboolean no_exit_flag;
+static gint empty_timeout = -1;
static GOptionEntry main_entries[] = {
{ "no-exit", 0, 0, G_OPTION_ARG_NONE, &no_exit_flag,
"Don't exit after being idle without clients",
NULL
},
+ { "empty-timeout", 0, 0, G_OPTION_ARG_INT, &empty_timeout,
+ "If no clients, exit after this timeout. If set to 0, equivalent to --no-exit.",
+ "[SECS]"
+ },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag,
"Run action with verbose logs, including the debug ones",
NULL
@@ -152,7 +157,8 @@ proxy_n_clients_changed (QmiProxy *_proxy)
{
if (qmi_proxy_get_n_clients (proxy) == 0) {
g_assert (timeout_id == 0);
- timeout_id = g_timeout_add_seconds (EMPTY_PROXY_LIFETIME_SECS,
+ g_assert (empty_timeout > 0);
+ timeout_id = g_timeout_add_seconds (empty_timeout,
(GSourceFunc)stop_loop_cb,
NULL);
return;
@@ -197,6 +203,10 @@ int main (int argc, char **argv)
g_unix_signal_add (SIGHUP, quit_cb, NULL);
g_unix_signal_add (SIGTERM, quit_cb, NULL);
+ /* Setup empty timeout */
+ if (empty_timeout < 0)
+ empty_timeout = EMPTY_TIMEOUT_DEFAULT;
+
/* Setup proxy */
proxy = qmi_proxy_new (&error);
if (!proxy) {
@@ -205,13 +215,15 @@ int main (int argc, char **argv)
}
/* Don't exit the proxy when no clients are found */
- if (!no_exit_flag) {
+ if (!no_exit_flag && empty_timeout != 0) {
+ g_debug ("proxy will exit after %d secs if unused", empty_timeout);
proxy_n_clients_changed (proxy);
g_signal_connect (proxy,
"notify::" QMI_PROXY_N_CLIENTS,
G_CALLBACK (proxy_n_clients_changed),
NULL);
- }
+ } else
+ g_debug ("proxy will remain running if unused");
/* Loop */
loop = g_main_loop_new (NULL, FALSE);