Skip to content

Commit fbf83e3

Browse files
committed
Create /run/.toolbxenv file
It's difficult to explain to people integrating with toolbx why you have to look at /run/.toolboxenv to see if you're in a toolbx :) Create this, but leave /run/.toolboxenv around as a legacy file as well. Updates any references to the short name.
1 parent c66ddd1 commit fbf83e3

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

doc/toolbox-create.1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ container, SELinux label separation is disabled, and the host file system can
4242
be accessed by the container at /run/host. The container has access to the
4343
host's Kerberos credentials cache if it's configured to use KCM caches.
4444

45-
A Toolbx container can be identified by the `com.github.containers.toolbox`
46-
label or the `/run/.toolboxenv` file.
45+
A Toolbx container can be identified by the
46+
`com.github.containers.toolbox` label or the `/run/.toolbxenv` file.
4747

4848
The entry point of a Toolbx container is the `toolbox init-container` command
4949
which plays a role in setting up the container, along with the options passed

profile.d/toolbox.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if [ -f /run/ostree-booted ] \
4747
fi
4848

4949
if [ -f /run/.containerenv ] \
50-
&& [ -f /run/.toolboxenv ]; then
50+
&& [ -f /run/.toolbxenv ]; then
5151
[ "${BASH_VERSION:-}" != "" ] && PS1=$(printf "\[\033[35m\]⬢ \[\033[0m\]%s" "[\u@\h \W]\\$ ")
5252
[ "${ZSH_VERSION:-}" != "" ] && PS1=$(printf "\033[35m⬢ \033[0m%s" "[%n@%m]%~%# ")
5353

src/cmd/initContainer.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func initContainer(cmd *cobra.Command, args []string) error {
163163

164164
utils.EnsureXdgRuntimeDirIsSet(initContainerFlags.uid)
165165

166-
logrus.Debug("Creating /run/.toolboxenv")
166+
logrus.Debug("Creating legacy /run/.toolboxenv")
167167

168168
toolboxEnvFile, err := os.Create("/run/.toolboxenv")
169169
if err != nil {
@@ -172,6 +172,15 @@ func initContainer(cmd *cobra.Command, args []string) error {
172172

173173
defer toolboxEnvFile.Close()
174174

175+
logrus.Debug("Creating /run/.toolbxenv")
176+
177+
toolbxEnvFile, err := os.Create("/run/.toolbxenv")
178+
if err != nil {
179+
return errors.New("failed to create /run/.toolbxenv")
180+
}
181+
182+
defer toolbxEnvFile.Close()
183+
175184
if toolbxDelayEntryPoint, ok := getDelayEntryPoint(); ok {
176185
delayString := toolbxDelayEntryPoint.String()
177186
logrus.Debugf("Adding a delay of %s", delayString)

src/pkg/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ func IsInsideContainer() bool {
765765
}
766766

767767
func IsInsideToolboxContainer() bool {
768-
return PathExists("/run/.toolboxenv")
768+
return PathExists("/run/.toolbxenv") || PathExists("/run/.toolboxenv")
769769
}
770770

771771
// ResolveContainerAndImageNames takes care of standardizing names of containers and images.

test/system/104-run.bats

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ teardown() {
220220
assert [ ${#stderr_lines[@]} -eq 0 ]
221221
}
222222

223-
@test "run: Ensure that /run/.toolboxenv exists" {
223+
@test "run: Ensure that legacy /run/.toolboxenv exists" {
224224
create_default_container
225225

226226
run --keep-empty-lines --separate-stderr "$TOOLBX" run test -f /run/.toolboxenv
@@ -230,6 +230,16 @@ teardown() {
230230
assert [ ${#stderr_lines[@]} -eq 0 ]
231231
}
232232

233+
@test "run: Ensure that /run/.toolbxenv exists" {
234+
create_default_container
235+
236+
run --keep-empty-lines --separate-stderr "$TOOLBX" run test -f /run/.toolbxenv
237+
238+
assert_success
239+
assert [ ${#lines[@]} -eq 0 ]
240+
assert [ ${#stderr_lines[@]} -eq 0 ]
241+
}
242+
233243
@test "run: Ensure that the default container is used" {
234244
test -z "${name+x}"
235245

0 commit comments

Comments
 (0)