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

[win-pv-devel] [PATCH] monitor: get dialog paramaters from the registry



It is easier to localise the monitor dialog if it picks up the reboot dialog
title and message from registry parameters rather than having the hardcoded
or in a string table. This patch does this and sets default values in the
the INF file.

This patchs also adds a call to wait for driver installations to complete
before initialiating a reboot.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/monitor/monitor.c                        | 177 ++++++++++++++++++++++++---
 src/monitor/strings.h                        |  37 ------
 src/monitor/strings.rc                       |  37 ------
 src/monitor/xenbus_monitor.rc                |   1 -
 src/xenbus.inf                               |   4 +
 vs2012/xenbus_monitor/xenbus_monitor.vcxproj |   2 +-
 vs2013/xenbus_monitor/xenbus_monitor.vcxproj |   2 +-
 7 files changed, 163 insertions(+), 97 deletions(-)
 delete mode 100644 src/monitor/strings.h
 delete mode 100644 src/monitor/strings.rc

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index e2e8e20..0bfdaaf 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -34,13 +34,13 @@
 #include <stdlib.h>
 #include <strsafe.h>
 #include <wtsapi32.h>
+#include <cfgmgr32.h>
 #include <malloc.h>
 #include <assert.h>
 
 #include <version.h>
 
 #include "messages.h"
-#include "strings.h"
 
 #define MONITOR_NAME        __MODULE__
 #define MONITOR_DISPLAYNAME MONITOR_NAME
@@ -53,6 +53,8 @@ typedef struct _MONITOR_CONTEXT {
     HANDLE                  StopEvent;
     HANDLE                  RequestEvent;
     HKEY                    RequestKey;
+    PTCHAR                  Title;
+    PTCHAR                  Message;
     BOOL                    RebootPending;
 } MONITOR_CONTEXT, *PMONITOR_CONTEXT;
 
@@ -296,6 +298,12 @@ DoReboot(
     VOID
     )
 {
+    Log("waiting for pending install events...");
+
+    (VOID) CM_WaitNoPendingInstallEvents(INFINITE);
+
+    Log("initiating shutdown...");
+
     (VOID) InitiateSystemShutdownEx(NULL,
                                     NULL,
                                     0,
@@ -340,17 +348,18 @@ PromptForReboot(
     )
 {
     PMONITOR_CONTEXT    Context = &MonitorContext;
+    PTCHAR              Title;
+    DWORD               TitleLength;
     HRESULT             Result;
     TCHAR               ServiceKeyName[MAX_PATH];
     HKEY                ServiceKey;
     DWORD               MaxValueLength;
     DWORD               DisplayNameLength;
     PTCHAR              DisplayName;
-    PTCHAR              Description;
     DWORD               Type;
-    TCHAR               Title[] = TEXT(VENDOR_NAME_STR);
-    TCHAR               Message[MAXIMUM_BUFFER_SIZE];
-    DWORD               Length;
+    PTCHAR              Description;
+    PTCHAR              Message;
+    DWORD               MessageLength;
     PWTS_SESSION_INFO   SessionInfo;
     DWORD               Count;
     DWORD               Index;
@@ -359,6 +368,10 @@ PromptForReboot(
 
     Log("====> (%s)", DriverName);
 
+    Title = Context->Title;
+    TitleLength = (DWORD)((_tcslen(Context->Title) +
+                           1) * sizeof (TCHAR));
+
     Result = StringCbPrintf(ServiceKeyName,
                             MAX_PATH,
                             SERVICES_KEY "\\%s",
@@ -420,27 +433,27 @@ PromptForReboot(
     else
         Description++;
 
-    Result = StringCbPrintf(Message,
-                            MAXIMUM_BUFFER_SIZE,
-                            TEXT("%s "),
-                            Description);
-    assert(SUCCEEDED(Result));
+    MessageLength = (DWORD)((_tcslen(Description) +
+                             1 + // ' '
+                             _tcslen(Context->Message) +
+                             1) * sizeof (TCHAR));
 
-    Length = (DWORD)_tcslen(Message);
-
-    Length = LoadString(GetModuleHandle(NULL),
-                        IDS_DIALOG,
-                        Message + Length,
-                        ARRAYSIZE(Message) - Length);
-    if (Length == 0)
+    Message = calloc(1, MessageLength);
+    if (Message == NULL)
         goto fail6;
 
+    Result = StringCbPrintf(Message,
+                            MessageLength,
+                            TEXT("%s %s"),
+                            Description,
+                            Context->Message);
+    assert(SUCCEEDED(Result));
+
     Success = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
                                    0,
                                    1,
                                    &SessionInfo,
                                    &Count);
-
     if (!Success)
         goto fail7;
 
@@ -464,9 +477,9 @@ PromptForReboot(
         Success = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE,
                                  SessionId,
                                  Title,
-                                 sizeof (Title),
+                                 TitleLength,
                                  Message,
-                                 sizeof (Message),
+                                 MessageLength,
                                  MB_YESNO | MB_ICONEXCLAMATION,
                                  Timeout,
                                  &Response,
@@ -834,6 +847,118 @@ fail1:
     return FALSE;
 }
 
+static BOOL
+GetDialogParameters(
+    VOID
+    )
+{
+    PMONITOR_CONTEXT    Context = &MonitorContext;
+    DWORD               MaxValueLength;
+    DWORD               TitleLength;
+    DWORD               MessageLength;
+    DWORD               Type;
+    HRESULT             Error;
+
+    Error = RegQueryInfoKey(Context->ParametersKey,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            &MaxValueLength,
+                            NULL,
+                            NULL);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail1;
+    }
+
+    TitleLength = MaxValueLength + sizeof (TCHAR);
+
+    Context->Title = calloc(1, TitleLength);
+    if (Context == NULL)
+        goto fail2;
+
+    Error = RegQueryValueEx(Context->ParametersKey,
+                            "DialogTitle",
+                            NULL,
+                            &Type,
+                            (LPBYTE)Context->Title,
+                            &TitleLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail3;
+    }
+
+    if (Type != REG_SZ) {
+        SetLastError(ERROR_BAD_FORMAT);
+        goto fail4;
+    }
+
+    MessageLength = MaxValueLength + sizeof (TCHAR);
+
+    Context->Message = calloc(1, MessageLength);
+    if (Context == NULL)
+        goto fail5;
+
+    Error = RegQueryValueEx(Context->ParametersKey,
+                            "DialogMessage",
+                            NULL,
+                            &Type,
+                            (LPBYTE)Context->Message,
+                            &MessageLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail6;
+    }
+
+    if (Type != REG_SZ) {
+        SetLastError(ERROR_BAD_FORMAT);
+        goto fail7;
+    }
+
+    return TRUE;
+
+fail7:
+    Log("fail7");
+
+fail6:
+    Log("fail6");
+
+    free(Context->Message);
+
+fail5:
+    Log("fail5");
+
+fail4:
+    Log("fail4");
+
+fail3:
+    Log("fail3");
+
+    free(Context->Title);
+
+fail2:
+    Log("fail2");
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return FALSE;
+}
+
+
+
 VOID WINAPI
 MonitorMain(
     _In_    DWORD       argc,
@@ -905,6 +1030,10 @@ MonitorMain(
     if (Error != ERROR_SUCCESS)
         goto fail8;
 
+    Success = GetDialogParameters();
+    if (!Success)
+        goto fail9;
+
     SetEvent(Context->RequestEvent);
 
     ReportStatus(SERVICE_RUNNING, NO_ERROR, 0);
@@ -941,7 +1070,10 @@ MonitorMain(
 done:
     (VOID) RegDeleteTree(Context->RequestKey, NULL);
 
+    free(Context->Message);
+    free(Context->Title);
     CloseHandle(Context->RequestKey);
+    free(RequestKeyName);
     CloseHandle(Context->RequestEvent);
     CloseHandle(Context->StopEvent);
 
@@ -955,6 +1087,11 @@ done:
 
     return;
 
+fail9:
+    Log("fail9");
+
+    CloseHandle(Context->RequestKey);
+
 fail8:
     Log("fail8");
 
diff --git a/src/monitor/strings.h b/src/monitor/strings.h
deleted file mode 100644
index 76ef975..0000000
--- a/src/monitor/strings.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright (c) Citrix Systems Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * *   Redistributions of source code must retain the above
- *     copyright notice, this list of conditions and the
- *     following disclaimer.
- * *   Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the
- *     following disclaimer in the documentation and/or other
- *     materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MONITOR_STRINGS_H_
-#define _MONITOR_STRINGS_H_
-
-#define        IDS_DIALOG      1
-
-#endif // _MONITOR_STRINGS_H_
diff --git a/src/monitor/strings.rc b/src/monitor/strings.rc
deleted file mode 100644
index 99d4fc1..0000000
--- a/src/monitor/strings.rc
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright (c) Citrix Systems Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * *   Redistributions of source code must retain the above
- *     copyright notice, this list of conditions and the
- *     following disclaimer.
- * *   Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the
- *     following disclaimer in the documentation and/or other
- *     materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "strings.h"
-
-STRINGTABLE
-{
-       IDS_DIALOG, "needs to restart the system to complete 
installation.\nPress 'Yes' to restart the system now or 'No' if you plan to 
restart the system later."
-}
\ No newline at end of file
diff --git a/src/monitor/xenbus_monitor.rc b/src/monitor/xenbus_monitor.rc
index 96247e3..090e5c8 100644
--- a/src/monitor/xenbus_monitor.rc
+++ b/src/monitor/xenbus_monitor.rc
@@ -54,4 +54,3 @@
 
 #include "common.ver"
 #include "messages.rc"
-#include "strings.rc"
diff --git a/src/xenbus.inf b/src/xenbus.inf
index dc4e71d..35343b2 100644
--- a/src/xenbus.inf
+++ b/src/xenbus.inf
@@ -132,6 +132,8 @@ AddReg = Monitor_Parameters, Monitor_Request
 [Monitor_Parameters]
 HKR,"Parameters",,0x00000010
 HKR,"Parameters","RequestKey",0x00000000,%RequestKey%
+HKR,"Parameters","DialogTitle",0x00000000,%DialogTitle%
+HKR,"Parameters","DialogMessage",0x00000000,%DialogMessage%
 
 [Monitor_Request]
 HKLM,%RequestKey% ,,0x00000010
@@ -159,6 +161,8 @@ XenFiltName="@PRODUCT_NAME@ Generic Bus Filter"
 MonitorName="@PRODUCT_NAME@ PV Driver Monitor"
 MonitorDesc="Provides support for @PRODUCT_NAME@ PV drivers"
 RequestKey="SOFTWARE\@VENDOR_NAME@\@PRODUCT_NAME@\PV Driver Monitor\Request"
+DialogTitle="@PRODUCT_NAME@"
+DialogMessage="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."
 
 SERVICE_BOOT_START=0x0 
 SERVICE_SYSTEM_START=0x1 
diff --git a/vs2012/xenbus_monitor/xenbus_monitor.vcxproj 
b/vs2012/xenbus_monitor/xenbus_monitor.vcxproj
index 2d8f801..96b21ce 100644
--- a/vs2012/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2012/xenbus_monitor/xenbus_monitor.vcxproj
@@ -37,7 +37,7 @@
       <RuntimeLibrary 
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      
<AdditionalDependencies>wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      
<AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <ResourceCompile>
       
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
diff --git a/vs2013/xenbus_monitor/xenbus_monitor.vcxproj 
b/vs2013/xenbus_monitor/xenbus_monitor.vcxproj
index 5575c7e..edb0c50 100644
--- a/vs2013/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2013/xenbus_monitor/xenbus_monitor.vcxproj
@@ -37,7 +37,7 @@
       <RuntimeLibrary 
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      
<AdditionalDependencies>wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      
<AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <ResourceCompile>
       
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

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