- Timestamp:
- Nov 24, 2009 3:09:43 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r24912 r24915 42 42 #include <VBox/version.h> 43 43 44 #include <iprt/asm.h> 44 45 #include <iprt/buildconfig.h> 45 #include <iprt/env.h>46 46 #include <iprt/initterm.h> 47 47 #include <iprt/stream.h> 48 48 #include <iprt/string.h> 49 49 50 #include <signal.h> 51 50 52 #include "VBoxManage.h" 51 53 … … 54 56 * Global Variables * 55 57 *******************************************************************************/ 56 /*extern*/ bool g_fDetailedProgress = false; 57 58 /*extern*/ bool g_fDetailedProgress = false; 58 59 59 60 #ifndef VBOX_ONLY_DOCS 61 /** Set by the signal handler. */ 62 static volatile bool g_fCanceled = false; 63 64 65 /** 66 * Signal handler that sets g_fCanceled. 67 * 68 * This can be executed on any thread in the process, on Windows it may even be 69 * a thread dedicated to delivering this signal. Do not doing anything 70 * unnecessary here. 71 */ 72 static void showProgressSignalHandler(int iSignal) 73 { 74 NOREF(iSignal); 75 ASMAtomicWriteBool(&g_fCanceled, true); 76 } 77 78 60 79 /** 61 80 * Print out progress on the console … … 84 103 } 85 104 105 /* setup signal handling if cancelable */ 106 bool fCanceledAlready = false; 107 BOOL fCancelable; 108 HRESULT hrc = progress->COMGETTER(Cancelable)(&fCancelable); 109 if (FAILED(hrc)) 110 fCancelable = FALSE; 111 if (fCancelable) 112 { 113 signal(SIGINT, showProgressSignalHandler); 114 #ifdef SIGBREAK 115 signal(SIGBREAK, showProgressSignalHandler); 116 #endif 117 } 118 86 119 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted)))) 87 120 { … … 101 134 } 102 135 103 if ( (ulCurrentPercent != ulLastPercent)104 || (ulCurrentOperationPercent != ulLastOperationPercent)136 if ( ulCurrentPercent != ulLastPercent 137 || ulCurrentOperationPercent != ulLastOperationPercent 105 138 ) 106 139 { … … 133 166 break; 134 167 168 /* process async cancelation */ 169 if (g_fCanceled && !fCanceledAlready) 170 { 171 hrc = progress->Cancel(); 172 if (SUCCEEDED(hrc)) 173 fCanceledAlready = true; 174 else 175 g_fCanceled = false; 176 } 177 135 178 /* make sure the loop is not too tight */ 136 179 progress->WaitForCompletion(100); 180 } 181 182 /* undo signal handling */ 183 if (fCancelable) 184 { 185 signal(SIGINT, SIG_DFL); 186 #ifdef SIGBREAK 187 signal(SIGBREAK, SIG_DFL); 188 #endif 137 189 } 138 190 … … 143 195 if (SUCCEEDED(iRc)) 144 196 RTPrintf("100%%\n"); 197 else if (g_fCanceled) 198 RTPrintf("CANCELED\n"); 145 199 else 146 200 RTPrintf("FAILED\n"); … … 151 205 return iRc; 152 206 } 207 153 208 #endif /* !VBOX_ONLY_DOCS */ 154 155 209 156 210 int main(int argc, char *argv[])
Note:
See TracChangeset
for help on using the changeset viewer.