From d3ccf536c44f3f4171822825ca99b3bb06dad677 Mon Sep 17 00:00:00 2001 From: Phil Budne Date: Mon, 28 Mar 2016 02:07:21 -0400 Subject: [PATCH] pbsh.s: detect if stdin is a regular file using seek seek doesn't fail on special devices, but it always returns zero --- src/other/pbsh.s | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/other/pbsh.s b/src/other/pbsh.s index ad54941..2301945 100644 --- a/src/other/pbsh.s +++ b/src/other/pbsh.s @@ -36,7 +36,17 @@ maxargs=10 lac d1 sys intrp " make shell uninterruptable - sys getuid + +" see if reading from a special file + cla; sys seek; 1; 0 " try seeking stdin forward + sna " new offset non-zero? + jmp 1f " no: input is a special file (ttyin,keyboard) + dzm prompt " yes: regular file, kill prompt + cla; sys seek; 0; 0 " seek file back to start + jmp newline + +" stdin is a special file, see if superuser +1: sys getuid sma " <0? jmp newline " no lac hash " yes: superuser