Skip to content

Commit e9bd379

Browse files
committed
Log when CNB_LAUNCH_UMASK is incorrect
Pass a logger down to the process launcher and log when setting the umaks is incorrect and continue.
1 parent 317922e commit e9bd379

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

cmd/launcher/cli/launcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func RunLaunch() error {
4949
ExecD: launch.NewExecDRunner(),
5050
Shell: launch.DefaultShell,
5151
Setenv: os.Setenv,
52+
Logger: cmd.DefaultLogger,
5253
}
5354

5455
if err := launcher.Launch(os.Args[0], os.Args[1:]); err != nil {

launch/launcher.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/buildpacks/lifecycle/api"
1111
"github.com/buildpacks/lifecycle/env"
12+
"github.com/buildpacks/lifecycle/log"
1213
)
1314

1415
var (
@@ -26,6 +27,7 @@ type Launcher struct {
2627
ExecD ExecD
2728
Shell Shell
2829
LayersDir string
30+
Logger *log.DefaultLogger
2931
PlatformAPI *api.Version
3032
Processes []Process
3133
Setenv func(string, string) error
@@ -70,8 +72,8 @@ func (l *Launcher) LaunchProcess(self string, proc Process) error {
7072
proc.WorkingDirectory = getProcessWorkingDirectory(proc, l.AppDir)
7173

7274
err := SetUmask(l.Env)
73-
if err != nil {
74-
return errors.Wrap(err, "umask")
75+
if err != nil && l.Logger != nil {
76+
l.Logger.Errorf("invalid umask: %s", err)
7577
}
7678

7779
if proc.Direct {

launch/launcher_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func testLauncher(t *testing.T, when spec.G, it spec.S) {
125125
process.Command = launch.NewRawCommand([]string{"sh"})
126126

127127
mockEnv.EXPECT().Get("PATH").Return("some-path").AnyTimes()
128+
mockEnv.EXPECT().Get("UMASK").Return("").AnyTimes()
128129
launcher.Setenv = func(k string, v string) error {
129130
if k == "PATH" {
130131
setPath = v

launch/umask_unix.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
package launch
44

55
import (
6+
"fmt"
67
"strconv"
78
"syscall"
89

910
"github.com/pkg/errors"
1011
)
1112

13+
const (
14+
umaskEnvVar = "CNB_LAUNCH_UMASK"
15+
)
16+
1217
// SetUmask on unix systems from the value in the `UMASK` environment variable
1318
func SetUmask(env Env) error {
1419
return SetUmaskWith(env, syscall.Umask)
1520
}
1621

1722
// SetUmaskWith the injected function umaskFn
1823
func SetUmaskWith(env Env, umaskFn func(int) int) error {
19-
if umask := env.Get("UMASK"); umask != "" {
24+
if umask := env.Get(umaskEnvVar); umask != "" {
2025
u, err := strconv.ParseInt(umask, 8, 0)
2126
if err != nil {
22-
return errors.Wrap(err, "invalid umask value")
27+
return errors.Wrap(err, fmt.Sprintf("invalid umask value %s", umask))
2328
}
2429
umaskFn(int(u))
2530
}

0 commit comments

Comments
 (0)