Commit aac770c1 authored by Dan Williams's avatar Dan Williams
Browse files

2005-04-27 Dan Williams <dcbw@redhat.com>

	Patch from Peter Jones:
	* Remove usage of varargs to fix crashes on PPC (RH #154336)

	Patch from Bill Moss:
	* src/NetworkManagerSystem.c
		- Fix checking of return value from ioctl()


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@592 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 0219e174
2005-04-27 Dan Williams <dcbw@redhat.com>
Patch from Peter Jones:
* Remove usage of varargs to fix crashes on PPC (RH #154336)
Patch from Bill Moss:
* src/NetworkManagerSystem.c
- Fix checking of return value from ioctl()
2005-04-27 Dan Williams <dcbw@redhat.com>
* Fix choosing of wireless networks and "Other wireless network..." from the applet
......
......@@ -258,6 +258,7 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev,
{
NMDevice *dev;
GError *error = NULL;
nm_completion_args args;
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (strlen (iface) > 0, NULL);
......@@ -391,11 +392,13 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev,
}
/* Block until our device thread has actually had a chance to start. */
args[0] = &dev->worker_started;
args[1] = "nm_device_new(): waiting for device's worker thread to start";
args[2] = (void *)LOG_INFO;
args[3] = 0;
nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY,
G_USEC_PER_SEC / 20, nm_completion_boolean_test, NULL,
&dev->worker_started,
"nm_device_new(): waiting for device's worker thread to start",
LOG_INFO, 0);
G_USEC_PER_SEC / 20, nm_completion_boolean_test, NULL, args);
nm_info ("nm_device_new(): device's worker thread started, continuing.");
return (dev);
......@@ -1564,16 +1567,13 @@ gboolean nm_device_is_up (NMDevice *dev)
}
/* I really wish nm_v_wait_for_completion_or_timeout could translate these
* to first class args instead of a va_list, so these helpers could be nice
* and _tiny_.
*
* ... and we can probably do that with __builtin_apply(), or libffi,
* but that's kindof cheating. */
gboolean nm_completion_device_is_up_test(int tries, va_list args)
* to first class args instead of a all this void * arg stuff, so these
* helpers could be nice and _tiny_. */
gboolean nm_completion_device_is_up_test(int tries, nm_completion_args args)
{
NMDevice *dev = va_arg(args, NMDevice *);
gboolean *err = va_arg(args, gboolean *);
gboolean cancelable = va_arg(args, gboolean);
NMDevice *dev = args[0];
gboolean *err = args[1];
gboolean cancelable = (gboolean)args[2];
g_return_val_if_fail (dev != NULL, TRUE);
g_return_val_if_fail (err != NULL, TRUE);
......@@ -1598,13 +1598,17 @@ void nm_device_bring_up (NMDevice *dev)
gboolean nm_device_bring_up_wait (NMDevice *dev, gboolean cancelable)
{
gboolean err = FALSE;
nm_completion_args args;
g_return_val_if_fail (dev != NULL, TRUE);
nm_device_bring_up (dev);
args[0] = dev;
args[1] = &err;
args[2] = (void *)cancelable;
nm_wait_for_completion(400, G_USEC_PER_SEC / 200, NULL,
nm_completion_device_is_up_test, dev,
&err, cancelable);
nm_completion_device_is_up_test, args);
if (err)
nm_info ("failed to bring device up");
return err;
......@@ -1617,11 +1621,11 @@ void nm_device_bring_down (NMDevice *dev)
nm_device_set_up_down (dev, FALSE);
}
gboolean nm_completion_device_is_down_test (int tries, va_list args)
gboolean nm_completion_device_is_down_test (int tries, nm_completion_args args)
{
NMDevice *dev = va_arg(args, NMDevice *);
gboolean *err = va_arg(args, gboolean *);
gboolean cancelable = va_arg(args, gboolean);
NMDevice *dev = args[0];
gboolean *err = args[1];
gboolean cancelable = (gboolean)args[2];
g_return_val_if_fail (dev != NULL, TRUE);
g_return_val_if_fail (err != NULL, TRUE);
......@@ -1639,13 +1643,17 @@ gboolean nm_completion_device_is_down_test (int tries, va_list args)
gboolean nm_device_bring_down_wait (NMDevice *dev, gboolean cancelable)
{
gboolean err = FALSE;
nm_completion_args args;
g_return_val_if_fail (dev != NULL, TRUE);
nm_device_bring_down (dev);
args[0] = dev;
args[1] = &err;
args[2] = (void *)cancelable;
nm_wait_for_completion(400, G_USEC_PER_SEC / 200, NULL,
nm_completion_device_is_down_test, dev,
&err, cancelable);
nm_completion_device_is_down_test, args);
if (err)
nm_info ("failed to bring device down");
return err;
......@@ -1850,13 +1858,13 @@ static gboolean nm_device_activation_handle_cancel (NMDevice *dev)
}
static gboolean nm_dwwfl_test (int tries, va_list args)
static gboolean nm_dwwfl_test (int tries, nm_completion_args args)
{
NMDevice *dev = va_arg (args, NMDevice *);
guint *assoc_count = va_arg (args, guint *);
double *last_freq = va_arg (args, double *);
char *essid = va_arg (args, char *);
int required = va_arg (args, int);
NMDevice *dev = args[0];
guint *assoc_count = args[1];
double *last_freq = args[2];
char *essid = args[3];
int required = (int)args[4];
double cur_freq = nm_device_get_frequency (dev);
gboolean assoc = nm_device_wireless_is_associated (dev);
......@@ -1904,6 +1912,7 @@ static gboolean nm_device_wireless_wait_for_link (NMDevice *dev, const char *ess
double last_freq = 0;
guint assoc_count = 0;
struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
nm_completion_args args;
/* we want to sleep for a very short amount of time, to minimize
* hysteresis on the boundaries of our required time. But we
......@@ -1929,9 +1938,13 @@ static gboolean nm_device_wireless_wait_for_link (NMDevice *dev, const char *ess
* associated, the driver stops scanning. To detect that, we look
* for the essid and frequency to remain constant for 3 seconds.
* When it remains constant, we assume it's a real link. */
args[0] = dev;
args[1] = &assoc;
args[2] = &last_freq;
args[3] = (void *)essid;
args[4] = (void *)(required_tries * 2);
nm_wait_for_timeout (&timeout, G_USEC_PER_SEC / delay,
nm_dwwfl_test, nm_dwwfl_test, dev, &assoc,
&last_freq, essid, required_tries * 2);
nm_dwwfl_test, nm_dwwfl_test, args);
/* If we've had a reasonable association count, we say we have a link */
if (assoc > required_tries)
......@@ -1940,10 +1953,10 @@ static gboolean nm_device_wireless_wait_for_link (NMDevice *dev, const char *ess
}
static gboolean nm_device_link_test(int tries, va_list args)
static gboolean nm_device_link_test(int tries, nm_completion_args args)
{
NMDevice *dev = va_arg(args, NMDevice *);
gboolean *err = va_arg(args, gboolean *);
NMDevice *dev = args[0];
gboolean *err = args[1];
g_return_val_if_fail (dev != NULL, TRUE);
g_return_val_if_fail (err != NULL, TRUE);
......@@ -1962,10 +1975,13 @@ static gboolean nm_device_is_up_and_associated_wait (NMDevice *dev, int timeout,
gboolean err;
const gint delay = (G_USEC_PER_SEC * nm_device_get_association_pause_value (dev)) / interval;
const gint max_cycles = timeout * interval;
nm_completion_args args;
g_return_val_if_fail (dev != NULL, TRUE);
nm_wait_for_completion (max_cycles, delay, NULL, nm_device_link_test, dev, &err);
args[0] = dev;
args[1] = &err;
nm_wait_for_completion (max_cycles, delay, NULL, nm_device_link_test, args);
return !err;
}
......@@ -2231,11 +2247,11 @@ void invalidate_ap (NMDevice *dev, NMAccessPoint *ap)
/* this gets called without the scan mutex held */
static gboolean nm_wa_test (int tries, va_list args)
static gboolean nm_wa_test (int tries, nm_completion_args args)
{
NMDevice *dev = va_arg (args, NMDevice *);
NMAccessPoint **best_ap = va_arg (args, NMAccessPoint **);
gboolean *err = va_arg (args, gboolean *);
NMDevice *dev = args[0];
NMAccessPoint **best_ap = args[1];
gboolean *err = args[2];
g_return_val_if_fail (dev != NULL, TRUE);
g_return_val_if_fail (best_ap != NULL, TRUE);
......@@ -2283,10 +2299,10 @@ static gboolean nm_wa_test (int tries, va_list args)
}
static gboolean nm_dukr_test (int tries, va_list args)
static gboolean nm_dukr_test (int tries, nm_completion_args args)
{
NMDevice *dev = va_arg (args, NMDevice *);
gboolean *err = va_arg (args, gboolean *);
NMDevice *dev = args[0];
gboolean *err = args[1];
g_return_val_if_fail (dev != NULL, TRUE);
g_return_val_if_fail (err != NULL, TRUE);
......@@ -2321,6 +2337,7 @@ static gboolean nm_device_activate_wireless (NMDevice *dev)
gboolean need_key = FALSE;
gboolean found_ap = FALSE;
gboolean err = FALSE;
nm_completion_args args;
g_return_val_if_fail (dev != NULL, FALSE);
g_return_val_if_fail (dev->app_data != NULL, FALSE);
......@@ -2346,7 +2363,11 @@ get_ap:
nm_device_set_now_scanning (dev, TRUE);
/* Get an access point to connect to */
nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY, G_USEC_PER_SEC / 50, nm_wa_test, NULL, dev, &best_ap, &err);
args[0] = dev;
args[1] = &best_ap;
args[2] = &err;
nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY, G_USEC_PER_SEC / 50,
nm_wa_test, NULL, args);
if (err)
{
/* Wierd as it may seem, we lock here to balance the unlock in "out:" */
......@@ -2397,8 +2418,11 @@ need_key:
/* Wait for the key to come back */
nm_debug ("Activation (%s/wireless): asking for user key.", nm_device_get_iface (dev));
nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY, G_USEC_PER_SEC / 20,
nm_dukr_test, nm_dukr_test, dev, &err);
args[0] = dev;
args[1] = &err;
nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY,
G_USEC_PER_SEC / 20, nm_dukr_test, nm_dukr_test, args);
nm_debug ("Activation (%s/wireless): user key received.", nm_device_get_iface (dev));
/* Done waiting, grab lock again */
......@@ -2706,9 +2730,9 @@ gboolean nm_device_activation_should_cancel (NMDevice *dev)
}
static gboolean nm_ac_test (int tries, va_list args)
static gboolean nm_ac_test (int tries, nm_completion_args args)
{
NMDevice *dev = va_arg (args, NMDevice *);
NMDevice *dev = args[0];
g_return_val_if_fail (dev != NULL, TRUE);
......@@ -2743,6 +2767,8 @@ static gboolean nm_ac_test (int tries, va_list args)
*/
void nm_device_activation_cancel (NMDevice *dev)
{
nm_completion_args args;
g_return_if_fail (dev != NULL);
if (nm_device_is_activating (dev))
......@@ -2754,8 +2780,9 @@ void nm_device_activation_cancel (NMDevice *dev)
* The other problem with waiting here is that we hold up dbus traffic
* that we should respond to.
*/
args[0] = dev;
nm_wait_for_completion(NM_COMPLETION_TRIES_INFINITY,
G_USEC_PER_SEC / 20, nm_ac_test, NULL, dev);
G_USEC_PER_SEC / 20, nm_ac_test, NULL, args);
nm_debug ("Activation (%s/wireless): cancelled.", nm_device_get_iface(dev));
nm_schedule_state_change_signal_broadcast (dev->app_data);
}
......@@ -3646,12 +3673,13 @@ static gboolean nm_device_wireless_process_scan_results (gpointer user_data)
}
static gboolean nm_completion_scan_has_results (int tries, va_list args)
static gboolean nm_completion_scan_has_results (int tries,
nm_completion_args args)
{
NMDevice *dev = va_arg (args, NMDevice *);
gboolean *err = va_arg (args, gboolean *);
NMSock *sk = va_arg (args, NMSock *);
NMWirelessScanResults *scan_results = va_arg (args, NMWirelessScanResults *);
NMDevice *dev = args[0];
gboolean *err = args[1];
NMSock *sk = args[2];
NMWirelessScanResults *scan_results = args[3];
int rc;
g_return_val_if_fail (dev != NULL, TRUE);
......@@ -3755,6 +3783,7 @@ static gboolean nm_device_wireless_scan (gpointer user_data)
double orig_freq = 0;
int orig_rate = 0;
const int max_wait = G_USEC_PER_SEC * nm_device_get_association_pause_value (dev) /2;
nm_completion_args args;
orig_mode = nm_device_get_mode (dev);
if (orig_mode == NETWORK_MODE_ADHOC)
......@@ -3770,9 +3799,13 @@ static gboolean nm_device_wireless_scan (gpointer user_data)
nm_device_set_frequency (dev, 0);
scan_results = g_malloc0 (sizeof (NMWirelessScanResults));
args[0] = dev;
args[1] = &err;
args[2] = sk;
args[3] = scan_results;
nm_wait_for_completion(max_wait, max_wait/20,
nm_completion_scan_has_results, NULL,
dev, &err, sk, scan_results);
nm_completion_scan_has_results, NULL, args);
nm_device_set_mode (dev, orig_mode);
/* Only set frequency if ad-hoc mode */
......
......@@ -277,19 +277,19 @@ gboolean nm_system_device_set_up_down_with_iface (NMDevice *dev, const char *ifa
/* Get flags already there */
memset (&ifr, 0, sizeof (struct ifreq));
memcpy (ifr.ifr_name, iface, strlen (iface));
if (!ioctl (nm_dev_sock_get_fd (sk), SIOCGIFFLAGS, &ifr))
if (ioctl (nm_dev_sock_get_fd (sk), SIOCGIFFLAGS, &ifr) == -1)
nm_warning ("nm_system_device_set_up_down_with_iface() could not get flags for device %s. errno = %d", iface, errno );
else
{
/* If the interface doesn't have those flags already, set them on it. */
if ((ifr.ifr_flags^flags) & IFF_UP)
{
ifr.ifr_flags &= ~IFF_UP;
ifr.ifr_flags |= IFF_UP & flags;
if (ioctl (nm_dev_sock_get_fd (sk), SIOCSIFFLAGS, &ifr))
if (ioctl (nm_dev_sock_get_fd (sk), SIOCSIFFLAGS, &ifr) == -1)
nm_warning ("nm_system_device_set_up_down_with_iface() could not bring device %s %s. errno = %d", iface, (up ? "up" : "down"), errno);
}
}
else
nm_warning ("nm_system_device_set_up_down_with_iface() could not get flags for device %s. errno = %d", iface, errno );
nm_dev_sock_close (sk);
return success;
......
......@@ -651,7 +651,7 @@ static void nm_v_wait_for_completion_or_timeout(
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
va_list args)
nm_completion_args args)
{
int try;
gboolean finished = FALSE;
......@@ -690,21 +690,19 @@ static void nm_v_wait_for_completion_or_timeout(
}
}
/* these should probably be moved to NetworkManagerUtils.h as macros
* since they don't do varargs stuff any more */
void nm_wait_for_completion_or_timeout(
const int max_tries,
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
nm_completion_args args)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(max_tries, max_time,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
action_func, args);
}
void nm_wait_for_completion(
......@@ -712,15 +710,11 @@ void nm_wait_for_completion(
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
nm_completion_args args)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(max_tries, NULL,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
action_func, args);
}
void nm_wait_for_timeout(
......@@ -728,24 +722,19 @@ void nm_wait_for_timeout(
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
nm_completion_args args)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(-1, max_time,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
nm_v_wait_for_completion_or_timeout(-1, max_time, interval_usecs,
test_func, action_func, args);
}
/* you can use these, but they're really just examples */
gboolean nm_completion_boolean_test(int tries, va_list args)
gboolean nm_completion_boolean_test(int tries, nm_completion_args args)
{
gboolean *condition = va_arg(args, gboolean *);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
gboolean *condition = (gboolean *)args[0];
char *message = (char *)args[1];
int log_level = (int)args[2];
int log_interval = (int)args[3];
g_return_val_if_fail (condition != NULL, TRUE);
......@@ -767,14 +756,16 @@ gboolean nm_completion_boolean_test(int tries, va_list args)
return FALSE;
}
gboolean nm_completion_boolean_function1_test(int tries, va_list args)
gboolean nm_completion_boolean_function1_test(int tries,
nm_completion_args args)
{
nm_completion_boolean_function_1 condition =
va_arg(args, nm_completion_boolean_function_1);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
u_int64_t arg0 = va_arg(args, unsigned long long);
nm_completion_boolean_function_1 condition = args[0];
char *message = args[1];
int log_level = (int)args[2];
int log_interval = (int)args[3];
u_int64_t arg0;
memcpy(&arg0, &args[4], sizeof (arg0));
g_return_val_if_fail (condition, TRUE);
......@@ -788,15 +779,17 @@ gboolean nm_completion_boolean_function1_test(int tries, va_list args)
return FALSE;
}
gboolean nm_completion_boolean_function2_test(int tries, va_list args)
gboolean nm_completion_boolean_function2_test(int tries,
nm_completion_args args)
{
nm_completion_boolean_function_2 condition =
va_arg(args, nm_completion_boolean_function_2);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
u_int64_t arg0 = va_arg(args, unsigned long long);
u_int64_t arg1 = va_arg(args, unsigned long long);
nm_completion_boolean_function_2 condition = args[0];
char *message = args[1];
int log_level = (int)args[2];
int log_interval = (int)args[3];
u_int64_t arg0, arg1;
memcpy(&arg0, &args[4], sizeof (arg0));
memcpy(&arg1, &args[4]+sizeof (arg0), sizeof (arg1));
g_return_val_if_fail (condition, TRUE);
......
......@@ -66,7 +66,9 @@ NMDriverSupportLevel nm_get_driver_support_level (LibHalContext *ctx, NMDevice
#define NM_COMPLETION_TRIES_INFINITY -1
typedef gboolean (*nm_completion_func)(int tries, va_list args);
typedef void * nm_completion_args[8];
typedef gboolean (*nm_completion_func)(int tries, nm_completion_args args);
typedef gboolean (*nm_completion_boolean_function_1)(u_int64_t arg);
typedef gboolean (*nm_completion_boolean_function_2)(
u_int64_t arg0, u_int64_t arg1);
......@@ -76,7 +78,7 @@ void nm_wait_for_completion(
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
nm_completion_args args);
void nm_wait_for_completion_or_timeout(
const int max_tries,
......@@ -84,18 +86,20 @@ void nm_wait_for_completion_or_timeout(
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
nm_completion_args args);
void nm_wait_for_timeout(
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
nm_completion_args args);
gboolean nm_completion_boolean_test(int tries, va_list args);
gboolean nm_completion_boolean_function1_test(int tries, va_list args);
gboolean nm_completion_boolean_function2_test(int tries, va_list args);
gboolean nm_completion_boolean_test(int tries, nm_completion_args args);
gboolean nm_completion_boolean_function1_test(int tries,
nm_completion_args args);
gboolean nm_completion_boolean_function2_test(int tries,
nm_completion_args args);
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment