Re: [PATCH] change nm-online behavior somewhat
- From: Bill Nottingham <notting redhat com>
- To: networkmanager-list gnome org
- Subject: Re: [PATCH] change nm-online behavior somewhat
- Date: Thu, 10 Apr 2008 11:47:55 -0400
Bill Nottingham (notting redhat com) said:
> The attached:
> - adds some usage()
> - lets the user specify '0' for no timeout, if they're crazy
> - changes it to only wait if NM is in the CONNECTING state,
> as opposed to waiting for something to happen
>
> Opinions? We can conditionalize the latter behavior on a commandline
> option if people would like.
And... the diff.
Bill
diff -up NetworkManager-0.7.0/test/nm-online.c.foo NetworkManager-0.7.0/test/nm-online.c
--- NetworkManager-0.7.0/test/nm-online.c.foo 2008-04-10 11:39:25.000000000 -0400
+++ NetworkManager-0.7.0/test/nm-online.c 2008-04-10 11:39:30.000000000 -0400
@@ -13,6 +13,7 @@
#define DBUS_API_SUBJECT_TO_CHANGE 1
#define PROGRESS_STEPS 15
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -39,7 +40,7 @@ static DBusHandlerResult dbus_filter (DB
exit (0);
}
-static gboolean check_online (DBusConnection *connection)
+static NMState check_online (DBusConnection *connection)
{
DBusMessage *message, *reply;
DBusError error;
@@ -55,16 +56,13 @@ static gboolean check_online (DBusConnec
-1, &error);
dbus_message_unref (message);
if (!reply)
- return FALSE;
+ return NM_STATE_UNKNOWN;
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &state,
DBUS_TYPE_INVALID))
exit (2);
- if (state != NM_STATE_CONNECTED)
- return FALSE;
-
- return TRUE;
+ return state;
}
static gboolean handle_timeout (gpointer data)
@@ -86,19 +84,31 @@ static gboolean handle_timeout (gpointer
return TRUE;
}
+static void usage ()
+{
+ fprintf(stderr, "nm-online: Waits for a successfull connection in NetworkManager\n\n");
+ fprintf(stderr, "Usage: nm-online [<timeout in seconds>]\n");
+}
+
int main (int argc, char *argv[])
{
DBusConnection *connection;
DBusError error;
GMainLoop *loop;
+ NMState state;
Timeout timeout;
timeout.value = 30;
if (argc == 2) {
+ if (!isdigit(*argv[1])) {
+ usage();
+ }
timeout.value = (int) strtol (argv[1], NULL, 10);
- if (timeout.value <= 0 || timeout.value > 3600)
+ if (timeout.value < 0 || timeout.value > 3600) {
+ usage();
return 2;
+ }
}
g_type_init ();
@@ -126,8 +136,11 @@ int main (int argc, char *argv[])
}
/* Check after we setup the filter to ensure that we cannot race. */
- if (check_online (connection))
+ state = check_online (connection);
+ if (state == NM_STATE_CONNECTED)
return 0;
+ if (state != NM_STATE_CONNECTING)
+ return 1;
if (timeout.value) {
timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]