From nobody Fri Apr 28 02:05:55 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q6wts68J5z47mZj for ; Fri, 28 Apr 2023 02:05:57 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q6wts4X82z3wdq for ; Fri, 28 Apr 2023 02:05:57 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-3f178da21b2so94240235e9.1 for ; Thu, 27 Apr 2023 19:05:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682647556; x=1685239556; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=at2UFgolcSOIFEHyvC12+x8UZem7VeA1uQF1gUYHDYs=; b=Q1hK3takoPxfPoBdLs12LjPNPegDfcLFLWOKDuOun9dTj5gzV5PiNl7XeY2ItOYlh9 WSz+834KTAiOZLtKZJqT8hcnlTklQbRyRYxYJIgU8wjybT4jzv2nEOjx0SMj/dL6MJFF vZzRA9QrQsYFOOPkXSZTQf2WEUOEycV19UOsJr9h5cCGcXCSd3fnPr7zU/KVlAtty50u fyxCQHO93vhE/OrtRmgfRfYlb/jJryeeNe/bDR5LCQ+I89WYRR93qzS26OJp+cOpHwX5 O4eSpUjWsC/YMs+cK1zMBOhZjhj51afL5Jh6BwSXFbmTIXkhfRMNOB4SNwdNCYuqhRUp M/Dw== X-Gm-Message-State: AC+VfDzacmyD07NrvNHqREOkZgY6l7Yj7XI8YZkY1w/V4EKaZ+MJ7voX EDI/E+xN+uP5nTDLv8YswG7FGg== X-Google-Smtp-Source: ACHHUZ4WM45C2IdOZ64VA0L29+LQDaJTtNvCm3KjzGqZdl3dYhutXTRxdFPzzD4qsWaSbq6ysNqgng== X-Received: by 2002:a05:6000:50f:b0:2f6:9bc4:76f1 with SMTP id a15-20020a056000050f00b002f69bc476f1mr2599397wrf.1.1682647556103; Thu, 27 Apr 2023 19:05:56 -0700 (PDT) Received: from smtpclient.apple ([131.111.5.246]) by smtp.gmail.com with ESMTPSA id m18-20020adffa12000000b003047297a5e8sm13161977wrr.54.2023.04.27.19.05.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Apr 2023 19:05:55 -0700 (PDT) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: 1808b5577da8 - main - Add efiwake tool From: Jessica Clarke In-Reply-To: <202304280129.33S1TwGg075232@gitrepo.freebsd.org> Date: Fri, 28 Apr 2023 03:05:55 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <797349B7-33E3-4C4A-92D9-F482B3159082@freebsd.org> References: <202304280129.33S1TwGg075232@gitrepo.freebsd.org> To: Konstantin Belousov X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Rspamd-Queue-Id: 4Q6wts4X82z3wdq X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 28 Apr 2023, at 02:29, Konstantin Belousov wrote: >=20 > The branch main has been updated by kib: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D1808b5577da8d3fcffc70973afef250f= 428f9381 >=20 > commit 1808b5577da8d3fcffc70973afef250f428f9381 > Author: Johannes Totz > AuthorDate: 2023-04-26 16:16:55 +0000 > Commit: Konstantin Belousov > CommitDate: 2023-04-28 01:28:51 +0000 >=20 > Add efiwake tool Hi, This has quite a few style(9) violations. Please fix them or work with the author to get them fixed. > Reviewed by: kib > MFC after: 1 week > Differential revision: https://reviews.freebsd.org/D36714 > --- > usr.sbin/Makefile | 2 +- > usr.sbin/efiwake/Makefile | 13 +++++ > usr.sbin/efiwake/efiwake.c | 134 = +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 148 insertions(+), 1 deletion(-) >=20 > diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile > index 9fa1dc05a1cc..fb707e515eaa 100644 > --- a/usr.sbin/Makefile > +++ b/usr.sbin/Makefile > @@ -129,7 +129,7 @@ SUBDIR.${MK_OPENSSL}+=3D certctl > .endif > SUBDIR.${MK_CXGBETOOL}+=3D cxgbetool > SUBDIR.${MK_DIALOG}+=3D bsdconfig > -SUBDIR.${MK_EFI}+=3D efivar efidp efibootmgr efitable > +SUBDIR.${MK_EFI}+=3D efivar efidp efibootmgr efitable efiwake > .if ${MK_OPENSSL} !=3D "no" > SUBDIR.${MK_EFI}+=3D uefisign > .endif > diff --git a/usr.sbin/efiwake/Makefile b/usr.sbin/efiwake/Makefile > new file mode 100644 > index 000000000000..ed2292f8a3ac > --- /dev/null > +++ b/usr.sbin/efiwake/Makefile > @@ -0,0 +1,13 @@ > +# $FreeBSD$ > + > +PACKAGE=3D efi-tools > + > +PROG=3D efiwake > +MAN=3D > + > +SRCS=3D efiwake.c > + > +EFIBOOT=3D${SRCTOP}/stand/efi > +CFLAGS+=3D-I${EFIBOOT}/include > + > +.include > diff --git a/usr.sbin/efiwake/efiwake.c b/usr.sbin/efiwake/efiwake.c > new file mode 100644 > index 000000000000..67497e2ede03 > --- /dev/null > +++ b/usr.sbin/efiwake/efiwake.c > @@ -0,0 +1,134 @@ > +/*- > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > + * > + * Copyright (c) 2023 Johannes Totz > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. 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 AUTHOR 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 AUTHOR 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include Headers don=E2=80=99t follow correct grouping. > + > +static void usage(void) New line after static void needed. > +{ > + printf("Usage:\n" stderr? > + " efiwake -- print out current EFI = time and wake time\n" > + " efiwake -d -- disable wake time\n" > + " efiwake -e yyyy-mm-ddThh:mm:ss -- enable wake time\n" > + ); > + > + exit(EX_USAGE); > +} > + > +int main(int argc, char **argv) New line after int needed. > +{ > + struct efi_waketime_ioc waketime; > + int error, ch; > + bool enable =3D false, disable =3D false; > + > + memset(&waketime, 0, sizeof(waketime)); > + > + while ((ch =3D getopt(argc, argv, "de:")) !=3D -1) { > + switch (ch) { > + case 'd': > + disable =3D true; > + break; > + case 'e': > + if (sscanf(optarg, > + "%hu-%02hhu-%02hhuT%02hhu:%02hhu:%02hhu", > + &waketime.waketime.tm_year, = &waketime.waketime.tm_mon, > + &waketime.waketime.tm_mday, = &waketime.waketime.tm_hour, > + &waketime.waketime.tm_min, = &waketime.waketime.tm_sec) > + !=3D 6) { > + usage(); > + } > + enable =3D true; > + break; > + case '?': > + default: > + usage(); > + } > + } > + argc -=3D optind; > + argv +=3D optind; > + > + if (argc > 0) > + usage(); > + if (disable && enable) > + usage(); > + > + int efi_fd =3D open("/dev/efi", O_RDWR); These all need to be at the start of the block. > + if (efi_fd < 0) > + err(EX_OSERR, "cannot open /dev/efi"); > + > + struct efi_tm now; > + error =3D ioctl(efi_fd, EFIIOC_GET_TIME, &now); > + if (error !=3D 0) > + err(EX_OSERR, "cannot get EFI time"); > + > + /* EFI's time can be different from kernel's time. */ > + printf("Current EFI time: %u-%02u-%02uT%02u:%02u:%02u\n", > + now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, = now.tm_min, > + now.tm_sec); > + > + if (disable) { > + /* It's tempting to preserve the current timer value. /* needs to be on its own line. Regards, Jess > + * However, wonky EFI implementations sometimes return = bogus > + * dates for the wake timer and would then fail = disabling it > + * here. > + * A safe timer value is the current EFI time. > + */ > + waketime.waketime =3D now; > + waketime.enabled =3D 0; > + error =3D ioctl(efi_fd, EFIIOC_SET_WAKETIME, &waketime); > + if (error !=3D 0) > + err(EX_OSERR, "cannot disable EFI wake time"); > + } > + if (enable) { > + waketime.enabled =3D 1; > + error =3D ioctl(efi_fd, EFIIOC_SET_WAKETIME, &waketime); > + if (error !=3D 0) > + err(EX_OSERR, "cannot enable EFI wake time"); > + } > + > + /* Confirm to user what the wake time has been set to. */ > + error =3D ioctl(efi_fd, EFIIOC_GET_WAKETIME, &waketime); > + if (error !=3D 0) > + err(EX_OSERR, "cannot get EFI wake time"); > + > + printf("EFI wake time: %u-%02u-%02uT%02u:%02u:%02u; enabled=3D%i, = pending=3D%i\n", > + waketime.waketime.tm_year, waketime.waketime.tm_mon, > + waketime.waketime.tm_mday, waketime.waketime.tm_hour, > + waketime.waketime.tm_min, waketime.waketime.tm_sec, > + waketime.enabled, waketime.pending); > + > + close(efi_fd); > + return (0); > +}