Skip to content

Commit

Permalink
client: Set WAIT_FOR_INTERFACES from compat
Browse files Browse the repository at this point in the history
  • Loading branch information
wipawel committed Jun 6, 2014
1 parent 3ec3165 commit e663e6f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
24 changes: 9 additions & 15 deletions client/ifup.c
Expand Up @@ -226,8 +226,7 @@ ni_do_ifup(int argc, char **argv)
unsigned int i;
ni_fsm_t *fsm;
int c, status = NI_WICKED_RC_USAGE;
const char *ptr;
long timeout = 0;
unsigned int timeout = 0;

fsm = ni_fsm_new();
ni_assert(fsm);
Expand All @@ -241,17 +240,6 @@ ni_do_ifup(int argc, char **argv)
ifmatch.allow_persistent = TRUE;
ifmatch.require_config = TRUE;

/*
* Client waits for WAIT_FOR_INTERFACES/3 miliseconds
* in order to let all ifworkers reach device-up state.
*/
if ((ptr = getenv("WAIT_FOR_INTERFACES"))) {
unsigned int sec;

if (ni_parse_uint(ptr, &sec, 10) == 0)
timeout = (sec * 1000)/3;
}

optind = 1;
while ((c = getopt_long(argc, argv, "", ifup_options, NULL)) != EOF) {
switch (c) {
Expand Down Expand Up @@ -378,6 +366,12 @@ ni_do_ifup(int argc, char **argv)
goto cleanup;
}

/* Client waits for device-up events for WAIT_FOR_INTERFACES / 3 */
if (timeout)
ni_wait_for_interfaces = timeout; /* One set by user */
else
ni_wait_for_interfaces *= (1000/3); /* One read from compat */

if (ni_fsm_build_hierarchy(fsm) < 0) {
ni_error("ifup: unable to build device hierarchy");
/* Severe error we always explicitly return */
Expand Down Expand Up @@ -416,13 +410,13 @@ ni_do_ifup(int argc, char **argv)
ni_info("%s: configuration applied to nanny", w->name);
}

ni_timer_register(timeout, ni_ifup_timer_expires, &status);
ni_timer_register(ni_wait_for_interfaces, ni_ifup_timer_expires, &status);
while (status == NI_WICKED_RC_SUCCESS) {
/* status is already success */
if (0 == ifmarked.count)
break;

if (ni_socket_wait(timeout) != 0)
if (ni_socket_wait(ni_wait_for_interfaces) != 0)
ni_fatal("ni_socket_wait failed");

ni_timer_next_timeout();
Expand Down
2 changes: 2 additions & 0 deletions client/ifup.h
Expand Up @@ -27,6 +27,8 @@
#ifndef __WICKED_CLIENT_IFUP_H__
#define __WICKED_CLIENT_IFUP_H__

extern unsigned int ni_wait_for_interfaces;

extern int ni_do_ifup(int argc, char **argv);

#endif /* __WICKED_CLIENT_IFUP_H__ */
2 changes: 2 additions & 0 deletions client/main.c
Expand Up @@ -98,6 +98,8 @@ char * opt_global_rootdir;
ni_bool_t opt_systemd;
ni_bool_t opt_transient;

unsigned int ni_wait_for_interfaces;

static int do_show_xml(int, char **);
static int do_show_config(int, char **, const char *);
extern int do_nanny(int, char **);
Expand Down
1 change: 1 addition & 0 deletions client/read-config.c
Expand Up @@ -514,6 +514,7 @@ ni_ifconfig_read_compat_suse(xml_document_array_t *array, const char *type,
if ((rv = __ni_suse_get_ifconfig(root, path, &conf))) {
ni_compat_generate_interfaces(array, &conf, check_prio, raw);
}

ni_compat_ifconfig_destroy(&conf);
return rv;
}
Expand Down
4 changes: 3 additions & 1 deletion client/suse/compat-suse.c
Expand Up @@ -262,9 +262,11 @@ __ni_suse_get_ifconfig(const char *root, const char *path, ni_compat_ifconfig_t
}

if (__ni_suse_config_defaults) {
extern unsigned int ni_wait_for_interfaces;

ni_sysconfig_get_integer(__ni_suse_config_defaults,
"WAIT_FOR_INTERFACES",
&result->timeout);
&ni_wait_for_interfaces);
}
} else
if (ni_file_exists(pathname)) {
Expand Down

0 comments on commit e663e6f

Please sign in to comment.