Browse code

add log messages when write to oom_score_adj fails

Signed-off-by: Michael Hudson-Doyle <michael.hudson@canonical.com>

Michael Hudson-Doyle authored on 2016/09/21 16:36:36
Showing 2 changed files
... ...
@@ -37,6 +37,7 @@ import (
37 37
 	lntypes "github.com/docker/libnetwork/types"
38 38
 	"github.com/golang/protobuf/ptypes"
39 39
 	"github.com/opencontainers/runc/libcontainer/label"
40
+	rsystem "github.com/opencontainers/runc/libcontainer/system"
40 41
 	"github.com/opencontainers/runc/libcontainer/user"
41 42
 	"github.com/opencontainers/runtime-spec/specs-go"
42 43
 )
... ...
@@ -1147,10 +1148,16 @@ func setupOOMScoreAdj(score int) error {
1147 1147
 	if err != nil {
1148 1148
 		return err
1149 1149
 	}
1150
-	_, err = f.WriteString(strconv.Itoa(score))
1150
+
1151
+	stringScore := strconv.Itoa(score)
1152
+	_, err = f.WriteString(stringScore)
1151 1153
 	if os.IsPermission(err) {
1152 1154
 		// Setting oom_score_adj does not work in an
1153
-		// unprivileged container. Ignore the error.
1155
+		// unprivileged container. Ignore the error, but log
1156
+		// it if we appear not to be in that situation.
1157
+		if !rsystem.RunningInUserNS() {
1158
+			logrus.Debugf("Permission denied writing %q to /proc/self/oom_score_adj", stringScore)
1159
+		}
1154 1160
 		return nil
1155 1161
 	}
1156 1162
 	f.Close()
... ...
@@ -22,6 +22,7 @@ import (
22 22
 	"github.com/docker/docker/utils"
23 23
 	"github.com/golang/protobuf/ptypes"
24 24
 	"github.com/golang/protobuf/ptypes/timestamp"
25
+	rsystem "github.com/opencontainers/runc/libcontainer/system"
25 26
 	"golang.org/x/net/context"
26 27
 	"google.golang.org/grpc"
27 28
 	"google.golang.org/grpc/grpclog"
... ...
@@ -429,15 +430,21 @@ func (r *remote) runContainerdDaemon() error {
429 429
 }
430 430
 
431 431
 func setOOMScore(pid, score int) error {
432
-	f, err := os.OpenFile(fmt.Sprintf("/proc/%d/oom_score_adj", pid), os.O_WRONLY, 0)
432
+	oomScoreAdjPath := fmt.Sprintf("/proc/%d/oom_score_adj", pid)
433
+	f, err := os.OpenFile(oomScoreAdjPath, os.O_WRONLY, 0)
433 434
 	if err != nil {
434 435
 		return err
435 436
 	}
436
-	_, err = f.WriteString(strconv.Itoa(score))
437
+	stringScore := strconv.Itoa(score)
438
+	_, err = f.WriteString(stringScore)
437 439
 	f.Close()
438 440
 	if os.IsPermission(err) {
439 441
 		// Setting oom_score_adj does not work in an
440
-		// unprivileged container. Ignore the error.
442
+		// unprivileged container. Ignore the error, but log
443
+		// it if we appear not to be in that situation.
444
+		if !rsystem.RunningInUserNS() {
445
+			logrus.Debugf("Permission denied writing %q to %s", stringScore, oomScoreAdjPath)
446
+		}
441 447
 		return nil
442 448
 	}
443 449
 	return err