Page MenuHomeFreeBSD

script: handle terminal resize on SIGSWINCH
ClosedPublic

Authored by kevans on Mar 1 2024, 3:46 PM.
Tags
None
Referenced Files
F102016377: D44167.diff
Wed, Nov 6, 2:22 PM
Unknown Object (File)
Wed, Oct 30, 12:26 PM
Unknown Object (File)
Oct 5 2024, 10:38 AM
Unknown Object (File)
Sep 30 2024, 1:30 AM
Unknown Object (File)
Sep 30 2024, 12:58 AM
Unknown Object (File)
Sep 30 2024, 12:51 AM
Unknown Object (File)
Sep 30 2024, 12:51 AM
Unknown Object (File)
Sep 30 2024, 12:50 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 Skipped
Unit
Tests Skipped

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

98

Consistency again- drop the name of the parameter

116

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

323

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
323
usr.bin/script/script.c
98

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

113

Should be wflg for consistency.

117–118
174
279
325

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
98

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
123

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.

302
doresize) right?

Or do window changes not fire select?

322

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

usr.bin/script/script.c
302

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
123

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
123

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.Apr 26 2024, 4:18 PM
des added inline comments.
usr.bin/script/script.c
143

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

259

I would merge those into a single assert()

281

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

323

braces are redundant

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

Address review feedback

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