Add timeout support, delete connection on errors
This commit is contained in:
parent
7f6f56a7d5
commit
4bc3bc211d
1 changed files with 28 additions and 0 deletions
|
@ -123,6 +123,7 @@ typedef struct {
|
||||||
int ret;
|
int ret;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
NMClient *client;
|
NMClient *client;
|
||||||
|
NMRemoteConnection *con;
|
||||||
} cb_arg;
|
} cb_arg;
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,6 +141,13 @@ static NMDevice * find_device(NMClient *client) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean timeout_cb(gpointer user_data) {
|
||||||
|
cb_arg *arg = user_data;
|
||||||
|
g_main_loop_quit(arg->loop);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void state_cb(NMDevice *device, UNUSED GParamSpec *pspec, gpointer user_data) {
|
static void state_cb(NMDevice *device, UNUSED GParamSpec *pspec, gpointer user_data) {
|
||||||
cb_arg *arg = user_data;
|
cb_arg *arg = user_data;
|
||||||
|
|
||||||
|
@ -179,14 +187,24 @@ static void add_cb(UNUSED NMRemoteSettings *settings, NMRemoteConnection *con, G
|
||||||
if (!device)
|
if (!device)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
arg->con = con;
|
||||||
|
|
||||||
g_signal_connect(device, "notify::state", G_CALLBACK(state_cb), arg);
|
g_signal_connect(device, "notify::state", G_CALLBACK(state_cb), arg);
|
||||||
nm_client_activate_connection(arg->client, NM_CONNECTION(con), device, NULL, activate_cb, arg);
|
nm_client_activate_connection(arg->client, NM_CONNECTION(con), device, NULL, activate_cb, arg);
|
||||||
|
|
||||||
|
g_timeout_add_seconds(CONNECTION_TIMEOUT, timeout_cb, arg);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
g_main_loop_quit(arg->loop);
|
g_main_loop_quit(arg->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void delete_cb(UNUSED NMRemoteConnection *connection, UNUSED GError *error, gpointer user_data) {
|
||||||
|
cb_arg *arg = user_data;
|
||||||
|
|
||||||
|
g_main_loop_quit(arg->loop);
|
||||||
|
}
|
||||||
|
|
||||||
static int authenticate(const char *user, const char *pass) {
|
static int authenticate(const char *user, const char *pass) {
|
||||||
DBusGConnection *dbus = NULL;
|
DBusGConnection *dbus = NULL;
|
||||||
NMRemoteSettings *settings = NULL;
|
NMRemoteSettings *settings = NULL;
|
||||||
|
@ -218,6 +236,16 @@ static int authenticate(const char *user, const char *pass) {
|
||||||
|
|
||||||
g_main_loop_run(arg.loop);
|
g_main_loop_run(arg.loop);
|
||||||
|
|
||||||
|
if (arg.ret == PAM_SUCCESS)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
/* Error */
|
||||||
|
if (arg.con) {
|
||||||
|
nm_remote_connection_delete(arg.con, delete_cb, &arg);
|
||||||
|
|
||||||
|
g_main_loop_run(arg.loop);
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
g_object_unref(con);
|
g_object_unref(con);
|
||||||
|
|
||||||
|
|
Reference in a new issue