The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: crossd@gmail.com (Dan Cross)
Subject: [TUHS] /bin/true (was basic tools / Universal Unix)
Date: Sun, 22 Oct 2017 21:11:25 -0400	[thread overview]
Message-ID: <CAEoi9W4e_jp3LQ-haRp037v8u=AgzH4KDfj60+bFq1CxHhHwtQ@mail.gmail.com> (raw)
In-Reply-To: <201710222300.v9MN0dN4135736@tahoe.cs.Dartmouth.EDU>

On Sun, Oct 22, 2017 at 7:00 PM, Doug McIlroy <doug at cs.dartmouth.edu> wrote:
>> macOS requires you to have a data section aligned to 4K, even if you
>> don't use it. The resulting binary is a little over 8K; again, mostly
>> zeros.
>
> Not quite. The classic empty executable file for /bin/true works
> on OS X. That is not just a clever trick;it's a natural consequence
> of Kernighan's ancient prrecept: do nothing gracefully. Conceivably
> the 4K data section is, too--if the page has no physical presence
> until it is accessed.

Oh sure! Sorry; the mention of the 4K data section was meant to be
orthogonal to the empty-shell file thing. However, one still cannot
'exec' an empty shell script, even on OS X:

: hurricane; mkdir t
: hurricane; cd t
/Users/dcross/t
: hurricane; touch true
: hurricane; cat>dotrue.c
int main() { execl("./true", "true", 0); write(2, "Boo\n", 4); return 1; }
: hurricane; chmod +x ./true
: hurricane; ./true
: hurricane; echo $?
0
: hurricane; make dotrue
cc     dotrue.c   -o dotrue
dotrue.c:1:14: warning: implicit declaration of function 'execl' is
invalid in C99 [-Wimplicit-function-declaration]
int main() { execl("./true", "true", 0); write(2, "Boo\n", 4); return 1; }
             ^
dotrue.c:1:42: warning: implicit declaration of function 'write' is
invalid in C99 [-Wimplicit-function-declaration]
int main() { execl("./true", "true", 0); write(2, "Boo\n", 4); return 1; }
                                         ^
2 warnings generated.
: hurricane; ./dotrue
Boo
: hurricane; echo $?
1
: hurricane; cp /usr/bin/true .
: hurricane; ./dotrue
: hurricane; echo $?
0
: hurricane; file true
true: Mach-O 64-bit executable x86_64
: hurricane; ls -l true
-rwxr-xr-x  1 dcross  eng  17760 Oct 22 21:08 true
: hurricane; cd ..
/Users/dcross
: hurricane; rm -fr t
: hurricane;

(The system-provided /usr/bin/true is >16KB!!)

        - Dan C.


  reply	other threads:[~2017-10-23  1:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-22 23:00 Doug McIlroy
2017-10-23  1:11 ` Dan Cross [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-10-19 14:52 /bin/true (was [TUHS] " Ron Natalie
2017-10-19 21:23 ` Steffen Nurpmeso
2017-10-19 21:43   ` Chet Ramey
2017-10-19 23:00     ` [TUHS] /bin/true (was " Dave Horsfall
2017-10-19 23:14       ` Grant Taylor
2017-10-19 23:23         ` Lyndon Nerenberg
2017-10-19 23:27         ` Kurt H Maier
2017-10-22  4:18           ` Dave Horsfall
2017-10-20 12:10       ` Chet Ramey
2017-10-19 21:43 ` /bin/true (was [TUHS] " Dave Horsfall
2017-10-19 22:04   ` Ronald Natalie
2017-10-19 23:25     ` [TUHS] /bin/true (was " Dave Horsfall
     [not found] ` <CAEoi9W7YZ7YXUip0JTMGip3Nd0czgdjqRCMRcK2GYmDJsckuDg@mail.gmail.com>
     [not found]   ` <CAEoi9W4zdJ3+RXjK5-5rAJ6rwx_0kx6N-bn1U61=txJGyLT_mw@mail.gmail.com>
2017-10-20  1:27     ` Dan Cross
2017-10-20  1:31       ` Lyndon Nerenberg
2017-10-20  2:05         ` Ronald Natalie
2017-11-28 16:21 ` Nemo
2017-11-28 17:56   ` Warner Losh
2017-11-28 18:26     ` Dan Cross
2017-11-28 18:41       ` Warner Losh
2017-11-28 19:09         ` Dan Cross
2017-11-28 20:34           ` Clem Cole
2017-11-28 22:42           ` Ralph Corderoy
2017-11-28 18:34     ` Bakul Shah
2017-11-28 23:25     ` Ralph Corderoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEoi9W4e_jp3LQ-haRp037v8u=AgzH4KDfj60+bFq1CxHhHwtQ@mail.gmail.com' \
    --to=crossd@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).