From owner-svn-src-all@freebsd.org Tue May 23 08:07:41 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 29578D7A907; Tue, 23 May 2017 08:07:41 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DECBB1DAF; Tue, 23 May 2017 08:07:40 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4N87dAe095352; Tue, 23 May 2017 08:07:39 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4N87d04095350; Tue, 23 May 2017 08:07:39 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201705230807.v4N87d04095350@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Tue, 23 May 2017 08:07:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r318728 - stable/11/usr.bin/resizewin X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 May 2017 08:07:41 -0000 Author: trasz Date: Tue May 23 08:07:39 2017 New Revision: 318728 URL: https://svnweb.freebsd.org/changeset/base/318728 Log: MFC rr317934: Add resizewin -z. It makes resizewin not do anything if the terminal size is already set to something other than zero. It's supposed to be called from eg /etc/profile - it's not neccessary to query terminal size when logging in over the network, because the protocol used already takes care of this, but it's neccessary when logging over a serial line. Modified: stable/11/usr.bin/resizewin/resizewin.1 stable/11/usr.bin/resizewin/resizewin.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/resizewin/resizewin.1 ============================================================================== --- stable/11/usr.bin/resizewin/resizewin.1 Tue May 23 08:06:00 2017 (r318727) +++ stable/11/usr.bin/resizewin/resizewin.1 Tue May 23 08:07:39 2017 (r318728) @@ -27,17 +27,27 @@ .\" .\" $FreeBSD$ .\" -.Dd July 9, 2016 +.Dd May 8, 2017 .Dt RESIZEWIN 1 .Os .Sh NAME .Nm resizewin .Nd update the kernel window size for the current TTY +.Sh SYNOPSIS +.Nm +.Op Fl z .Sh DESCRIPTION Query the terminal emulator window size with the .Dv TIOCSWINSZ ioctl and set the window size known by the kernel to the new values. The terminal is assumed to be VT100/ANSI compatible. +.Pp +The following options are available: +.Bl -tag -width ".Fl z" +.It Fl z +Do nothing unless the current kernel terminal size is zero. +.El +.Pp .Nm is functionally similar to .Xr resize 1 , Modified: stable/11/usr.bin/resizewin/resizewin.c ============================================================================== --- stable/11/usr.bin/resizewin/resizewin.c Tue May 23 08:06:00 2017 (r318727) +++ stable/11/usr.bin/resizewin/resizewin.c Tue May 23 08:07:39 2017 (r318728) @@ -47,20 +47,50 @@ static const char query[] = "\033[999;999H" /* Move cursor */ "\033[6n" /* Get cursor position */ "\0338"; /* Restore cursor position */ + +static void +usage(void) +{ + + fprintf(stderr, "usage: resizewin [-z]\n"); + exit(1); +} + int -main(__unused int argc, __unused char **argv) +main(int argc, char **argv) { struct termios old, new; struct winsize w; - int ret, fd, cnt, error; + int ret, fd, ch, cnt, error, zflag; char data[20]; struct timeval then, now; error = 0; + zflag = 0; + while ((ch = getopt(argc, argv, "z")) != -1) { + switch (ch) { + case 'z': + zflag = 1; + break; + case '?': + default: + usage(); + } + } + argc -= optind; + if (argc != 0) + usage(); if ((fd = open("/dev/tty", O_RDWR | O_NONBLOCK)) == -1) exit(1); + if (zflag) { + if (ioctl(fd, TIOCGWINSZ, &w) == -1) + exit(1); + if (w.ws_row != 0 && w.ws_col != 0) + exit(0); + } + /* Disable echo */ if (tcgetattr(fd, &old) == -1) exit(1);