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 10 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
 	int rc;
166
 	int rc;
167
 
167
 
168
 	/* If no response has been received, notify the callback function */
168
 	/* If no response has been received, notify the callback function */
169
-	if ( pinger->pending )
169
+	if ( pinger->pending && pinger->callback )
170
 		pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
170
 		pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
171
 
171
 
172
 	/* Check for termination */
172
 	/* Check for termination */
263
 	/* Discard I/O buffer */
263
 	/* Discard I/O buffer */
264
 	free_iob ( iobuf );
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
 	/* Terminate if applicable */
270
 	/* Terminate if applicable */
270
 	if ( terminate )
271
 	if ( terminate )
301
  * @v timeout		Timeout (in ticks)
302
  * @v timeout		Timeout (in ticks)
302
  * @v len		Payload length
303
  * @v len		Payload length
303
  * @v count		Number of packets to send (or zero for no limit)
304
  * @v count		Number of packets to send (or zero for no limit)
305
+ * @v callback		Callback function (or NULL)
304
  * @ret rc		Return status code
306
  * @ret rc		Return status code
305
  */
307
  */
306
 int create_pinger ( struct interface *job, const char *hostname,
308
 int create_pinger ( struct interface *job, const char *hostname,

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

50
 	unsigned long timeout;
50
 	unsigned long timeout;
51
 	/** Number of packets to send (or zero for no limit) */
51
 	/** Number of packets to send (or zero for no limit) */
52
 	unsigned int count;
52
 	unsigned int count;
53
+	/** Inhibit output */
54
+	int quiet;
53
 };
55
 };
54
 
56
 
55
 /** "ping" option list */
57
 /** "ping" option list */
60
 		      struct ping_options, timeout, parse_timeout ),
62
 		      struct ping_options, timeout, parse_timeout ),
61
 	OPTION_DESC ( "count", 'c', required_argument,
63
 	OPTION_DESC ( "count", 'c', required_argument,
62
 		      struct ping_options, count, parse_integer ),
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
 /** "ping" command descriptor */
69
 /** "ping" command descriptor */
92
 
96
 
93
 	/* Ping */
97
 	/* Ping */
94
 	if ( ( rc = ping ( hostname, opts.timeout, opts.size,
98
 	if ( ( rc = ping ( hostname, opts.timeout, opts.size,
95
-			   opts.count ) ) != 0 )
99
+			   opts.count, opts.quiet ) ) != 0 )
96
 		return rc;
100
 		return rc;
97
 
101
 
98
 	return 0;
102
 	return 0;

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

12
 #include <stdint.h>
12
 #include <stdint.h>
13
 
13
 
14
 extern int ping ( const char *hostname, unsigned long timeout, size_t len,
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
 #endif /* _USR_PINGMGMT_H */
17
 #endif /* _USR_PINGMGMT_H */

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

59
  * @v timeout		Timeout between pings, in ticks
59
  * @v timeout		Timeout between pings, in ticks
60
  * @v len		Payload length
60
  * @v len		Payload length
61
  * @v count		Number of packets to send (or zero for no limit)
61
  * @v count		Number of packets to send (or zero for no limit)
62
+ * @v quiet		Inhibit output
62
  * @ret rc		Return status code
63
  * @ret rc		Return status code
63
  */
64
  */
64
 int ping ( const char *hostname, unsigned long timeout, size_t len,
65
 int ping ( const char *hostname, unsigned long timeout, size_t len,
65
-	   unsigned int count ) {
66
+	   unsigned int count, int quiet ) {
66
 	int rc;
67
 	int rc;
67
 
68
 
68
 	/* Create pinger */
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
 		printf ( "Could not start ping: %s\n", strerror ( rc ) );
72
 		printf ( "Could not start ping: %s\n", strerror ( rc ) );
72
 		return rc;
73
 		return rc;
73
 	}
74
 	}
74
 
75
 
75
 	/* Wait for ping to complete */
76
 	/* Wait for ping to complete */
76
 	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
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
 		return rc;
80
 		return rc;
79
 	}
81
 	}
80
 
82
 

Loading…
Cancel
Save