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

Re: [PATCH 2/5] Refactor monitor.c registry enumeration


  • To: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>, "win-pv-devel@xxxxxxxxxxxxxxxxxxxx" <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Fri, 13 Feb 2026 13:45:44 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yIT5GLk5rW3fDZNSDqCGIzrh7GeleWQuUScJs++7TqY=; b=AYgrau991Koz4l8xgrHlth/dhTAM/wiBwuwFpYs+qTpvKoHi/Tk/kj7nLM4aovU/fnIkX3IVbWPIjxBvuZTYuwFDKNAgLy5YuQYc05Grb94dn9VXp8mqvScoKnzOfbJr6gIQKcEEdLBhLylTp6tQbNvx+4nqoilRjqjcgrJ4H2zna3l0cO02rHxln9GT2/Sl0IcZ8Vtj97nxTrxdtV0Z8+K+wYR0eXq3FPY71IPax2pi528N33K7GwjcT91QKaUp7N4z19C4H7SoCGUzlp7CMIdWU9uwbxDbWC5EL5AiHZ4VkxeXGDKH7CQ8GQGhLSPD3SJVHPJgXMBnugzk59J/1g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SuHRs7iW3aSJvnuTDDc2vc5Ld0DYQYbYsZOkOI+Qwl6p5pIJ10TzabkMGgrCBLCC7sa+hqIL2c9y6w+GM/3sFR1LONPLeJuCMtFA7MktB8M+jM2QQ9U8ZM86mlFCBmJhtTRPUlAGJRo/MXdg5/B67Zvwh3KAKheaJ51VF+zF7y9IxPXnRSXaIaWEFaL5hMD8VXX/bFxXm8kkBFu3KO7n/cQQ4nGJ2XggXqv2x4K5FAkYPqnu9cIryAJs/1H9r8K5WTt1sUzRiut+H3B0sRWLJKYOGCa7RZJxO4z1Gryyzm4mtyddNl2CEzU6q3fK/K6p9EIKtshAKwG2MvsfC1gubQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Delivery-date: Fri, 13 Feb 2026 13:45:52 +0000
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHcl0T1V8TQgvlWOkKV6i1uSCIc1rV9dbeAgAM5fsY=
  • Thread-topic: [PATCH 2/5] Refactor monitor.c registry enumeration

Since the change to remove StartOverride values moved from registry enumeration
to using SetupApi, this patch wasnt immediately required
I dropped this patch, to focus on the cleanup

Owen

________________________________________
From: win-pv-devel <win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx> on behalf of Tu 
Dinh <ngoc-tu.dinh@xxxxxxxxxx>
Sent: 11 February 2026 12:29 PM
To: Owen Smith; win-pv-devel@xxxxxxxxxxxxxxxxxxxx
Subject: Re: [PATCH 2/5] Refactor monitor.c registry enumeration

Hi,

On 06/02/2026 09:45, Owen Smith wrote:
> Move registry enumeration code into a function, using a callback that is 
> called
> for each sub key of the specified key.
>
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>

Could you rebase this patch in your next series? I haven't had the time
to look at this in detail.

Thanks,

> ---
>   src/monitor/monitor.c | 149 ++++++++++++++++++++++++++++--------------
>   1 file changed, 100 insertions(+), 49 deletions(-)
>
> diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
> index 1154de5..52311aa 100644
> --- a/src/monitor/monitor.c
> +++ b/src/monitor/monitor.c
> @@ -856,23 +856,25 @@ fail1:
>       return;
>   }
>
> -static VOID
> -CheckRequestSubKeys(
> -    VOID
> +typedef BOOLEAN(*PREGENUM_FUNC)(HKEY, PTSTR, PVOID);
> +
> +static HRESULT
> +RegEnumSubKeys(
> +    _In_ HKEY           BaseKey,
> +    _In_ PREGENUM_FUNC  Callback,
> +    _In_opt_ PVOID      Context
>       )
>   {
> -    PMONITOR_CONTEXT    Context = &MonitorContext;
>       DWORD               SubKeys;
>       DWORD               MaxSubKeyLength;
>       DWORD               SubKeyLength;
>       PTSTR               SubKeyName;
>       DWORD               Index;
> -    HKEY                SubKey;
>       HRESULT             Error;
>
>       Log("====>");
>
> -    Error = RegQueryInfoKey(Context->RequestKey,
> +    Error = RegQueryInfoKey(BaseKey,
>                               NULL,
>                               NULL,
>                               NULL,
> @@ -896,14 +898,10 @@ CheckRequestSubKeys(
>           goto fail2;
>
>       for (Index = 0; Index < SubKeys; Index++) {
> -        DWORD   Length;
> -        DWORD   Type;
> -        DWORD   Reboot;
> -
>           SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
>           memset(SubKeyName, 0, SubKeyLength);
>
> -        Error = RegEnumKeyEx(Context->RequestKey,
> +        Error = RegEnumKeyEx(BaseKey,
>                                Index,
>                                (LPTSTR)SubKeyName,
>                                &SubKeyLength,
> @@ -918,59 +916,112 @@ CheckRequestSubKeys(
>
>           Log("%s", SubKeyName);
>
> -        Error = RegOpenKeyEx(Context->RequestKey,
> -                             SubKeyName,
> -                             0,
> -                             KEY_READ,
> -                             &SubKey);
> -        if (Error != ERROR_SUCCESS)
> -            continue;
> +        if (!Callback(BaseKey, SubKeyName, Context))
> +            break;
> +    }
>
> -        Length = sizeof (DWORD);
> -        Error = RegQueryValueEx(SubKey,
> -                                "Reboot",
> -                                NULL,
> -                                &Type,
> -                                (LPBYTE)&Reboot,
> -                                &Length);
> -        if (Error != ERROR_SUCCESS ||
> -            Type != REG_DWORD)
> -            goto loop;
> +    free(SubKeyName);
>
> -        if (Reboot != 0)
> -            goto found;
> +    return ERROR_SUCCESS;
>
> -loop:
> -        RegCloseKey(SubKey);
> +fail3:
> +    Log("fail3");
> +
> +    free(SubKeyName);
> +
> +fail2:
> +    Log("fail2");
> +
> +fail1:
> +    Error = GetLastError();
> +
> +    {
> +        PTSTR   Message;
> +        Message = GetErrorMessage(Error);
> +        Log("fail1 (%s)", Message);
> +        LocalFree(Message);
>       }
>
> -    Error = RegDeleteValue(Context->ParametersKey,
> -                           "RebootCount");
> -    if (Error == ERROR_SUCCESS)
> -        (VOID) RegFlushKey(Context->ParametersKey);
> +    return Error;
> +}
>
> -    goto done;
> +static BOOLEAN
> +CheckRequestSubKey(
> +    _In_ HKEY           BaseKey,
> +    _In_ PTSTR          SubKeyName,
> +    _In_opt_ PVOID      Context
> +    )
> +{
> +    DWORD               Length;
> +    DWORD               Reboot;
> +    DWORD               Type;
> +    HKEY                SubKey;
> +    HRESULT             Error;
> +    PBOOLEAN            Found = (PBOOLEAN)Context;
>
> -found:
> -    RegCloseKey(SubKey);
> +    Error = RegOpenKeyEx(BaseKey,
> +                         SubKeyName,
> +                         0,
> +                         KEY_READ,
> +                         &SubKey);
> +    if (Error != ERROR_SUCCESS)
> +        return TRUE;
> +
> +    Length = sizeof (DWORD);
> +    Error = RegQueryValueEx(SubKey,
> +                            "Reboot",
> +                            NULL,
> +                            &Type,
> +                            (LPBYTE)&Reboot,
> +                            &Length);
> +    if (Error != ERROR_SUCCESS ||
> +        Type != REG_DWORD)
> +        goto loop;
> +
> +    if (Reboot == 0)
> +        goto loop;
>
> -    if (!Context->RebootRequestedBy)
> +    if (Found != NULL)
> +        *Found = TRUE;
> +
> +    if (!MonitorContext.RebootRequestedBy)
>           TryAutoReboot(SubKeyName);
>
> -done:
> -    free(SubKeyName);
> +loop:
> +    RegCloseKey(SubKey);
>
> -    Log("<====");
> +    return (Found != NULL) ? !(*Found) : TRUE;
> +}
>
> -    return;
> +static VOID
> +CheckRequestSubKeys(
> +    VOID
> +    )
> +{
> +    PMONITOR_CONTEXT    Context = &MonitorContext;
> +    BOOLEAN             Found;
> +    HRESULT             Error;
>
> -fail3:
> -    Log("fail3");
> +    Log("====>");
>
> -    free(SubKeyName);
> +    Found = FALSE;
>
> -fail2:
> -    Log("fail2");
> +    Error = RegEnumSubKeys(Context->RequestKey,
> +                           CheckRequestSubKey,
> +                           &Found);
> +    if (Error != ERROR_SUCCESS)
> +        goto fail1;
> +
> +    if (!Found) {
> +        Error = RegDeleteValue(Context->ParametersKey,
> +                               "RebootCount");
> +        if (Error == ERROR_SUCCESS)
> +            (VOID) RegFlushKey(Context->ParametersKey);
> +    }
> +
> +    Log("<====");
> +
> +    return;
>
>   fail1:
>       Error = GetLastError();



--
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®.