From nobody Wed Feb 11 05:37:55 2026 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1648051718; cv=none; d=zohomail.com; s=zohoarc; b=X9fExqPpXicJA8stjfq1U4NMkNzcGISG/rMVskCQ5v2Zb62Hj/ZBX5zhPTczk5fbP+VkcH9mHI9hs8YDJZMVyQ8ZpMGFCh0Ouje5kzxIj9hFrTL7AazejMqtw6u/c3nfwUvM6yVkafuRRWpHcvdqJrMFOtvA5MHoJKkHC/dTDjY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648051718; h=Content-Type: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:References:Sender:Subject:To; bh=k+6taBTX171mQOsFRae/3dBnP0czW6HaVZUNNiKOkUg=; b=RVAI9qPTYxneg/ty0HBhQ2oZpUjZkiiHzuN8kG0alX4BzAe/z/YyNQXF/JEVIsfS3kF+7KYnDWd4CcHy9//Z/l3iGDuKFV1ANQka+E1IEzcWuLJ8H0JsJsL8xjrxmw9QHEQnGGQzLTlWqbf8NzAaRKTWLsmMdU2zPiObUmx+4tU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648051718879582.9608066731483; Wed, 23 Mar 2022 09:08:38 -0700 (PDT) Received: from localhost ([::1]:32954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX3XJ-0003jW-EJ for importer@patchew.org; Wed, 23 Mar 2022 12:08:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3Ng-0002wi-GV for qemu-devel@nongnu.org; Wed, 23 Mar 2022 11:58:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3Ne-0004oG-H8 for qemu-devel@nongnu.org; Wed, 23 Mar 2022 11:58:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-494-Tw9GWcJ8MIqBAOvXXYflkg-1; Wed, 23 Mar 2022 11:58:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AE651044563 for ; Wed, 23 Mar 2022 15:58:36 +0000 (UTC) Received: from localhost (unknown [10.39.208.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 218CC140241B; Wed, 23 Mar 2022 15:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648051117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+6taBTX171mQOsFRae/3dBnP0czW6HaVZUNNiKOkUg=; b=IN10XUHvCySvGtwTxnrZsQjAAJndQNNLi6ZgOou5Z6ljSd8CGDNbL7g/cW7vkZugsZvVxO 7guiah7itgIRtR2yLODDwwyIUtOb3VJnUVgTbw1lpOeHJxL9afw+j9fsUCa5sDj3HMhf9e LjRo00dULy+Bjh+RvYBmQowSBme3UEA= X-MC-Unique: Tw9GWcJ8MIqBAOvXXYflkg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 05/32] char: move qemu_openpty_raw from util/ to char/ Date: Wed, 23 Mar 2022 19:57:16 +0400 Message-Id: <20220323155743.1585078-6-marcandre.lureau@redhat.com> In-Reply-To: <20220323155743.1585078-1-marcandre.lureau@redhat.com> References: <20220323155743.1585078-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1648051720670100001 From: Marc-Andr=C3=A9 Lureau It is only needed by char-pty. Fix the code style while at it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qemu-common.h | 2 - chardev/char-pty.c | 111 +++++++++++++++++++++++++++++++++ util/qemu-openpty.c | 139 ------------------------------------------ chardev/meson.build | 4 +- util/meson.build | 1 - 5 files changed, 113 insertions(+), 144 deletions(-) delete mode 100644 util/qemu-openpty.c diff --git a/include/qemu-common.h b/include/qemu-common.h index f0fe07cd74c3..f9b3f85b8124 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -31,8 +31,6 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t c= ount) =20 #ifndef _WIN32 int qemu_pipe(int pipefd[2]); -/* like openpty() but also makes it raw; return master fd */ -int qemu_openpty_raw(int *aslave, char *pty_name); #endif =20 void cpu_exec_init_all(void); diff --git a/chardev/char-pty.c b/chardev/char-pty.c index a2d1e7c985bc..d73d8b23903d 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -197,6 +197,117 @@ static void char_pty_finalize(Object *obj) qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } =20 +#if defined HAVE_PTY_H +# include +#elif defined CONFIG_BSD +# include +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__Drag= onFly__) +# include +# else +# include +# endif +#elif defined CONFIG_SOLARIS +# include +# include +#else +# include +#endif + +#ifdef __sun__ + +#if !defined(HAVE_OPENPTY) +/* Once illumos has openpty(), this is going to be removed. */ +static int openpty(int *amaster, int *aslave, char *name, + struct termios *termp, struct winsize *winp) +{ + const char *slave; + int mfd =3D -1, sfd =3D -1; + + *amaster =3D *aslave =3D -1; + + mfd =3D open("/dev/ptmx", O_RDWR | O_NOCTTY); + if (mfd < 0) { + goto err; + } + + if (grantpt(mfd) =3D=3D -1 || unlockpt(mfd) =3D=3D -1) { + goto err; + } + + if ((slave =3D ptsname(mfd)) =3D=3D NULL) { + goto err; + } + + if ((sfd =3D open(slave, O_RDONLY | O_NOCTTY)) =3D=3D -1) { + goto err; + } + + if (ioctl(sfd, I_PUSH, "ptem") =3D=3D -1 || + (termp !=3D NULL && tcgetattr(sfd, termp) < 0)) { + goto err; + } + + *amaster =3D mfd; + *aslave =3D sfd; + + if (winp) { + ioctl(sfd, TIOCSWINSZ, winp); + } + + return 0; + +err: + if (sfd !=3D -1) { + close(sfd); + } + close(mfd); + return -1; +} +#endif + +static void cfmakeraw (struct termios *termios_p) +{ + termios_p->c_iflag &=3D + ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON= ); + termios_p->c_oflag &=3D ~OPOST; + termios_p->c_lflag &=3D ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + termios_p->c_cflag &=3D ~(CSIZE | PARENB); + termios_p->c_cflag |=3D CS8; + + termios_p->c_cc[VMIN] =3D 0; + termios_p->c_cc[VTIME] =3D 0; +} +#endif + +/* like openpty() but also makes it raw; return master fd */ +static int qemu_openpty_raw(int *aslave, char *pty_name) +{ + int amaster; + struct termios tty; +#if defined(__OpenBSD__) || defined(__DragonFly__) + char pty_buf[PATH_MAX]; +#define q_ptsname(x) pty_buf +#else + char *pty_buf =3D NULL; +#define q_ptsname(x) ptsname(x) +#endif + + if (openpty(&amaster, aslave, pty_buf, NULL, NULL) < 0) { + return -1; + } + + /* Set raw attributes on the pty. */ + tcgetattr(*aslave, &tty); + cfmakeraw(&tty); + tcsetattr(*aslave, TCSAFLUSH, &tty); + + if (pty_name) { + strcpy(pty_name, q_ptsname(amaster)); + } + + return amaster; +} + static void char_pty_open(Chardev *chr, ChardevBackend *backend, bool *be_opened, diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c deleted file mode 100644 index 427f43a76973..000000000000 --- a/util/qemu-openpty.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * qemu-openpty.c - * - * Copyright (c) 2003-2008 Fabrice Bellard - * Copyright (c) 2010 Red Hat, Inc. - * - * Wrapper function qemu_openpty() implementation. - * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), t= o deal - * in the Software without restriction, including without limitation the r= ights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN - * THE SOFTWARE. - */ - -/* - * This is not part of oslib-posix.c because this function - * uses openpty() which often in -lutil, and if we add this - * dependency to oslib-posix.o, every app will have to be - * linked with -lutil. - */ - -#include "qemu/osdep.h" -#include "qemu-common.h" - -#if defined HAVE_PTY_H -# include -#elif defined CONFIG_BSD -# include -# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__Drag= onFly__) -# include -# else -# include -# endif -#elif defined CONFIG_SOLARIS -# include -# include -#else -# include -#endif - -#ifdef __sun__ - -#if !defined(HAVE_OPENPTY) -/* Once illumos has openpty(), this is going to be removed. */ -static int openpty(int *amaster, int *aslave, char *name, - struct termios *termp, struct winsize *winp) -{ - const char *slave; - int mfd =3D -1, sfd =3D -1; - - *amaster =3D *aslave =3D -1; - - mfd =3D open("/dev/ptmx", O_RDWR | O_NOCTTY); - if (mfd < 0) - goto err; - - if (grantpt(mfd) =3D=3D -1 || unlockpt(mfd) =3D=3D -1) - goto err; - - if ((slave =3D ptsname(mfd)) =3D=3D NULL) - goto err; - - if ((sfd =3D open(slave, O_RDONLY | O_NOCTTY)) =3D=3D -1) - goto err; - - if (ioctl(sfd, I_PUSH, "ptem") =3D=3D -1 || - (termp !=3D NULL && tcgetattr(sfd, termp) < 0)) - goto err; - - *amaster =3D mfd; - *aslave =3D sfd; - - if (winp) - ioctl(sfd, TIOCSWINSZ, winp); - - return 0; - -err: - if (sfd !=3D -1) - close(sfd); - close(mfd); - return -1; -} -#endif - -static void cfmakeraw (struct termios *termios_p) -{ - termios_p->c_iflag &=3D - ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); - termios_p->c_oflag &=3D ~OPOST; - termios_p->c_lflag &=3D ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - termios_p->c_cflag &=3D ~(CSIZE|PARENB); - termios_p->c_cflag |=3D CS8; - - termios_p->c_cc[VMIN] =3D 0; - termios_p->c_cc[VTIME] =3D 0; -} -#endif - -int qemu_openpty_raw(int *aslave, char *pty_name) -{ - int amaster; - struct termios tty; -#if defined(__OpenBSD__) || defined(__DragonFly__) - char pty_buf[PATH_MAX]; -#define q_ptsname(x) pty_buf -#else - char *pty_buf =3D NULL; -#define q_ptsname(x) ptsname(x) -#endif - - if (openpty(&amaster, aslave, pty_buf, NULL, NULL) < 0) { - return -1; - } - - /* Set raw attributes on the pty. */ - tcgetattr(*aslave, &tty); - cfmakeraw(&tty); - tcsetattr(*aslave, TCSAFLUSH, &tty); - - if (pty_name) { - strcpy(pty_name, q_ptsname(amaster)); - } - - return amaster; -} diff --git a/chardev/meson.build b/chardev/meson.build index 325ba2bdb97d..664f77b8879a 100644 --- a/chardev/meson.build +++ b/chardev/meson.build @@ -12,11 +12,11 @@ chardev_ss.add(files( 'char-udp.c', 'char.c', )) -chardev_ss.add(when: 'CONFIG_POSIX', if_true: files( +chardev_ss.add(when: 'CONFIG_POSIX', if_true: [files( 'char-fd.c', 'char-parallel.c', 'char-pty.c', -)) +), util]) chardev_ss.add(when: 'CONFIG_WIN32', if_true: files( 'char-console.c', 'char-win-stdio.c', diff --git a/util/meson.build b/util/meson.build index bb0b010662d7..f8f0643318c3 100644 --- a/util/meson.build +++ b/util/meson.build @@ -16,7 +16,6 @@ if targetos =3D=3D 'freebsd' freebsd_dep =3D util endif util_ss.add(when: 'CONFIG_POSIX', if_true: [files('oslib-posix.c'), freebs= d_dep]) -util_ss.add(when: 'CONFIG_POSIX', if_true: [files('qemu-openpty.c'), util]) util_ss.add(when: 'CONFIG_POSIX', if_true: files('qemu-thread-posix.c')) util_ss.add(when: 'CONFIG_POSIX', if_true: files('memfd.c')) util_ss.add(when: 'CONFIG_WIN32', if_true: files('aio-win32.c')) --=20 2.35.1.273.ge6ebfd0e8cbb