mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 07:08:02 +02:00
Merge fixes for nm-online (rh #rh1054364)
https://bugzilla.redhat.com/show_bug.cgi?id=1054364
This commit is contained in:
commit
0d1bdffe91
4 changed files with 55 additions and 13 deletions
|
|
@ -7,7 +7,7 @@ Before=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=@bindir@/nm-online -q --timeout=30
|
ExecStart=@bindir@/nm-online -s -q --timeout=30
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=network.target
|
WantedBy=network.target
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Before=network.target network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=@bindir@/nm-online -q --timeout=30
|
ExecStart=@bindir@/nm-online -s -q --timeout=30
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@
|
||||||
.\" with this manual; if not, write to the Free Software Foundation, Inc.,
|
.\" with this manual; if not, write to the Free Software Foundation, Inc.,
|
||||||
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (C) 2010 Red Hat, Inc.
|
.\" Copyright (C) 2010 - 2014 Red Hat, Inc.
|
||||||
.\"
|
.\"
|
||||||
.TH NM-ONLINE "1" "11 July 2013"
|
.TH NM-ONLINE "1" "25 March 2014"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
nm-online \- ask NetworkManager whether the network is connected
|
nm-online \- ask NetworkManager whether the network is connected
|
||||||
|
|
@ -47,6 +47,9 @@ Exit immediately if NetworkManager is not running or connecting.
|
||||||
.TP
|
.TP
|
||||||
.B \-q, \-\-quiet
|
.B \-q, \-\-quiet
|
||||||
Don't print anything.
|
Don't print anything.
|
||||||
|
.TP
|
||||||
|
.B \-s, \-\-wait-for-startup
|
||||||
|
Wait for NetworkManager finishing its startup instead of establishing a connection.
|
||||||
|
|
||||||
.SH EXIT STATUS
|
.SH EXIT STATUS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 - 2008 Novell, Inc.
|
* Copyright (C) 2006 - 2008 Novell, Inc.
|
||||||
|
* Copyright (C) 2008 - 2014 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -42,6 +43,7 @@
|
||||||
#include "nm-client.h"
|
#include "nm-client.h"
|
||||||
|
|
||||||
#define PROGRESS_STEPS 15
|
#define PROGRESS_STEPS 15
|
||||||
|
#define WAIT_STARTUP_TAG "wait-startup"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
@ -56,11 +58,22 @@ client_properties_changed (GObject *object,
|
||||||
gpointer loop)
|
gpointer loop)
|
||||||
{
|
{
|
||||||
NMClient *client = NM_CLIENT (object);
|
NMClient *client = NM_CLIENT (object);
|
||||||
|
NMState state;
|
||||||
|
gboolean wait_startup = GPOINTER_TO_UINT (g_object_get_data (object, WAIT_STARTUP_TAG));
|
||||||
|
|
||||||
if (!nm_client_get_manager_running (client))
|
if (!nm_client_get_manager_running (client))
|
||||||
return;
|
return;
|
||||||
if (!nm_client_get_startup (client))
|
|
||||||
g_main_loop_quit (loop);
|
if (wait_startup) {
|
||||||
|
if (!nm_client_get_startup (client))
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
} else {
|
||||||
|
state = nm_client_get_state (client);
|
||||||
|
if ( state == NM_STATE_CONNECTED_LOCAL
|
||||||
|
|| state == NM_STATE_CONNECTED_SITE
|
||||||
|
|| state == NM_STATE_CONNECTED_GLOBAL)
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -93,20 +106,24 @@ main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
gint t_secs = -1;
|
gint t_secs = -1;
|
||||||
gboolean exit_no_nm = FALSE;
|
gboolean exit_no_nm = FALSE;
|
||||||
gboolean quiet = FALSE;
|
gboolean wait_startup = FALSE;
|
||||||
Timeout timeout;
|
Timeout timeout;
|
||||||
GOptionContext *opt_ctx = NULL;
|
GOptionContext *opt_ctx = NULL;
|
||||||
gboolean success;
|
gboolean success;
|
||||||
NMClient *client;
|
NMClient *client;
|
||||||
|
NMState state = NM_STATE_UNKNOWN;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
|
|
||||||
GOptionEntry options[] = {
|
GOptionEntry options[] = {
|
||||||
{"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), "<timeout>"},
|
{"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), "<timeout>"},
|
||||||
{"exit", 'x', 0, G_OPTION_ARG_NONE, &exit_no_nm, N_("Exit immediately if NetworkManager is not running"), NULL},
|
{"exit", 'x', 0, G_OPTION_ARG_NONE, &exit_no_nm, N_("Exit immediately if NetworkManager is not running or connecting"), NULL},
|
||||||
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Don't print anything"), NULL},
|
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &timeout.quiet, N_("Don't print anything"), NULL},
|
||||||
|
{"wait-for-startup", 's', 0, G_OPTION_ARG_NONE, &wait_startup, N_("Wait for NetworkManager startup instead of a connection"), NULL},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
timeout.quiet = FALSE;
|
||||||
|
|
||||||
/* Set locale to be able to use environment variables */
|
/* Set locale to be able to use environment variables */
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
|
|
@ -152,13 +169,35 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
|
g_object_set_data (G_OBJECT (client), WAIT_STARTUP_TAG, GUINT_TO_POINTER (wait_startup));
|
||||||
|
state = nm_client_get_state (client);
|
||||||
if (!nm_client_get_manager_running (client)) {
|
if (!nm_client_get_manager_running (client)) {
|
||||||
if (exit_no_nm)
|
if (exit_no_nm) {
|
||||||
|
g_object_unref (client);
|
||||||
return 1;
|
return 1;
|
||||||
} else if (!nm_client_get_startup (client))
|
}
|
||||||
return 0;
|
} else if (wait_startup) {
|
||||||
if (!timeout.value)
|
if (!nm_client_get_startup (client)) {
|
||||||
|
g_object_unref (client);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( state == NM_STATE_CONNECTED_LOCAL
|
||||||
|
|| state == NM_STATE_CONNECTED_SITE
|
||||||
|
|| state == NM_STATE_CONNECTED_GLOBAL) {
|
||||||
|
g_object_unref (client);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exit_no_nm && (state != NM_STATE_CONNECTING)) {
|
||||||
|
g_object_unref (client);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timeout.value) {
|
||||||
|
g_object_unref (client);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
|
timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
|
||||||
g_timeout_add_seconds (1, handle_timeout, &timeout);
|
g_timeout_add_seconds (1, handle_timeout, &timeout);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue