diff options
author | Michael Brown | 2014-10-23 17:52:08 +0200 |
---|---|---|
committer | Michael Brown | 2014-10-23 17:52:08 +0200 |
commit | dea6a6c1a07462890dc8bed4d048febdd13a2a3a (patch) | |
tree | 9bee6d8e8215e0c73ea4a5f4f38b77a8c0bf5d74 /src | |
parent | [ping] Allow termination after a specified number of packets (diff) | |
download | ipxe-dea6a6c1a07462890dc8bed4d048febdd13a2a3a.tar.gz ipxe-dea6a6c1a07462890dc8bed4d048febdd13a2a3a.tar.xz ipxe-dea6a6c1a07462890dc8bed4d048febdd13a2a3a.zip |
[ping] Allow "ping" command output to be inhibited
Originally-implemented-by: Cedric Levasseur <cyr-ius@ipocus.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/pinger.c | 8 | ||||
-rw-r--r-- | src/hci/commands/ping_cmd.c | 6 | ||||
-rw-r--r-- | src/include/usr/pingmgmt.h | 2 | ||||
-rw-r--r-- | src/usr/pingmgmt.c | 10 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/core/pinger.c b/src/core/pinger.c index 558cfb49..31ea2ce1 100644 --- a/src/core/pinger.c +++ b/src/core/pinger.c @@ -166,7 +166,7 @@ static void pinger_expired ( struct retry_timer *timer, int over __unused ) { int rc; /* If no response has been received, notify the callback function */ - if ( pinger->pending ) + if ( pinger->pending && pinger->callback ) pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT ); /* Check for termination */ @@ -263,8 +263,9 @@ static int pinger_deliver ( struct pinger *pinger, struct io_buffer *iobuf, /* Discard I/O buffer */ free_iob ( iobuf ); - /* Notify callback function */ - pinger->callback ( meta->src, sequence, len, rc ); + /* Notify callback function, if applicable */ + if ( pinger->callback ) + pinger->callback ( meta->src, sequence, len, rc ); /* Terminate if applicable */ if ( terminate ) @@ -301,6 +302,7 @@ static struct interface_descriptor pinger_job_desc = * @v timeout Timeout (in ticks) * @v len Payload length * @v count Number of packets to send (or zero for no limit) + * @v callback Callback function (or NULL) * @ret rc Return status code */ int create_pinger ( struct interface *job, const char *hostname, diff --git a/src/hci/commands/ping_cmd.c b/src/hci/commands/ping_cmd.c index 92c5443a..34807696 100644 --- a/src/hci/commands/ping_cmd.c +++ b/src/hci/commands/ping_cmd.c @@ -50,6 +50,8 @@ struct ping_options { unsigned long timeout; /** Number of packets to send (or zero for no limit) */ unsigned int count; + /** Inhibit output */ + int quiet; }; /** "ping" option list */ @@ -60,6 +62,8 @@ static struct option_descriptor ping_opts[] = { struct ping_options, timeout, parse_timeout ), OPTION_DESC ( "count", 'c', required_argument, struct ping_options, count, parse_integer ), + OPTION_DESC ( "quiet", 'q', no_argument, + struct ping_options, quiet, parse_flag ), }; /** "ping" command descriptor */ @@ -92,7 +96,7 @@ static int ping_exec ( int argc, char **argv ) { /* Ping */ if ( ( rc = ping ( hostname, opts.timeout, opts.size, - opts.count ) ) != 0 ) + opts.count, opts.quiet ) ) != 0 ) return rc; return 0; diff --git a/src/include/usr/pingmgmt.h b/src/include/usr/pingmgmt.h index 8bded384..d4c2d6cd 100644 --- a/src/include/usr/pingmgmt.h +++ b/src/include/usr/pingmgmt.h @@ -12,6 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> extern int ping ( const char *hostname, unsigned long timeout, size_t len, - unsigned int count ); + unsigned int count, int quiet ); #endif /* _USR_PINGMGMT_H */ diff --git a/src/usr/pingmgmt.c b/src/usr/pingmgmt.c index f8366f26..16b3ec99 100644 --- a/src/usr/pingmgmt.c +++ b/src/usr/pingmgmt.c @@ -59,22 +59,24 @@ static void ping_callback ( struct sockaddr *peer, unsigned int sequence, * @v timeout Timeout between pings, in ticks * @v len Payload length * @v count Number of packets to send (or zero for no limit) + * @v quiet Inhibit output * @ret rc Return status code */ int ping ( const char *hostname, unsigned long timeout, size_t len, - unsigned int count ) { + unsigned int count, int quiet ) { int rc; /* Create pinger */ - if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, - count, ping_callback ) ) != 0 ) { + if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count, + ( quiet ? NULL : ping_callback ) ) ) != 0 ){ printf ( "Could not start ping: %s\n", strerror ( rc ) ); return rc; } /* Wait for ping to complete */ if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) { - printf ( "Finished: %s\n", strerror ( rc ) ); + if ( ! quiet ) + printf ( "Finished: %s\n", strerror ( rc ) ); return rc; } |