Skip to content

Commit dea479d

Browse files
authored
[bug] Added abs path ref. to devbox binary in wrappers (#1260)
## Summary This fixes an issue where if you install `coreutils` devbox shell in some cases gets stuck in infinite loop due this sequence of events: 1. devbox shell creates wrappers 2. wrappers try to omit wrappers from PATH and call devbox shellenv but it's unsuccessful 3. devbox call in wrappers uses a couple of util tools (like `tr`) that now have their own wrappers because of coreutils. 4. the process is never able to skip the wrappers hence showing `fork: Resource Temporarily Unavailable` I think it addresses #881 or at least a portion of it. The fix: in step 3 instead of calling devbox (launcher script in /usr/local/bin) we get the absolute path to the devbox binary and reference that directly in wrappers script. This way the launcher script is not called more than once and avoids getting stuck in infinite loop. ## How was it tested? - compile -> compiled binary is now in <path to devbox>/dist/devbox - update line 413 of launcher (/usr/local/devbox) to `local -r bin="<path to devbox>/dist/devbox"` - in an empty directory run devbox init - add `coreutils@latest` to devbox.json - run `devbox shell`
1 parent 5a44d96 commit dea479d

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

internal/wrapnix/wrapper.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,21 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error {
4949
if err != nil {
5050
return err
5151
}
52+
// get absolute path of devbox binary that the launcher script invokes
53+
// to avoid causing an infinite loop when coreutils gets installed
54+
executablePath, err := os.Executable()
55+
if err != nil {
56+
return err
57+
}
5258

5359
for _, bin := range bins {
5460
if err = createWrapper(&createWrapperArgs{
55-
devboxer: devbox,
56-
BashPath: bashPath,
57-
Command: bin,
58-
ShellEnvHash: shellEnvHash,
59-
destPath: filepath.Join(destPath, filepath.Base(bin)),
61+
devboxer: devbox,
62+
BashPath: bashPath,
63+
Command: bin,
64+
ShellEnvHash: shellEnvHash,
65+
DevboxBinaryPath: executablePath,
66+
destPath: filepath.Join(destPath, filepath.Base(bin)),
6067
}); err != nil {
6168
return errors.WithStack(err)
6269
}
@@ -67,11 +74,11 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error {
6774

6875
type createWrapperArgs struct {
6976
devboxer
70-
BashPath string
71-
Command string
72-
ShellEnvHash string
73-
74-
destPath string
77+
BashPath string
78+
Command string
79+
ShellEnvHash string
80+
DevboxBinaryPath string
81+
destPath string
7582
}
7683

7784
func createWrapper(args *createWrapperArgs) error {

internal/wrapnix/wrapper.sh.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
1919

2020
if [[ "${{ .ShellEnvHashKey }}" != "{{ .ShellEnvHash }}" ]] && [[ -z "${{ .ShellEnvHashKey }}_GUARD" ]]; then
2121
export {{ .ShellEnvHashKey }}_GUARD=true
22-
eval "$(DO_NOT_TRACK=1 devbox shellenv -c {{ .ProjectDir }})"
22+
eval "$(DO_NOT_TRACK=1 {{ .DevboxBinaryPath }} shellenv -c {{ .ProjectDir }})"
2323
fi
2424

2525
{{/*
@@ -29,6 +29,6 @@ should be in PATH.
2929

3030
DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
3131
*/ -}}
32-
eval "$(DO_NOT_TRACK=1 devbox shellenv only-path-without-wrappers)"
32+
eval "$(DO_NOT_TRACK=1 {{ .DevboxBinaryPath }} shellenv only-path-without-wrappers)"
3333

3434
exec {{ .Command }} "$@"

0 commit comments

Comments
 (0)