|
@@ -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" );
|