]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[monojob] Add timeout parameter to monojob_wait()
authorMichael Brown <mcb30@ipxe.org>
Fri, 1 Nov 2013 01:55:13 +0000 (01:55 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 1 Nov 2013 16:26:02 +0000 (16:26 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/monojob.c
src/include/ipxe/monojob.h
src/usr/dhcpmgmt.c
src/usr/fcmgmt.c
src/usr/imgmgmt.c
src/usr/imgtrust.c
src/usr/nslookup.c
src/usr/pingmgmt.c

index d262f70b25cd1268f9c0a017411254e15308056f..94ed74c0f22de4bc05dbd99407b3c245b811acd3 100644 (file)
@@ -55,12 +55,12 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
  * Wait for single foreground job to complete
  *
  * @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
  */
-int monojob_wait ( const char *string ) {
+int monojob_wait ( const char *string, unsigned long timeout ) {
        struct job_progress progress;
-       int key;
-       int rc;
+       unsigned long start;
        unsigned long last_keycheck;
        unsigned long last_progress;
        unsigned long now;
@@ -69,11 +69,13 @@ int monojob_wait ( const char *string ) {
        unsigned long total;
        unsigned int percentage;
        int shown_percentage = 0;
+       int key;
+       int rc;
 
        if ( string )
                printf ( "%s...", string );
        monojob_rc = -EINPROGRESS;
-       last_keycheck = last_progress = currticks();
+       last_keycheck = last_progress = start = currticks();
        while ( monojob_rc == -EINPROGRESS ) {
 
                /* Allow job to progress */
@@ -83,20 +85,25 @@ int monojob_wait ( const char *string ) {
                /* Check for keypresses.  This can be time-consuming,
                 * so check only once per clock tick.
                 */
-               if ( now != last_keycheck ) {
+               elapsed = ( now - last_keycheck );
+               if ( elapsed ) {
                        if ( iskey() ) {
                                key = getchar();
-                               switch ( key ) {
-                               case CTRL_C:
-                                       monojob_close ( &monojob, -ECANCELED );
-                                       break;
-                               default:
+                               if ( key == CTRL_C ) {
+                                       monojob_rc = -ECANCELED;
                                        break;
                                }
                        }
                        last_keycheck = now;
                }
 
+               /* Check for timeout, if applicable */
+               elapsed = ( now - start );
+               if ( timeout && ( elapsed >= timeout ) ) {
+                       monojob_rc = -ETIMEDOUT;
+                       break;
+               }
+
                /* Display progress, if applicable */
                elapsed = ( now - last_progress );
                if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
@@ -118,6 +125,7 @@ int monojob_wait ( const char *string ) {
                }
        }
        rc = monojob_rc;
+       monojob_close ( &monojob, rc );
 
        if ( shown_percentage )
                printf ( "\b\b\b\b    \b\b\b\b" );
index 3d8b31c0eb3377ddcb1d7021f160135773790afc..aedc37ecade03d3ec64418bd01aa1b23e7d3e4c4 100644 (file)
@@ -13,6 +13,6 @@ struct interface;
 
 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 */
index 10d8ecfa595067017af48285fd24369c3b3dbfc8..7b8e53701b56ea98ec8e43127dd847dc827982eb 100644 (file)
@@ -52,7 +52,7 @@ int dhcp ( struct net_device *netdev ) {
        printf ( "DHCP (%s %s)", netdev->name,
                 netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
        if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
-               rc = monojob_wait ( "" );
+               rc = monojob_wait ( "", 0 );
 
        return rc;
 }
@@ -63,7 +63,7 @@ int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
        /* Perform PXE Boot Server Discovery */
        printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
        if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
-               rc = monojob_wait ( "" );
+               rc = monojob_wait ( "", 0 );
 
        return rc;
 }
index 2657ba0cfbad4a742824ba3638c0c813299b547a..a30f37a711a4dc44400a5ac59272a2f5cdf3126f 100644 (file)
@@ -112,5 +112,5 @@ int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
        }
 
        /* Wait for ELS to complete */
-       return monojob_wait ( "" );
+       return monojob_wait ( "", 0 );
 }
index ef4e2c3664421cd51289123164f704247cc739ab..ecf9d31d405430619b8cf1b1a66c7a08a29a418f 100644 (file)
@@ -72,7 +72,7 @@ int imgdownload ( struct uri *uri, struct image **image ) {
        }
 
        /* 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;
 
        /* Register image */
index afb41529f00a90e645d4414e41fa56150b34d2e8..c49eb7f272031a9254a4f06838db26891516ea81 100644 (file)
@@ -77,7 +77,7 @@ int imgverify ( struct image *image, struct image *signature,
        list_for_each_entry ( info, &sig->info, list ) {
                if ( ( rc = create_validator ( &monojob, info->chain ) ) != 0 )
                        goto err_create_validator;
-               if ( ( rc = monojob_wait ( NULL ) ) != 0 )
+               if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
                        goto err_validator_wait;
        }
 
index cb6d8d2b1b9c9b7654430d1baa3f9270298f568b..b691962ef0574f68b4429e32de93f78b41dc744c 100644 (file)
@@ -186,7 +186,7 @@ int nslookup ( const char *name, const char *setting_name ) {
 
        /* Perform name resolution */
        if ( ( rc = resolv_setting ( &monojob, name, setting_name ) ) == 0 )
-               rc = monojob_wait ( NULL );
+               rc = monojob_wait ( NULL, 0 );
        if ( rc != 0 ) {
                printf ( "Could not resolve %s: %s\n", name, strerror ( rc ) );
                return rc;
index 0db10c219307d74b3ca25f811a1737e9ed445592..2d4db491fbbf7952bbab203efc6896b3691ad031 100644 (file)
@@ -71,7 +71,7 @@ int ping ( const char *hostname, unsigned long timeout, size_t len ) {
        }
 
        /* Wait for ping to complete */
-       if ( ( rc = monojob_wait ( NULL ) ) != 0 ) {
+       if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
                printf ( "Finished: %s\n", strerror ( rc ) );
                return rc;
        }