From nobody Tue Nov 26 08:34:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1709314249; cv=none; d=zohomail.com; s=zohoarc; b=N6lOOBIYnFxUfgwloYh/X4fn8ApJleOCXM8E3CpgFMhC+sVNhxYIaQEtE43blnBe9dztZjTYUe6nn0AarcGUldMlQ7ZLe9jOixnBHesAgt01+0p1+M4QcVbWZv/AOvycUzFIncM5xGuVGZ8ojshNrAEaQHH09B1DjVXSs7kJPvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314249; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rih3hdm+11U4Ol1ngr62njSzb6IySI6jIVRER8pZI5o=; b=fxhVFTEOWUlzBvZGEhdZgY4Se/S5+0Gpel7llseI1wopIxvbyDFCOws2ALaBqT+RpPGBf9Us5p2AqrSGLHOnVUosOj6sdm02j7wq55jEzQcSixPdHpdY+7a45iVNLt4H6juI48W13D1lSHb91ELCeN4f5apgagXzDVqYU1XYOPs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709314249834878.9546227770969; Fri, 1 Mar 2024 09:30:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h3-0003nn-OZ; Fri, 01 Mar 2024 12:29:09 -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 1rg6h2-0003nD-Ky for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -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 1rg6gx-0005cy-V9 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-18; Fri, 01 Mar 2024 18:28:57 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=rih3hdm+11U4Ol1ngr62njSzb6IySI6jIVRER8pZI5o=; b=qaHvazn+jvab l2Usrb+l6izivZLH6nwKa8khKQqfpC7d86ygQ6ZGNXsZkfe5aLGc1maq091CR0IMPNiiteQVXJHqY s2yzsTsC5mAu7rABaHR1xpS/v1iPrewDcEotfckKAlPyJvA0ncV9TFp5Azd2OEG/J/pGfXh20CbGV LBnBMIsgChSca1P1QJ0zmr3QlciD1DAYs/45xJd85LNi8c99hWNxQEl0jS/M058aoiGheS6A3vNFI pHvmM0Gp7/9Gcri8+JJh599tkuXdr7QbjgvHmGaOr0DctvjjJbk/jqgatdTGLa0WTATV4OqjP80as QPDmcWOiNjSoQyUClKJzUQ==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 4/7] qga/commands-posix: qmp_guest_set_time: use ga_run_command helper Date: Fri, 1 Mar 2024 19:28:55 +0200 Message-Id: <20240301172858.665135-5-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1709314250762100003 Content-Type: text/plain; charset="utf-8" There's no need to check for the existence of "/sbin/hwclock", the exec() call will do that for us. Signed-off-by: Andrey Drobyshev --- qga/commands-posix.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 003054891f..e44203a273 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -269,21 +269,9 @@ void qmp_guest_shutdown(const char *mode, Error **errp) void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) { int ret; - int status; - pid_t pid; Error *local_err =3D NULL; struct timeval tv; - static const char hwclock_path[] =3D "/sbin/hwclock"; - static int hwclock_available =3D -1; - - if (hwclock_available < 0) { - hwclock_available =3D (access(hwclock_path, X_OK) =3D=3D 0); - } - - if (!hwclock_available) { - error_setg(errp, QERR_UNSUPPORTED); - return; - } + const char *argv[] =3D {"/sbin/hwclock", has_time ? "-w" : "-s", NULL}; =20 /* If user has passed a time, validate and set it. */ if (has_time) { @@ -314,37 +302,12 @@ void qmp_guest_set_time(bool has_time, int64_t time_n= s, Error **errp) * just need to synchronize the hardware clock. However, if no time was * passed, user is requesting the opposite: set the system time from t= he * hardware clock (RTC). */ - pid =3D fork(); - if (pid =3D=3D 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - /* Use '/sbin/hwclock -w' to set RTC from the system time, - * or '/sbin/hwclock -s' to set the system time from RTC. */ - execl(hwclock_path, "hwclock", has_time ? "-w" : "-s", NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); + ga_run_command(argv, NULL, "set hardware clock to system time", + &local_err); if (local_err) { error_propagate(errp, local_err); return; } - - if (!WIFEXITED(status)) { - error_setg(errp, "child process has terminated abnormally"); - return; - } - - if (WEXITSTATUS(status)) { - error_setg(errp, "hwclock failed to set hardware clock to system t= ime"); - return; - } } =20 typedef enum { --=20 2.39.3