From nobody Tue Feb 10 00:39:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1669669147; cv=none; d=zohomail.com; s=zohoarc; b=LMrp+1QyAkmF6uDjxslFOyxhIDOs8Szd4XUvrwsb5nalvEg8MrJgkbI99j3t3Oo6nY3KUNwxoN4mj3T3Eu8booaLY0lWdVGwkQAPVLt0ThX8cZndQtJGZX+I5nl3YCAn5d/mXaZkDuVC0NbcXZ9wspnB7UdjHP2FE7KHJl6acq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669669147; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PyRPjh8wPDaAfDkkbsHI/AlgXVpGS9XM7ua6uieRDrU=; b=T4NyQEaDIZYAA8ne+oqz+3GJKr9k9pblabVNfsAUZ7RZLZwqS014ybK6PyA0R8tUuX+QaO9g3GXrPJHWf0+pE8TcHzxEf44IkNN4uXfecd1t11lvbHhYr8Uft3lXeOEs/32ls/GTGE/cRr4CsSyx2KWDza/L6PIJ4NOzCtMqKeg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669669147196874.9908007927444; Mon, 28 Nov 2022 12:59:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozlD2-0000be-9Z; Mon, 28 Nov 2022 15:58:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozjG3-0003fX-S5 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 13:53:35 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozjG1-0003To-PB for qemu-devel@nongnu.org; Mon, 28 Nov 2022 13:53:35 -0500 Received: from [192.168.16.189] (helo=roughy.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1ozjFn-00D7Sg-Pk; Mon, 28 Nov 2022 19:53:19 +0100 To: qemu-devel@nongnu.org Cc: andrey.drobyshev@virtuozzo.com, den@virtuozzo.com, yur@openvz.org Subject: [PATCH 1/2] qga-win: add logging to Windows event log Date: Mon, 28 Nov 2022 20:54:02 +0200 Message-Id: <20221128185403.447817-2-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221128185403.447817-1-andrey.drobyshev@virtuozzo.com> References: <20221128185403.447817-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 28 Nov 2022 15:58:31 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Andrey Drobyshev From: Andrey Drobyshev via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1669669149270100005 Content-Type: text/plain; charset="utf-8" This commit allows QGA to write to Windows event log using Win32 API's ReportEvent() [1], much like syslog() under *nix guests. In order to generate log message definitions we use a very basic message text file [2], so that every QGA's message gets ID 1. The tools "windmc" and "windres" respectively are used to generate ".rc" file and COFF object file, and then the COFF file is linked into qemu-ga.exe. [1] https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-= reporteventa [2] https://learn.microsoft.com/en-us/windows/win32/eventlog/message-text-f= iles Originally-by: Yuri Pudgorodskiy Signed-off-by: Andrey Drobyshev --- configure | 3 +++ qga/installer/qemu-ga.wxs | 5 +++++ qga/main.c | 15 ++++++++++++--- qga/meson.build | 19 ++++++++++++++++++- qga/messages-win32.mc | 9 +++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 qga/messages-win32.mc diff --git a/configure b/configure index 26c7bc5154..789a4f6cc9 100755 --- a/configure +++ b/configure @@ -372,6 +372,7 @@ smbd=3D"$SMBD" strip=3D"${STRIP-${cross_prefix}strip}" widl=3D"${WIDL-${cross_prefix}widl}" windres=3D"${WINDRES-${cross_prefix}windres}" +windmc=3D"${WINDMC-${cross_prefix}windmc}" pkg_config_exe=3D"${PKG_CONFIG-${cross_prefix}pkg-config}" query_pkg_config() { "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@" @@ -2561,6 +2562,7 @@ if test "$skip_meson" =3D no; then echo "strip =3D [$(meson_quote $strip)]" >> $cross echo "widl =3D [$(meson_quote $widl)]" >> $cross echo "windres =3D [$(meson_quote $windres)]" >> $cross + echo "windmc =3D [$(meson_quote $windmc)]" >> $cross if test "$cross_compile" =3D "yes"; then cross_arg=3D"--cross-file config-meson.cross" echo "[host_machine]" >> $cross @@ -2667,6 +2669,7 @@ preserve_env SMBD preserve_env STRIP preserve_env WIDL preserve_env WINDRES +preserve_env WINDMC =20 printf "exec" >>config.status for i in "$0" "$@"; do diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index 73ce2c4965..d9567836f3 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -110,6 +110,11 @@ + + + + diff --git a/qga/main.c b/qga/main.c index b3580508fa..10314dfe5d 100644 --- a/qga/main.c +++ b/qga/main.c @@ -82,6 +82,7 @@ struct GAState { bool logging_enabled; #ifdef _WIN32 GAService service; + HANDLE event_log; HANDLE wakeup_event; #endif bool delimit_response; @@ -324,13 +325,14 @@ static void ga_log(const gchar *domain, GLogLevelFlag= s level, } =20 level &=3D G_LOG_LEVEL_MASK; -#ifndef _WIN32 if (g_strcmp0(domain, "syslog") =3D=3D 0) { +#ifndef _WIN32 syslog(LOG_INFO, "%s: %s", level_str, msg); - } else if (level & s->log_level) { #else - if (level & s->log_level) { + ReportEvent(s->event_log, EVENTLOG_INFORMATION_TYPE, + 0, 1, NULL, 1, 0, &msg, NULL); #endif + } else if (level & s->log_level) { g_autoptr(GDateTime) now =3D g_date_time_new_now_utc(); g_autofree char *nowstr =3D g_date_time_format(now, "%s.%f"); fprintf(s->log_file, "%s: %s: %s\n", nowstr, level_str, msg); @@ -1286,6 +1288,13 @@ static GAState *initialize_agent(GAConfig *config, i= nt socket_activation) g_debug("Guest agent version %s started", QEMU_FULL_VERSION); =20 #ifdef _WIN32 + s->event_log =3D RegisterEventSource(NULL, "qemu-ga"); + if (!s->event_log) { + g_autofree gchar *errmsg =3D g_win32_error_message(GetLastError()); + g_critical("unable to register event source: %s", errmsg); + return NULL; + } + /* On win32 the state directory is application specific (be it the def= ault * or a user override). We got past the command line parsing; let's cr= eate * the directory (with any intermediate directories). If we run into an diff --git a/qga/meson.build b/qga/meson.build index 3cfb9166e5..1ff159edc1 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -98,7 +98,24 @@ if targetos =3D=3D 'windows' endif endif =20 -qga =3D executable('qemu-ga', qga_ss.sources(), +qga_objs =3D [] +if targetos =3D=3D 'windows' + windmc =3D find_program('windmc', required: true) + windres =3D find_program('windres', required: true) + + msgrc =3D custom_target('messages-win32.rc', + input: 'messages-win32.mc', + output: ['messages-win32.rc', 'MSG00409.bin', 'mes= sages-win32.h'], + command: [windmc, '-h', '@OUTDIR@', '-r', '@OUTDIR= @', '@INPUT@']) + msgobj =3D custom_target('messages-win32.o', + input: msgrc[0], + output: 'messages-win32.o', + command: [windres, '-I', '@OUTDIR@', '-o', '@OUTP= UT@', '@INPUT@']) + + qga_objs =3D [msgobj] +endif + +qga =3D executable('qemu-ga', qga_ss.sources() + qga_objs, link_args: qga_libs, dependencies: [qemuutil, libudev], install: true) diff --git a/qga/messages-win32.mc b/qga/messages-win32.mc new file mode 100644 index 0000000000..e21019cebe --- /dev/null +++ b/qga/messages-win32.mc @@ -0,0 +1,9 @@ +LanguageNames=3D( + English=3D0x409:MSG00409 +) + +MessageId=3D1 +SymbolicName=3DQEMU_GA_EVENTLOG_GENERAL +Language=3DEnglish +%1 +. --=20 2.38.1