Bug 10001

Summary: command-line tcdrain utility needed
Product: Busybox Reporter: Philip Prindeville <philipp>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: enhancement CC: busybox-cvs, philipp
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Philip Prindeville 2017-06-30 00:47:07 UTC
In some of the environments where busybox is used a lot, you have things happening like root pivots happening, the init process (pid 1) exec'ing its replacement (especially during upgrades), etc.

It's not uncommon for some of these operations to lose output (1) if they are scripted and (2) if they're running on a serial console and output is being generated faster than the serial baudrate can move bits around.

For example, imagine a script which:

(1) generates a lengthy list of (say) files being preserved across an upgrade;

(2) kills all other processes but itself and init (perhaps including the sshd which is the grandparent of this process);

(3) signals init to run (exec as a replacement) a process which pivots the root, updates the filesystem, and reboots;

(actually, that's a good description of the revamped 'sysupgrade' in LEDE).

The problem is that when (1) happens, the sshd/bash that's the parent of the script that's running, or the getty which is handling the login on a serial port which isn't /dev/console (say /dev/ttyS1) might not finish draining output before (2) happens as either disconnects the ssh session you're connected via or the getty that was the parent of your login session resets your serial port settings (including flushing buffers).

As a result, you don't get to see the output from (1) or the warnings from (2) saying "killing all other processes".

What would be nice is having a wrapper for "tcdrain(3)" like:

tcdrain [device]

which opens "device" (or uses stdout, if "device" isn't specified) and does a tcdrain() on it, then exits.

This would allow one to add an invocation to scripts like the above not-so-hypothetical sysupgrade script.

It should be trivial, and I don't think it would add a lot of size to busybox... and of course the feature could be turned off.
Comment 1 Denys Vlasenko 2017-07-04 19:16:10 UTC
What tool is used for this purpose on busybox-less systems?

I would like to avoid reinventing the wheel, if possible, but implement a solution which is compatible with other existing environments.
Comment 2 Philip Prindeville 2017-07-04 21:15:25 UTC
(In reply to Denys Vlasenko from comment #1)

There isn't any standardized tool that I know of.