GithubHelp home page GithubHelp logo

Comments (3)

icarroll avatar icarroll commented on June 26, 2024

I know that at least bash caches executables on $PATH , most likely for exactly this reason.

from oil.

andychu avatar andychu commented on June 26, 2024

Yeah I just checked bash and dash. The first time they stat() everything on PATH. Then the second time they know where it is.

I will have to research the cache invalidation though. It seems like there are 2 cases:

  1. $PATH is changed. Technically you don't have to invalidate the whole cache, if the cache lists all of /bin /usr/bin/ etc. and some of them are still on $PATH.

  2. If any directory in $PATH changes (new programs can be inserted there). Before using the cache I think you have to check the timestamp on the directory to make sure it hasn't changed.

$ PATH=/bin:/usr/bin:_tmp/1 strace -e stat,execve -ff -- dash -c 'prog; prog'
execve("/bin/dash", ["dash", "-c", "prog; prog"], [/* 74 vars */]) = 0
stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/bin/prog", 0x7fff2c3fedc0)       = -1 ENOENT (No such file or directory)
stat("/usr/bin/prog", 0x7fff2c3fedc0)   = -1 ENOENT (No such file or directory)
stat("_tmp/1/prog", {st_mode=S_IFREG|0775, st_size=7, ...}) = 0
strace: Process 27141 attached
[pid 27141] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27141] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27141] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27141] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27141] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27141, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 27142 attached
[pid 27142] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27142] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27142] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27142] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27142] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27142, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++

dash does the same thing as bash AFAICT:

andy@lisa:~/git/alpine/abuild$ PATH=/bin:/usr/bin:_tmp/1 strace -e stat,execve -ff -- dash -c 'prog; prog'
execve("/bin/dash", ["dash", "-c", "prog; prog"], [/* 74 vars */]) = 0
stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/bin/prog", 0x7fff1eca4590)       = -1 ENOENT (No such file or directory)
stat("/usr/bin/prog", 0x7fff1eca4590)   = -1 ENOENT (No such file or directory)
stat("_tmp/1/prog", {st_mode=S_IFREG|0775, st_size=7, ...}) = 0
strace: Process 27152 attached
[pid 27152] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27152] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27152] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27152] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27152] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27152, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 27153 attached
[pid 27153] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27153] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27153] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27153] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27153] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27153, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++

from oil.

andychu avatar andychu commented on June 26, 2024

Released with 0.7.pre1: https://www.oilshell.org/release/0.7.pre1/

from oil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.