Skip to content

Conversation

@RJVB
Copy link

@RJVB RJVB commented Jan 9, 2019

This is the PR announced in issue #13 . It's become a bit of a catch-all for a number of more or less (un)related changes:

  • add support for an optional sync-on-exit (end sync). Set EATMYDATA_END_SYNC=1 to do this only in the application launched by the user, set it EATMYDATA_END_SYNC=2 to do it in every child process too (that does slow things down if the child processes each do only tiny bits of work).
  • verbose mode: Set EATMYDATA_VERBOSE to print out the number of syncs and sync modes that were swallowed. Uses a simple counter without any thread-safeties because there's nothing crucial to the feature and I don't want to introduce locks in overloads of functions that have to remain signal-safe.
  • Mac-related fixes, making the code build and the scripts run on 10.9 (and up, presumably).

And, a bit stupidly: a source code reformat.

RJVB added 6 commits January 7, 2019 23:23
Adds an exit() overload and a library destructor routine
that call libc_sync() when syncs have been eaten and the
EATMYDATA_END_SYNC env. var is set. They also print how
many syncs were swallowed, if EATMYDATA_VERBOSE is set.

Committed from host : Portia.local
Committed from host : Portia.local
let the OS deallocate progName and cache nosyncs before printing,
all to prevent race conditions and print something that's less
likely to be wrong.

Committed from host : Bola
Set EATMYDATA_END_SYNC=1 to sync only when the 1st eatmydata instance
exits (libeatmydata reads and unsets the variable internally). Use
EATMYDATA_END_SYNC=2 to present the variable and cause an end-sync in
each child process.

Also, reformat the source.

Committed from host : Portia.local
EATMYDATA_END_SYNC=-1 will disable eating syncs after exit() or _exit()
have been called, allowing the libc runtime to do any of the explicit
syncs it wants to do. A new close() overload also starts doing explicit
fsync's on the descriptors it has to close.

Potential because I haven't yet seen it do any syncs or NOT eat any.

Committed from host : Bola
Comment on lines +42 to +45
exe="`which "${cmd}"`"
if [ -x "$exe" ] ;then
ok="yes"
else
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, the whole point of the path-searching logic here is that you can't use which to look up the command in question — which will almost certainly return your own location, in the case where some other executable's name is symlinked to eatmydata.

i.e.: If you have $HOME/bin/git symlinked to /usr/bin/eatmydata, because you want to use libeatmydata on /usr/bin/git, then assuming $HOME/bin/ is earlier in your $PATH you can just run git clone https://github.com/stewartsmith/libeatmydata and it'll launch /usr/bin/eatmydata with $1 set to git and $2 set to https://github.com/stewartsmith/libeatmydata.

But a which git will ALWAYS RETURN $HOME/bin/git in that scenario, which is the exact thing the "avoid loops with self" code is trying to prevent.

In order to find /usr/bin/git as the real executable to launch, you have to search the $PATH yourself instead of using which.

I don't know how universally supported it is, but if the available which implementation supports the -a flag, using which -a "$cmd" (to get all commands matching $cmd on the $PATH) could be a useful way to avoid walking the $PATH manually. But each of the returned executables would still have to be checked against "`readlink -f "$exe"`" != "$self", because the first item would be expected to fail that test.

@RJVB
Copy link
Author

RJVB commented Feb 6, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants