Selaa lähdekoodia

[monojob] Add timeout parameter to monojob_wait()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 vuotta sitten
vanhempi
commit
d1be9f4acc
8 muutettua tiedostoa jossa 26 lisäystä ja 18 poistoa
  1. 18
    10
      src/core/monojob.c
  2. 1
    1
      src/include/ipxe/monojob.h
  3. 2
    2
      src/usr/dhcpmgmt.c
  4. 1
    1
      src/usr/fcmgmt.c
  5. 1
    1
      src/usr/imgmgmt.c
  6. 1
    1
      src/usr/imgtrust.c
  7. 1
    1
      src/usr/nslookup.c
  8. 1
    1
      src/usr/pingmgmt.c

+ 18
- 10
src/core/monojob.c Näytä tiedosto

@@ -55,12 +55,12 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
55 55
  * Wait for single foreground job to complete
56 56
  *
57 57
  * @v string		Job description to display, or NULL to be silent
58
+ * @v timeout		Timeout period, in ticks (0=indefinite)
58 59
  * @ret rc		Job final status code
59 60
  */
60
-int monojob_wait ( const char *string ) {
61
+int monojob_wait ( const char *string, unsigned long timeout ) {
61 62
 	struct job_progress progress;
62
-	int key;
63
-	int rc;
63
+	unsigned long start;
64 64
 	unsigned long last_keycheck;
65 65
 	unsigned long last_progress;
66 66
 	unsigned long now;
@@ -69,11 +69,13 @@ int monojob_wait ( const char *string ) {
69 69
 	unsigned long total;
70 70
 	unsigned int percentage;
71 71
 	int shown_percentage = 0;
72
+	int key;
73
+	int rc;
72 74
 
73 75
 	if ( string )
74 76
 		printf ( "%s...", string );
75 77
 	monojob_rc = -EINPROGRESS;
76
-	last_keycheck = last_progress = currticks();
78
+	last_keycheck = last_progress = start = currticks();
77 79
 	while ( monojob_rc == -EINPROGRESS ) {
78 80
 
79 81
 		/* Allow job to progress */
@@ -83,20 +85,25 @@ int monojob_wait ( const char *string ) {
83 85
 		/* Check for keypresses.  This can be time-consuming,
84 86
 		 * so check only once per clock tick.
85 87
 		 */
86
-		if ( now != last_keycheck ) {
88
+		elapsed = ( now - last_keycheck );
89
+		if ( elapsed ) {
87 90
 			if ( iskey() ) {
88 91
 				key = getchar();
89
-				switch ( key ) {
90
-				case CTRL_C:
91
-					monojob_close ( &monojob, -ECANCELED );
92
-					break;
93
-				default:
92
+				if ( key == CTRL_C ) {
93
+					monojob_rc = -ECANCELED;
94 94
 					break;
95 95
 				}
96 96
 			}
97 97
 			last_keycheck = now;
98 98
 		}
99 99
 
100
+		/* Check for timeout, if applicable */
101
+		elapsed = ( now - start );
102
+		if ( timeout && ( elapsed >= timeout ) ) {
103
+			monojob_rc = -ETIMEDOUT;
104
+			break;
105
+		}
106
+
100 107
 		/* Display progress, if applicable */
101 108
 		elapsed = ( now - last_progress );
102 109
 		if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
@@ -118,6 +125,7 @@ int monojob_wait ( const char *string ) {
118 125
 		}
119 126
 	}
120 127
 	rc = monojob_rc;
128
+	monojob_close ( &monojob, rc );
121 129
 
122 130
 	if ( shown_percentage )
123 131
 		printf ( "\b\b\b\b    \b\b\b\b" );

+ 1
- 1
src/include/ipxe/monojob.h Näytä tiedosto

@@ -13,6 +13,6 @@ struct interface;
13 13
 
14 14
 extern struct interface monojob;
15 15
 
16
-extern int monojob_wait ( const char *string );
16
+extern int monojob_wait ( const char *string, unsigned long timeout );
17 17
 
18 18
 #endif /* _IPXE_MONOJOB_H */

+ 2
- 2
src/usr/dhcpmgmt.c Näytä tiedosto

@@ -52,7 +52,7 @@ int dhcp ( struct net_device *netdev ) {
52 52
 	printf ( "DHCP (%s %s)", netdev->name,
53 53
 		 netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
54 54
 	if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
55
-		rc = monojob_wait ( "" );
55
+		rc = monojob_wait ( "", 0 );
56 56
 
57 57
 	return rc;
58 58
 }
@@ -63,7 +63,7 @@ int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
63 63
 	/* Perform PXE Boot Server Discovery */
64 64
 	printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
65 65
 	if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
66
-		rc = monojob_wait ( "" );
66
+		rc = monojob_wait ( "", 0 );
67 67
 
68 68
 	return rc;
69 69
 }

+ 1
- 1
src/usr/fcmgmt.c Näytä tiedosto

@@ -112,5 +112,5 @@ int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
112 112
 	}
113 113
 
114 114
 	/* Wait for ELS to complete */
115
-	return monojob_wait ( "" );
115
+	return monojob_wait ( "", 0 );
116 116
 }

+ 1
- 1
src/usr/imgmgmt.c Näytä tiedosto

@@ -72,7 +72,7 @@ int imgdownload ( struct uri *uri, struct image **image ) {
72 72
 	}
73 73
 
74 74
 	/* Wait for download to complete */
75
-	if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
75
+	if ( ( rc = monojob_wait ( uri_string_redacted, 0 ) ) != 0 )
76 76
 		goto err_monojob_wait;
77 77
 
78 78
 	/* Register image */

+ 1
- 1
src/usr/imgtrust.c Näytä tiedosto

@@ -77,7 +77,7 @@ int imgverify ( struct image *image, struct image *signature,
77 77
 	list_for_each_entry ( info, &sig->info, list ) {
78 78
 		if ( ( rc = create_validator ( &monojob, info->chain ) ) != 0 )
79 79
 			goto err_create_validator;
80
-		if ( ( rc = monojob_wait ( NULL ) ) != 0 )
80
+		if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
81 81
 			goto err_validator_wait;
82 82
 	}
83 83
 

+ 1
- 1
src/usr/nslookup.c Näytä tiedosto

@@ -186,7 +186,7 @@ int nslookup ( const char *name, const char *setting_name ) {
186 186
 
187 187
 	/* Perform name resolution */
188 188
 	if ( ( rc = resolv_setting ( &monojob, name, setting_name ) ) == 0 )
189
-		rc = monojob_wait ( NULL );
189
+		rc = monojob_wait ( NULL, 0 );
190 190
 	if ( rc != 0 ) {
191 191
 		printf ( "Could not resolve %s: %s\n", name, strerror ( rc ) );
192 192
 		return rc;

+ 1
- 1
src/usr/pingmgmt.c Näytä tiedosto

@@ -71,7 +71,7 @@ int ping ( const char *hostname, unsigned long timeout, size_t len ) {
71 71
 	}
72 72
 
73 73
 	/* Wait for ping to complete */
74
-	if ( ( rc = monojob_wait ( NULL ) ) != 0 ) {
74
+	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
75 75
 		printf ( "Finished: %s\n", strerror ( rc ) );
76 76
 		return rc;
77 77
 	}

Loading…
Peruuta
Tallenna