From: Stephen Hemminger <stephen@networkplumber.org>
To: Nathaniel W Filardo <nwf@cs.jhu.edu>
Cc: netdev@vger.kernel.org
Subject: Re: New "ip wait" subcommand for iproute2
Date: Wed, 30 Dec 2015 12:31:41 -0800 [thread overview]
Message-ID: <20151230123141.3769ecbb@xeon-e3> (raw)
In-Reply-To: <20151228234751.GH47562@gradx.cs.jhu.edu>
[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]
On Mon, 28 Dec 2015 18:47:51 -0500
Nathaniel W Filardo <nwf@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?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2015-12-30 20:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-28 23:47 New "ip wait" subcommand for iproute2 Nathaniel W Filardo
2015-12-30 20:31 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151230123141.3769ecbb@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.org \
--cc=nwf@cs.jhu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.