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

[XENBUS PATCH 2/2] Don't autoreboot during ES_SYSTEM_REQUIRED



Programs may set the ES_SYSTEM_REQUIRED execution state when they're
busy with some activity (media playback, downloads, updates etc.)

We don't want to autoreboot in these situations.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/monitor/monitor.c                        | 12 ++++++++++++
 vs2019/xenbus_monitor/xenbus_monitor.vcxproj |  2 +-
 vs2022/xenbus_monitor/xenbus_monitor.vcxproj |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index faf1155..c9cbcc8 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -36,6 +36,8 @@
 #include <strsafe.h>
 #include <wtsapi32.h>
 #include <cfgmgr32.h>
+#include <winternl.h>
+#include <powrprof.h>
 #include <malloc.h>
 #include <assert.h>
 
@@ -473,6 +475,16 @@ TryAutoReboot(
     PTCHAR              Text;
     DWORD               TextLength;
     HRESULT             Error;
+    NTSTATUS            Status;
+    ULONG               PowerInfo;
+
+    Status = CallNtPowerInformation(SystemExecutionState,
+                                    NULL,
+                                    0,
+                                    &PowerInfo,
+                                    sizeof(PowerInfo));
+    if (Status < 0 || (PowerInfo & ES_SYSTEM_REQUIRED))
+        goto done;
 
     Length = sizeof (DWORD);
 
diff --git a/vs2019/xenbus_monitor/xenbus_monitor.vcxproj 
b/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
index 2a2c00f..047166e 100644
--- a/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
@@ -34,7 +34,7 @@
       <RuntimeLibrary 
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      
<AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
diff --git a/vs2022/xenbus_monitor/xenbus_monitor.vcxproj 
b/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
index 4d26331..0437024 100644
--- a/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
@@ -34,7 +34,7 @@
       <RuntimeLibrary 
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      
<AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
-- 
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®.