On Mon, 28 Dec 2015 18:47:51 -0500 Nathaniel W Filardo <n...@cs.jhu.edu> wrote:
> Hallo netdev@, > > I had occasion to want to programmatically wait for an interface to become > available from within a shell script, but found there to be no off-the-shelf > tool for such a thing. Could this patch be considered for inclusion as part > of iproute2? It adds an "ip wait link" subcommand ("link" required in case > someone wants to add things like "ip wait addr" or somesuch) based quite > heavily on the ipmonitor.c file. > > For example, one might "ip wait link dev eth0 up" to wait for an interface > of that name to appear (specifically, for a RTM_NEWLINK message). "ip wait > link dev eth0 down" will wait for it to go away (RTM_DELLINK). > > This should be checkpatch clean, but please let me know if I missed > something. > > Cheers, > --nwf; > Thank you for your contribution, it looks useful. Could you also update the man page? > +static int accept_msg(const struct sockaddr_nl *who, > + struct rtnl_ctrl_data *ctrl, > + struct nlmsghdr *n, void *arg) > +{ > + int done = 0; > + > + if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) { > + if (wait_for == n->nlmsg_type > + && wait_for == RTM_DELLINK > + && ll_name_to_index(wait_dev) != 0) > + done = 1; > + > + ll_remember_index(who, n, NULL); > + if (verbose) > + print_linkinfo(who, n, stdout); > + > + if (wait_for == n->nlmsg_type > + && wait_for == RTM_NEWLINK > + && ll_name_to_index(wait_dev) != 0) > + done = 1; > + } > + if (done) { > + fflush(stdout); > + exit(0); I don't think you need explicit fflush here. Stdio does it automatically. Which means all the conditional(done) can be removed. Have you considered how wait could be used with --batch option to write a script?
pgpPz1yuXOjv7.pgp
Description: OpenPGP digital signature