[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XENBUS PATCH v3 3/5] Repeat TryAutoReboot() with timer



Add a timer that calls TryAutoReboot() every minute if reboot has been
requested beforehand.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
Reviewed-by: Paul Durrant <paul@xxxxxxx>
---
 src/monitor/monitor.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 1bb4705..ccb2d8a 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -57,6 +57,7 @@ typedef struct _MONITOR_CONTEXT {
     HANDLE                  EventLog;
     HANDLE                  StopEvent;
     HANDLE                  RequestEvent;
+    HANDLE                  Timer;
     HKEY                    RequestKey;
     PTCHAR                  Title;
     PTCHAR                  Text;
@@ -77,6 +78,7 @@ typedef struct _REBOOT_PROMPT {
 MONITOR_CONTEXT MonitorContext;
 
 #define MAXIMUM_BUFFER_SIZE 1024
+#define REBOOT_RETRY_DELAY  60000L // 1 minute
 
 #define SERVICES_KEY "SYSTEM\\CurrentControlSet\\Services"
 
@@ -1347,6 +1349,7 @@ MonitorMain(
     PTCHAR              RequestKeyName;
     BOOL                Success;
     HRESULT             Error;
+    LARGE_INTEGER       DueTime;
 
     UNREFERENCED_PARAMETER(argc);
     UNREFERENCED_PARAMETER(argv);
@@ -1426,17 +1429,33 @@ MonitorMain(
     if (!Success)
         goto fail10;
 
+    Context->Timer = CreateWaitableTimer(NULL, FALSE, NULL);
+    if (Context->Timer == NULL)
+        goto fail11;
+
+    DueTime.QuadPart = -10000LL * REBOOT_RETRY_DELAY;
+
+    Success = SetWaitableTimer(Context->Timer,
+                               &DueTime,
+                               REBOOT_RETRY_DELAY,
+                               NULL,
+                               NULL,
+                               FALSE);
+    if (!Success)
+        goto fail12;
+
     SetEvent(Context->RequestEvent);
 
     ReportStatus(SERVICE_RUNNING, NO_ERROR, 0);
 
     for (;;) {
-        HANDLE  Events[3];
+        HANDLE  Events[4];
         DWORD   Object;
 
         Events[0] = Context->StopEvent;
         Events[1] = Context->RequestEvent;
         Events[2] = Context->ResponseEvent;
+        Events[3] = Context->Timer;
 
         Log("waiting (%u)...", ARRAYSIZE(Events));
         Object = WaitForMultipleObjects(ARRAYSIZE(Events),
@@ -1460,12 +1479,21 @@ MonitorMain(
                 DoReboot(NULL, 0);
             break;
 
+        case WAIT_OBJECT_0 + 3:
+            if (Context->RebootRequestedBy)
+                TryAutoReboot(Context->RebootRequestedBy);
+            break;
+
         default:
             break;
         }
     }
 
 done:
+    free(Context->RebootRequestedBy);
+    CancelWaitableTimer(Context->Timer);
+    CloseHandle(Context->Timer);
+
     (VOID) RegDeleteTree(Context->RequestKey, NULL);
 
     free(Context->Question);
@@ -1488,6 +1516,14 @@ done:
 
     return;
 
+fail12:
+    Log("fail12");
+
+    CloseHandle(Context->Timer);
+
+fail11:
+    Log("fail11");
+
 fail10:
     Log("fail10");
 
-- 
2.49.0.windows.1



Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.