]> xenbits.xensource.com Git - people/pauldu/xenbus.git/commitdiff
monitor: get dialog paramaters from the registry
authorPaul Durrant <paul.durrant@citrix.com>
Fri, 12 Aug 2016 13:39:35 +0000 (14:39 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Fri, 12 Aug 2016 13:39:35 +0000 (14:39 +0100)
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@citrix.com>
src/monitor/monitor.c
src/monitor/strings.h [deleted file]
src/monitor/strings.rc [deleted file]
src/monitor/xenbus_monitor.rc
src/xenbus.inf
vs2012/xenbus_monitor/xenbus_monitor.vcxproj
vs2013/xenbus_monitor/xenbus_monitor.vcxproj

index e2e8e2000d935a61d10d2e27191aff9a8e0fa5f9..0bfdaafdab6e382a9e51ae54ed485f3c7fb42ddd 100644 (file)
 #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 (file)
index 76ef975..0000000
+++ /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 (file)
index 99d4fc1..0000000
+++ /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
index 96247e38d300447bdf39457d23b6140561a5faf0..090e5c8c387abeab818945e571b19865b42549b8 100644 (file)
@@ -54,4 +54,3 @@
 
 #include "common.ver"
 #include "messages.rc"
-#include "strings.rc"
index dc4e71d766d34556cad9ba3812222626258eba7f..35343b21682dfbf79ad5e1ec2e9df2d2e02b1f2b 100644 (file)
@@ -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 
index 2d8f801aa38fe5b6862427a939afebe59456676a..96b21ce13475265bada239c248f63a08471dcc3b 100644 (file)
@@ -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>
index 5575c7e8f2a17b2f1c967b42ccca2fab58951ab5..edb0c502dfdf27044b5e115e279c45908fc99b4d 100644 (file)
@@ -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>