Browse Source

[monojob] Add timeout parameter to monojob_wait()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
d1be9f4acc
8 changed files with 26 additions and 18 deletions
  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 View File

55
  * Wait for single foreground job to complete
55
  * Wait for single foreground job to complete
56
  *
56
  *
57
  * @v string		Job description to display, or NULL to be silent
57
  * @v string		Job description to display, or NULL to be silent
58
+ * @v timeout		Timeout period, in ticks (0=indefinite)
58
  * @ret rc		Job final status code
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
 	struct job_progress progress;
62
 	struct job_progress progress;
62
-	int key;
63
-	int rc;
63
+	unsigned long start;
64
 	unsigned long last_keycheck;
64
 	unsigned long last_keycheck;
65
 	unsigned long last_progress;
65
 	unsigned long last_progress;
66
 	unsigned long now;
66
 	unsigned long now;
69
 	unsigned long total;
69
 	unsigned long total;
70
 	unsigned int percentage;
70
 	unsigned int percentage;
71
 	int shown_percentage = 0;
71
 	int shown_percentage = 0;
72
+	int key;
73
+	int rc;
72
 
74
 
73
 	if ( string )
75
 	if ( string )
74
 		printf ( "%s...", string );
76
 		printf ( "%s...", string );
75
 	monojob_rc = -EINPROGRESS;
77
 	monojob_rc = -EINPROGRESS;
76
-	last_keycheck = last_progress = currticks();
78
+	last_keycheck = last_progress = start = currticks();
77
 	while ( monojob_rc == -EINPROGRESS ) {
79
 	while ( monojob_rc == -EINPROGRESS ) {
78
 
80
 
79
 		/* Allow job to progress */
81
 		/* Allow job to progress */
83
 		/* Check for keypresses.  This can be time-consuming,
85
 		/* Check for keypresses.  This can be time-consuming,
84
 		 * so check only once per clock tick.
86
 		 * so check only once per clock tick.
85
 		 */
87
 		 */
86
-		if ( now != last_keycheck ) {
88
+		elapsed = ( now - last_keycheck );
89
+		if ( elapsed ) {
87
 			if ( iskey() ) {
90
 			if ( iskey() ) {
88
 				key = getchar();
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
 					break;
94
 					break;
95
 				}
95
 				}
96
 			}
96
 			}
97
 			last_keycheck = now;
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
 		/* Display progress, if applicable */
107
 		/* Display progress, if applicable */
101
 		elapsed = ( now - last_progress );
108
 		elapsed = ( now - last_progress );
102
 		if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
109
 		if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
118
 		}
125
 		}
119
 	}
126
 	}
120
 	rc = monojob_rc;
127
 	rc = monojob_rc;
128
+	monojob_close ( &monojob, rc );
121
 
129
 
122
 	if ( shown_percentage )
130
 	if ( shown_percentage )
123
 		printf ( "\b\b\b\b    \b\b\b\b" );
131
 		printf ( "\b\b\b\b    \b\b\b\b" );

+ 1
- 1
src/include/ipxe/monojob.h View File

13
 
13
 
14
 extern struct interface monojob;
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
 #endif /* _IPXE_MONOJOB_H */
18
 #endif /* _IPXE_MONOJOB_H */

+ 2
- 2
src/usr/dhcpmgmt.c View File

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

+ 1
- 1
src/usr/fcmgmt.c View File

112
 	}
112
 	}
113
 
113
 
114
 	/* Wait for ELS to complete */
114
 	/* Wait for ELS to complete */
115
-	return monojob_wait ( "" );
115
+	return monojob_wait ( "", 0 );
116
 }
116
 }

+ 1
- 1
src/usr/imgmgmt.c View File

72
 	}
72
 	}
73
 
73
 
74
 	/* Wait for download to complete */
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
 		goto err_monojob_wait;
76
 		goto err_monojob_wait;
77
 
77
 
78
 	/* Register image */
78
 	/* Register image */

+ 1
- 1
src/usr/imgtrust.c View File

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

+ 1
- 1
src/usr/nslookup.c View File

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

+ 1
- 1
src/usr/pingmgmt.c View File

71
 	}
71
 	}
72
 
72
 
73
 	/* Wait for ping to complete */
73
 	/* Wait for ping to complete */
74
-	if ( ( rc = monojob_wait ( NULL ) ) != 0 ) {
74
+	if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
75
 		printf ( "Finished: %s\n", strerror ( rc ) );
75
 		printf ( "Finished: %s\n", strerror ( rc ) );
76
 		return rc;
76
 		return rc;
77
 	}
77
 	}

Loading…
Cancel
Save