The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: jnc@mercury.lcs.mit.edu (Noel Chiappa)
Subject: [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards?
Date: Mon, 24 Apr 2017 20:59:15 -0400 (EDT)	[thread overview]
Message-ID: <20170425005915.1249018C0D0@mercury.lcs.mit.edu> (raw)

    > From: "Ron Natalie"

    > Actually, it's the shell that calls glob.

Yes, in the initial expansion of the command line, but V6 'rm' also uses
'glob' internally; if the '-r' flag is given, and the current name in the
command argument list is a directory, viz.:

	if ((buf->mode & 060000) == 040000) {
		if (rflg) {
			...
			execl("/etc/glob", "glob", "rm", "-r", 
					    fflg? "-f": "*", fflg? "*": p, 0);
			printf("%s: no glob\n", arg);
			exit();
			}			

(where 'p' is 0 - no idea why the writer didn't just say '"*": 0, 0').

So "rm -f foo*", where the current directory contains file 'foo0 foo1 foo2'
and directoty 'foobar', and directory 'foobar' contains 'bar0 bar1 bar2', the
first instance of 'glob' (run by the shell) expands the 'foo0 foo1 foo2 foobar'
and the second instance (run by 'rm') expands the 'bar0 bar1 bar2'.


     > Glob then invokes the command (in this case rm).

I don't totally grok 'glob', but it is prepared to exec() either the command
name, /bin/{command} or /usr/bin/{command}; but if that file is not executable
it tries feeding it to the shell, on the assumption it must be a shell command
list:
	   
	execv(file, arg);
	if (errno==ENOEXEC) {
		arg[0] = file;
		*--arg = "/bin/sh";
		execv(*arg, arg);
		}

I guess (too lazy to look) that the execv() must return a different error
number if the file doesn't exist at all, so it only tries the shell if the
file existed, but wasn't executable.

	Noel


             reply	other threads:[~2017-04-25  0:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25  0:59 Noel Chiappa [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-04-25  1:34 Noel Chiappa
2017-04-24 22:06 Noel Chiappa
2017-04-24 22:18 ` Josh Good
2017-04-24 23:23   ` Kurt H Maier
2017-04-25  0:06     ` Ron Natalie
2017-04-25  0:18       ` Kurt H Maier
2017-04-25  0:22         ` ron minnich
2017-04-25  0:24           ` Kurt H Maier
2017-04-25  0:26             ` ron minnich
2017-04-24 21:42 Josh Good
2017-04-24 21:48 ` Alec Muffett
2017-04-24 21:59   ` Arthur Krewat
2017-04-24 22:10 ` Kurt H Maier

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=20170425005915.1249018C0D0@mercury.lcs.mit.edu \
    --to=jnc@mercury.lcs.mit.edu \
    /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).