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

[PATCH 1/2] Refactor monitor.c


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Wed, 9 Dec 2020 13:28:46 +0000
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Wed, 09 Dec 2020 13:29:14 +0000
  • Ironport-hdrordr: A9a23:EuEX2Kij6k87lyZrcO+bZMs6OHBQX/t13DAbvn1ZSRFFG/Gwve rGppUm/DXzjyscX2xlpMuJP7OOTWiZ2Zl+54QQOrnKZniAhEKDKoZ+4Yz+hwDxAiGWzJ8l6Y 5Me7VzYeeAbmRSot395GCDfOoI5Pmi3OSWifzFz3FrJDsaD51IywtiEA6UHglXaWB9dPgEPa GR7MZGuDasEE5/Bq/QaxU4dtPOusHRk9beaQMGbiRXjjWmty+i67LxDnGjvis2bjUn+9kf2F mAtwT446m52svLryPh/mrY2ZRaibLd49FIbfbstuEeLDLwhgG0IJl7U7qZszwv5O2p4lAmkN 7Dyi1QWPhb4XXXY22zvF/xyxDtuQxekkPKxFeEjRLY0K/EbT0gDc4pv+1kWx/U8VApst050K 8j5RP6i7NSDRfN2Dvw/MLJURYCrDvRnVM4neQej2NSXOIlAdc7x+FywGpPHIodByW/8Yg7EY BVfafhzexLelCXZW2xhAlS6cGrN05cIj6WBkwLusmYyFFt7RVE83c=
  • Ironport-sdr: pd4gNcqosgDE2Zo/Nd6a+W+lciIY3r7L530IQ7e36rzNlPKpE/IUynKd5HKggl7QOfmLpIYBQU Oe/X7stfmTFnlB1Ly/TliCfow+YNX7807fmrKbCs3a/Ox9S2Ch192aIoIBM0ErEC7e0M3pgiWA y57DGm+KJt7los9rAeAd+CJ96cXRpWOdJ3dgl9rSPgZeYlSfSKPIHRHu+vhd5B5W53CyjYMdm9 3wBLOKi05SgpEEJ2w98LZVAyMCIMYDx1Ae8IHfpCJbbAuw8rmhupkb6y3BSQKctKuBl0D9XD0X Za0=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

- Split reboot question from statement
- Move GetDisplayName to seperate function call

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/monitor/monitor.c | 155 ++++++++++++++++++++++++++++++------------
 src/xenbus.inf        |   4 +-
 2 files changed, 114 insertions(+), 45 deletions(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 3cf33ce..07bf8c1 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -59,6 +59,7 @@ typedef struct _MONITOR_CONTEXT {
     HKEY                    RequestKey;
     PTCHAR                  Title;
     PTCHAR                  Text;
+    PTCHAR                  Question;
     BOOL                    RebootPending;
 } MONITOR_CONTEXT, *PMONITOR_CONTEXT;
 
@@ -348,36 +349,20 @@ GetPromptTimeout(
     return Value;
 }
 
-static VOID
-PromptForReboot(
+static PTCHAR
+GetDisplayName(
     IN PTCHAR           DriverName
     )
 {
-    PMONITOR_CONTEXT    Context = &MonitorContext;
-    PTCHAR              Title;
-    DWORD               TitleLength;
     HRESULT             Result;
     TCHAR               ServiceKeyName[MAX_PATH];
     HKEY                ServiceKey;
     DWORD               MaxValueLength;
+    DWORD               Type;
     DWORD               DisplayNameLength;
     PTCHAR              DisplayName;
-    DWORD               Type;
-    PTCHAR              Description;
-    PTCHAR              Text;
-    DWORD               TextLength;
-    PWTS_SESSION_INFO   SessionInfo;
-    DWORD               Count;
-    DWORD               Index;
-    BOOL                Success;
     HRESULT             Error;
 
-    Log("====> (%s)", DriverName);
-
-    Title = Context->Title;
-    TitleLength = (DWORD)((_tcslen(Context->Title) +
-                           1) * sizeof (TCHAR));
-
     Result = StringCbPrintf(ServiceKeyName,
                             MAX_PATH,
                             SERVICES_KEY "\\%s",
@@ -433,6 +418,68 @@ PromptForReboot(
         goto fail5;
     }
 
+    RegCloseKey(ServiceKey);
+
+    return DisplayName;
+
+fail5:
+    Log("fail5");
+
+fail4:
+    Log("fail4");
+
+    free(DisplayName);
+
+fail3:
+    Log("fail3");
+
+fail2:
+    Log("fail2");
+
+    RegCloseKey(ServiceKey);
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return NULL;
+}
+
+static VOID
+PromptForReboot(
+    IN PTCHAR           DriverName
+    )
+{
+    PMONITOR_CONTEXT    Context = &MonitorContext;
+    HRESULT             Result;
+    PTCHAR              Title;
+    DWORD               TitleLength;
+    PTCHAR              DisplayName;
+    PTCHAR              Description;
+    PTCHAR              Text;
+    DWORD               TextLength;
+    PWTS_SESSION_INFO   SessionInfo;
+    DWORD               Count;
+    DWORD               Index;
+    BOOL                Success;
+    HRESULT             Error;
+
+    Log("====> (%s)", DriverName);
+
+    Title = Context->Title;
+    TitleLength = (DWORD)((_tcslen(Context->Title) +
+                           1) * sizeof (TCHAR));
+
+    DisplayName = GetDisplayName(DriverName);
+    if (DisplayName == NULL)
+        goto fail1;
+
     Description = _tcsrchr(DisplayName, ';');
     if (Description == NULL)
         Description = DisplayName;
@@ -442,17 +489,20 @@ PromptForReboot(
     TextLength = (DWORD)((_tcslen(Description) +
                           1 + // ' '
                           _tcslen(Context->Text) +
+                          1 + // ' '
+                          _tcslen(Context->Question) +
                           1) * sizeof (TCHAR));
 
     Text = calloc(1, TextLength);
     if (Text == NULL)
-        goto fail6;
+        goto fail2;
 
     Result = StringCbPrintf(Text,
                             TextLength,
-                            TEXT("%s %s"),
+                            TEXT("%s %s %s"),
                             Description,
-                            Context->Text);
+                            Context->Text,
+                            Context->Question);
     assert(SUCCEEDED(Result));
 
     Success = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
@@ -461,7 +511,7 @@ PromptForReboot(
                                    &SessionInfo,
                                    &Count);
     if (!Success)
-        goto fail7;
+        goto fail3;
 
     for (Index = 0; Index < Count; Index++) {
         DWORD                   SessionId = SessionInfo[Index].SessionId;
@@ -492,7 +542,7 @@ PromptForReboot(
                                  TRUE);
 
         if (!Success)
-            goto fail8;
+            goto fail4;
 
         Context->RebootPending = TRUE;
 
@@ -506,30 +556,14 @@ PromptForReboot(
 
     free(DisplayName);
 
-    RegCloseKey(ServiceKey);
-
     Log("<====");
 
     return;
 
-fail8:
-    Log("fail8");
-
-    WTSFreeMemory(SessionInfo);
-
-fail7:
-    Log("fail7");
-
-fail6:
-    Log("fail6");
-
-fail5:
-    Log("fail5");
-
 fail4:
     Log("fail4");
 
-    free(DisplayName);
+    WTSFreeMemory(SessionInfo);
 
 fail3:
     Log("fail3");
@@ -537,7 +571,7 @@ fail3:
 fail2:
     Log("fail2");
 
-    RegCloseKey(ServiceKey);
+    free(DisplayName);
 
 fail1:
     Error = GetLastError();
@@ -862,6 +896,7 @@ GetDialogParameters(
     DWORD               MaxValueLength;
     DWORD               TitleLength;
     DWORD               TextLength;
+    DWORD               QuestionLength;
     DWORD               Type;
     HRESULT             Error;
 
@@ -926,8 +961,41 @@ GetDialogParameters(
         goto fail7;
     }
 
+    QuestionLength = MaxValueLength + sizeof (TCHAR);
+
+    Context->Question = calloc(1, QuestionLength);
+    if (Context == NULL)
+        goto fail8;
+
+    Error = RegQueryValueEx(Context->ParametersKey,
+                            "DialogQuestion",
+                            NULL,
+                            &Type,
+                            (LPBYTE)Context->Question,
+                            &QuestionLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail9;
+    }
+
+    if (Type != REG_SZ) {
+        SetLastError(ERROR_BAD_FORMAT);
+        goto fail10;
+    }
+
     return TRUE;
 
+fail10:
+    Log("fail10");
+
+fail9:
+    Log("fail9");
+
+    free(Context->Question);
+
+fail8:
+    Log("fail8");
+
 fail7:
     Log("fail7");
 
@@ -963,8 +1031,6 @@ fail1:
     return FALSE;
 }
 
-
-
 VOID WINAPI
 MonitorMain(
     _In_    DWORD       argc,
@@ -1080,6 +1146,7 @@ MonitorMain(
 done:
     (VOID) RegDeleteTree(Context->RequestKey, NULL);
 
+    free(Context->Question);
     free(Context->Text);
     free(Context->Title);
     CloseHandle(Context->RequestKey);
diff --git a/src/xenbus.inf b/src/xenbus.inf
index bf3f0a1..f9a5475 100644
--- a/src/xenbus.inf
+++ b/src/xenbus.inf
@@ -134,6 +134,7 @@ HKR,"Parameters",,0x00000010
 HKR,"Parameters","RequestKey",0x00000000,%RequestKey%
 HKR,"Parameters","DialogTitle",0x00000000,%DialogTitle%
 HKR,"Parameters","DialogText",0x00000000,%DialogText%
+HKR,"Parameters","DialogQuestion",0x00000000,%DialogQuestion%
 
 [Monitor_EventLog]
 AddReg=Monitor_EventLog_AddReg
@@ -159,7 +160,8 @@ MonitorName="@PRODUCT_NAME@ PV Driver Monitor"
 MonitorDesc="Provides support for @PRODUCT_NAME@ PV drivers"
 RequestKey="SYSTEM\CurrentControlSet\Services\xenbus_monitor\Request"
 DialogTitle="@PRODUCT_NAME@"
-DialogText="needs to restart the system to complete installation. Press 'Yes' 
to restart the system now or 'No' if you plan to restart the system later."
+DialogText="needs to restart the system to complete installation."
+DialogQuestion="Press 'Yes' to restart the system now or 'No' if you plan to 
restart the system later."
 
 SERVICE_BOOT_START=0x0 
 SERVICE_SYSTEM_START=0x1 
-- 
2.28.0.windows.1




 


Rackspace

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