mirror of
https://github.com/ipxe/ipxe
synced 2025-12-15 00:12:19 +03:00
[monojob] Add timeout parameter to monojob_wait()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -55,12 +55,12 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
|
|||||||
* Wait for single foreground job to complete
|
* Wait for single foreground job to complete
|
||||||
*
|
*
|
||||||
* @v string Job description to display, or NULL to be silent
|
* @v string Job description to display, or NULL to be silent
|
||||||
|
* @v timeout Timeout period, in ticks (0=indefinite)
|
||||||
* @ret rc Job final status code
|
* @ret rc Job final status code
|
||||||
*/
|
*/
|
||||||
int monojob_wait ( const char *string ) {
|
int monojob_wait ( const char *string, unsigned long timeout ) {
|
||||||
struct job_progress progress;
|
struct job_progress progress;
|
||||||
int key;
|
unsigned long start;
|
||||||
int rc;
|
|
||||||
unsigned long last_keycheck;
|
unsigned long last_keycheck;
|
||||||
unsigned long last_progress;
|
unsigned long last_progress;
|
||||||
unsigned long now;
|
unsigned long now;
|
||||||
@@ -69,11 +69,13 @@ int monojob_wait ( const char *string ) {
|
|||||||
unsigned long total;
|
unsigned long total;
|
||||||
unsigned int percentage;
|
unsigned int percentage;
|
||||||
int shown_percentage = 0;
|
int shown_percentage = 0;
|
||||||
|
int key;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if ( string )
|
if ( string )
|
||||||
printf ( "%s...", string );
|
printf ( "%s...", string );
|
||||||
monojob_rc = -EINPROGRESS;
|
monojob_rc = -EINPROGRESS;
|
||||||
last_keycheck = last_progress = currticks();
|
last_keycheck = last_progress = start = currticks();
|
||||||
while ( monojob_rc == -EINPROGRESS ) {
|
while ( monojob_rc == -EINPROGRESS ) {
|
||||||
|
|
||||||
/* Allow job to progress */
|
/* Allow job to progress */
|
||||||
@@ -83,20 +85,25 @@ int monojob_wait ( const char *string ) {
|
|||||||
/* Check for keypresses. This can be time-consuming,
|
/* Check for keypresses. This can be time-consuming,
|
||||||
* so check only once per clock tick.
|
* so check only once per clock tick.
|
||||||
*/
|
*/
|
||||||
if ( now != last_keycheck ) {
|
elapsed = ( now - last_keycheck );
|
||||||
|
if ( elapsed ) {
|
||||||
if ( iskey() ) {
|
if ( iskey() ) {
|
||||||
key = getchar();
|
key = getchar();
|
||||||
switch ( key ) {
|
if ( key == CTRL_C ) {
|
||||||
case CTRL_C:
|
monojob_rc = -ECANCELED;
|
||||||
monojob_close ( &monojob, -ECANCELED );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_keycheck = now;
|
last_keycheck = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for timeout, if applicable */
|
||||||
|
elapsed = ( now - start );
|
||||||
|
if ( timeout && ( elapsed >= timeout ) ) {
|
||||||
|
monojob_rc = -ETIMEDOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Display progress, if applicable */
|
/* Display progress, if applicable */
|
||||||
elapsed = ( now - last_progress );
|
elapsed = ( now - last_progress );
|
||||||
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
||||||
@@ -118,6 +125,7 @@ int monojob_wait ( const char *string ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = monojob_rc;
|
rc = monojob_rc;
|
||||||
|
monojob_close ( &monojob, rc );
|
||||||
|
|
||||||
if ( shown_percentage )
|
if ( shown_percentage )
|
||||||
printf ( "\b\b\b\b \b\b\b\b" );
|
printf ( "\b\b\b\b \b\b\b\b" );
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ struct interface;
|
|||||||
|
|
||||||
extern struct interface monojob;
|
extern struct interface monojob;
|
||||||
|
|
||||||
extern int monojob_wait ( const char *string );
|
extern int monojob_wait ( const char *string, unsigned long timeout );
|
||||||
|
|
||||||
#endif /* _IPXE_MONOJOB_H */
|
#endif /* _IPXE_MONOJOB_H */
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ int dhcp ( struct net_device *netdev ) {
|
|||||||
printf ( "DHCP (%s %s)", netdev->name,
|
printf ( "DHCP (%s %s)", netdev->name,
|
||||||
netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
|
netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
|
||||||
if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
|
if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
|
||||||
rc = monojob_wait ( "" );
|
rc = monojob_wait ( "", 0 );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
|
|||||||
/* Perform PXE Boot Server Discovery */
|
/* Perform PXE Boot Server Discovery */
|
||||||
printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
|
printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
|
||||||
if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
|
if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
|
||||||
rc = monojob_wait ( "" );
|
rc = monojob_wait ( "", 0 );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,5 +112,5 @@ int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for ELS to complete */
|
/* Wait for ELS to complete */
|
||||||
return monojob_wait ( "" );
|
return monojob_wait ( "", 0 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ int imgdownload ( struct uri *uri, struct image **image ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for download to complete */
|
/* Wait for download to complete */
|
||||||
if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
|
if ( ( rc = monojob_wait ( uri_string_redacted, 0 ) ) != 0 )
|
||||||
goto err_monojob_wait;
|
goto err_monojob_wait;
|
||||||
|
|
||||||
/* Register image */
|
/* Register image */
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ int imgverify ( struct image *image, struct image *signature,
|
|||||||
list_for_each_entry ( info, &sig->info, list ) {
|
list_for_each_entry ( info, &sig->info, list ) {
|
||||||
if ( ( rc = create_validator ( &monojob, info->chain ) ) != 0 )
|
if ( ( rc = create_validator ( &monojob, info->chain ) ) != 0 )
|
||||||
goto err_create_validator;
|
goto err_create_validator;
|
||||||
if ( ( rc = monojob_wait ( NULL ) ) != 0 )
|
if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
|
||||||
goto err_validator_wait;
|
goto err_validator_wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ int nslookup ( const char *name, const char *setting_name ) {
|
|||||||
|
|
||||||
/* Perform name resolution */
|
/* Perform name resolution */
|
||||||
if ( ( rc = resolv_setting ( &monojob, name, setting_name ) ) == 0 )
|
if ( ( rc = resolv_setting ( &monojob, name, setting_name ) ) == 0 )
|
||||||
rc = monojob_wait ( NULL );
|
rc = monojob_wait ( NULL, 0 );
|
||||||
if ( rc != 0 ) {
|
if ( rc != 0 ) {
|
||||||
printf ( "Could not resolve %s: %s\n", name, strerror ( rc ) );
|
printf ( "Could not resolve %s: %s\n", name, strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ int ping ( const char *hostname, unsigned long timeout, size_t len ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for ping to complete */
|
/* Wait for ping to complete */
|
||||||
if ( ( rc = monojob_wait ( NULL ) ) != 0 ) {
|
if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
|
||||||
printf ( "Finished: %s\n", strerror ( rc ) );
|
printf ( "Finished: %s\n", strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user