Page MenuHomeFreeBSD

script: handle terminal resize on SIGSWINCH
ClosedPublic

Authored by kevans on Mar 1 2024, 3:46 PM.
Tags
None
Referenced Files
F82360725: D44167.id135411.diff
Sat, Apr 27, 8:58 PM
F82311986: D44167.id.diff
Sat, Apr 27, 1:38 PM
Unknown Object (File)
Sat, Apr 27, 4:31 AM
Unknown Object (File)
Sat, Apr 27, 3:42 AM
Unknown Object (File)
Sat, Apr 27, 3:13 AM
Unknown Object (File)
Fri, Apr 26, 4:42 PM
Unknown Object (File)
Fri, Apr 26, 3:12 PM
Unknown Object (File)
Fri, Apr 26, 3:49 AM

Details

Summary

This is split into two commits:

commit 8ecbf42730cae3b6b50d36f453478a1afdf0780c (HEAD -> kbsd/script)
Author: Kyle Evans <kevans@FreeBSD.org>
Date:   Fri Apr 26 11:12:00 2024 -0500

    script: handle terminal resize on SIGWINCH
    
    Add a -w flag to forward terminal resize events on to the child, which
    can be useful in some circumstances to avoid terminal corruption.
    
    Co-authored-by: Xavier Beaudouin <xavier.beaudouin@klarasystems.com>
    Sponsored by: Modirum MDPay
    Sponsored by: Klara, Inc.

commit 8e5a3c3e7b70eceb39c19655f8e2d75748ef7524
Author: Xavier Beaudouin <xavier.beaudouin@klarasystems.com>
Date:   Fri Apr 26 11:10:15 2024 -0500

    script: minor style improvements
    
    Fix some nits pointed out by checkstyle9.pl in advance of functional
    changes to script(1).

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

allanjude retitled this revision from Handle terminal resize on SIGSWINCH in /usr/bin/script Added '-w' to enable forwarding of these events follows. to Handle terminal resize on SIGSWINCH in /usr/bin/scriptAdded '-w' to enable forwarding of these events follows..Mar 1 2024, 3:49 PM
allanjude added reviewers: Klara, des, sjg.
kevans added inline comments.
usr.bin/script/script.c
80

Prevailing style in this file seems to be to dropping the explicit initialization, it'll be in .bss anyways

97

Consistency again- drop the name of the parameter

113

This should probably go up with win and whatnot, to maintain some semblance of the current size-descending -ish ordering

290

I'm wondering if there's a way for this to fail; might be better to error-check it, just to avoid TIOCWINSZ with a potentially bogus win? It may not hae actually been initialized earlier if stdin isn't a tty, though I wonder now if you can hit that scenario *and* get a SIGWINCH somewhere in there.

Not suggesting doing anything with the error, just only doing the TIOCSWINSZ call if this one returned != -1

xavier.beaudouin_klarasystems.com retitled this revision from Handle terminal resize on SIGSWINCH in /usr/bin/scriptAdded '-w' to enable forwarding of these events follows. to Handle terminal resize on SIGSWINCH in /usr/bin/script Added '-w' to enable forwarding of these events follows..Mar 4 2024, 4:02 PM

Do initialization of variables in main().
Renamed the fuction onsigwinch() into resizeit().
Check if return -1 before doing the next ioctl.

usr.bin/script/script.c
290
usr.bin/script/script.c
97

You marked this as done but didn't actually do it.

110

Should be wflg for consistency.

114
161
263
292

This needs to be unconditional, otherwise you'll keep trying (and presumably failing) every time select() fires.

xavier.beaudouin_klarasystems.com marked 4 inline comments as done.

Variable names consitency.
Move do_resize=0 out of the if to avoid trying resize. May fail one time instead of always.

xavier.beaudouin_klarasystems.com added inline comments.
usr.bin/script/script.c
97

Right... Sorry

xavier.beaudouin_klarasystems.com retitled this revision from Handle terminal resize on SIGSWINCH in /usr/bin/script Added '-w' to enable forwarding of these events follows. to script: Handle terminal resize on SIGSWINCH.Mar 5 2024, 1:48 PM
xavier.beaudouin_klarasystems.com edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Mar 5 2024, 1:51 PM
usr.bin/script/script.c
119

These still needed? The comment is lame anyway... no version, no reason, no deeper explanation.... I know you're just fixing the style, but did you try it w/o the init? It's likely for gcc 4 at this point.

269
doresize) right?

Or do window changes not fire select?

289

is a 1 second latency sufficient? See above...

usr.bin/script/script.c
269

I don't believe they do; in the common case you're probably inside select(2) and you get smacked with an EINTR after returning from the signal handler.

You could perhaps block SIGWINCH and then switch to pselect(2) to unblock it and reliably interrupt it.

usr.bin/script/script.c
119

I don't know, is there any architecture supported by FreeBSD that use gcc for building ? (sorry for the stupid question indeed).

usr.bin/script/script.c
119

Yes, but I would just remove the comment as there's no harm in initializing those variables even with clang (if the compiler can tell the initialization isn't needed, it will simply not generate code for it)

kevans updated this revision to Diff 137723.
kevans retitled this revision from script: Handle terminal resize on SIGSWINCH to script: handle terminal resize on SIGSWINCH.
kevans edited the summary of this revision. (Show Details)

Do signal handling to avoid races, other small fixes (-w to manpage, drop in some assertionsabout fm_fd to make sure it's set / unset when we expect it to be)

This revision now requires review to proceed.Fri, Apr 26, 4:18 PM
des added inline comments.
usr.bin/script/script.c
130

This should be a single-line comment between the case and the break

243

I would merge those into a single assert()

265

call me old-fashioned but I'd prefer to see these at the top

290

braces are redundant

This revision is now accepted and ready to land.Fri, Apr 26, 4:27 PM
kevans marked 2 inline comments as done.

Address review feedback

This revision now requires review to proceed.Fri, Apr 26, 4:35 PM
This revision is now accepted and ready to land.Fri, Apr 26, 4:36 PM