Browse Source

[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>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
dea6a6c1a0
4 changed files with 17 additions and 9 deletions
  1. 5
    3
      src/core/pinger.c
  2. 5
    1
      src/hci/commands/ping_cmd.c
  3. 1
    1
      src/include/usr/pingmgmt.h
  4. 6
    4
      src/usr/pingmgmt.c

+ 5
- 3
src/core/pinger.c View File

@@ -166,7 +166,7 @@ static void pinger_expired ( struct retry_timer *timer, int over __unused ) {
166 166
 	int rc;
167 167
 
168 168
 	/* If no response has been received, notify the callback function */
169
-	if ( pinger->pending )
169
+	if ( pinger->pending && pinger->callback )
170 170
 		pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
171 171
 
172 172
 	/* Check for termination */
@@ -263,8 +263,9 @@ static int pinger_deliver ( struct pinger *pinger, struct io_buffer *iobuf,
263 263
 	/* Discard I/O buffer */
264 264
 	free_iob ( iobuf );
265 265
 
266
-	/* Notify callback function */
267
-	pinger->callback ( meta->src, sequence, len, rc );
266
+	/* Notify callback function, if applicable */
267
+	if ( pinger->callback )
268
+		pinger->callback ( meta->src, sequence, len, rc );
268 269
 
269 270
 	/* Terminate if applicable */
270 271
 	if ( terminate )
@@ -301,6 +302,7 @@ static struct interface_descriptor pinger_job_desc =
301 302
  * @v timeout		Timeout (in ticks)
302 303
  * @v len		Payload length
303 304
  * @v count		Number of packets to send (or zero for no limit)
305
+ * @v callback		Callback function (or NULL)
304 306
  * @ret rc		Return status code
305 307
  */
306 308
 int create_pinger ( struct interface *job, const char *hostname,

+ 5
- 1
src/hci/commands/ping_cmd.c View File

@@ -50,6 +50,8 @@ struct ping_options {
50 50
 	unsigned long timeout;
51 51
 	/** Number of packets to send (or zero for no limit) */
52 52
 	unsigned int count;
53
+	/** Inhibit output */
54
+	int quiet;
53 55
 };
54 56
 
55 57
 /** "ping" option list */
@@ -60,6 +62,8 @@ static struct option_descriptor ping_opts[] = {
60 62
 		      struct ping_options, timeout, parse_timeout ),
61 63
 	OPTION_DESC ( "count", 'c', required_argument,
62 64
 		      struct ping_options, count, parse_integer ),
65
+	OPTION_DESC ( "quiet", 'q', no_argument,
66
+		      struct ping_options, quiet, parse_flag ),
63 67
 };
64 68
 
65 69
 /** "ping" command descriptor */
@@ -92,7 +96,7 @@ static int ping_exec ( int argc, char **argv ) {
92 96
 
93 97
 	/* Ping */
94 98
 	if ( ( rc = ping ( hostname, opts.timeout, opts.size,
95
-			   opts.count ) ) != 0 )
99
+			   opts.count, opts.quiet ) ) != 0 )
96 100
 		return rc;
97 101
 
98 102
 	return 0;

+ 1
- 1
src/include/usr/pingmgmt.h View File

@@ -12,6 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 #include <stdint.h>
13 13
 
14 14
 extern int ping ( const char *hostname, unsigned long timeout, size_t len,
15
-		  unsigned int count );
15
+		  unsigned int count, int quiet );
16 16
 
17 17
 #endif /* _USR_PINGMGMT_H */

+ 6
- 4
src/usr/pingmgmt.c View File

@@ -59,22 +59,24 @@ static void ping_callback ( struct sockaddr *peer, unsigned int sequence,
59 59
  * @v timeout		Timeout between pings, in ticks
60 60
  * @v len		Payload length
61 61
  * @v count		Number of packets to send (or zero for no limit)
62
+ * @v quiet		Inhibit output
62 63
  * @ret rc		Return status code
63 64
  */
64 65
 int ping ( const char *hostname, unsigned long timeout, size_t len,
65
-	   unsigned int count ) {
66
+	   unsigned int count, int quiet ) {
66 67
 	int rc;
67 68
 
68 69
 	/* Create pinger */
69
-	if ( ( rc = create_pinger ( &monojob, hostname, timeout, len,
70
-				    count, ping_callback ) ) != 0 ) {
70
+	if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count,
71
+				    ( quiet ? NULL : ping_callback ) ) ) != 0 ){
71 72
 		printf ( "Could not start ping: %s\n", strerror ( rc ) );
72 73
 		return rc;
73 74
 	}
74 75
 
75 76
 	/* Wait for ping to complete */
76 77
 	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
77
-		printf ( "Finished: %s\n", strerror ( rc ) );
78
+		if ( ! quiet )
79
+			printf ( "Finished: %s\n", strerror ( rc ) );
78 80
 		return rc;
79 81
 	}
80 82
 

Loading…
Cancel
Save