Open19

script コマンド

hzuikahzuika

log_write で実際の書き込みが行われていそう

log_write の定義

4番目の引数 obuf を log->fp に書き込む

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L451-L509

log->format によって,書き込み方が異なる

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L465

スクリプトはストリーム(stdout/stdin)の活動によって駆動されます。ストリームには、任意の数のログファイルを関連付けることが可能です。ログファイルには基本的に2つのタイプがある。「タイミングファイル(シンプルまたはマルチストリーム)とデータファイル(生)です。
同じログファイルを両方のストリームで共有することができます。例えば、マルチストリームのタイミングファイルは、標準入力と標準出力に使用することが可能です。
www.DeepL.com/Translator(無料版)で翻訳しました。

ふつうは SCRIPT_FMT_RAW なのだと思う

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L91-L104

log_write 内の fwrite_all で書き込む

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L466-L474

log_write は log_stream_activity から呼ばれる

hzuikahzuika

callback_log_stream_activity の定義

stdin → command と,
command → stdout , log の二か所で呼ばれている

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L663-L695

callback_log_stream_activity は main の中で, struct ul_pty_callbacks 構造体の log_stream_activity 関数ポインタに格納している

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/term-utils/script.c#L935

hzuikahzuika

ul_pty_callbacks 構造体の定義

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/include/pty-session.h#L17-L64

log_stream_activity は master か 標準入力のアクティビティで実行

引数2: ファイルディスクリプタ
引数3: データのバッファ
引数4: データのサイズ

https://github.com/util-linux/util-linux/blob/6ed644fbf4869a7e042826900eff531cf6660cfb/include/pty-session.h#L45-L51