veyron/services/mgmt/suidhelper: Fix argv
Before this change, suidhelper did not set the first value of argv
correctly. It was missing the name of the binary. With this change,
os.Args has the right value in the child process and the INFO logs start
to appear in the logs directory.
Change-Id: I501e3a05720d6346fbe43d955cbf3d27c982f51a
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index ca1f416..efc1c5c 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -1031,26 +1031,41 @@
"apps/google naps/" + installID + "/" + instance1ID + "/logs",
"apps/google naps/" + installID + "/" + instance1ID + "/logs/STDERR-<timestamp>",
"apps/google naps/" + installID + "/" + instance1ID + "/logs/STDOUT-<timestamp>",
+ "apps/google naps/" + installID + "/" + instance1ID + "/logs/bin.INFO",
+ "apps/google naps/" + installID + "/" + instance1ID + "/logs/bin.<*>.INFO.<timestamp>",
"nm",
}},
{"nm/apps", "*", []string{"google naps"}},
{"nm/apps/google naps", "*", []string{installID}},
{"nm/apps/google naps/" + installID, "*", []string{instance1ID}},
{"nm/apps/google naps/" + installID + "/" + instance1ID, "*", []string{"logs"}},
- {"nm/apps/google naps/" + installID + "/" + instance1ID + "/logs", "*", []string{"STDERR-<timestamp>", "STDOUT-<timestamp>"}},
+ {"nm/apps/google naps/" + installID + "/" + instance1ID + "/logs", "*", []string{
+ "STDERR-<timestamp>",
+ "STDOUT-<timestamp>",
+ "bin.INFO",
+ "bin.<*>.INFO.<timestamp>",
+ }},
}
- re := regexp.MustCompile("(STDOUT|STDERR)-[0-9]+$")
+ logFileTimeStampRE := regexp.MustCompile("(STDOUT|STDERR)-[0-9]+$")
+ logFileTrimINFORE := regexp.MustCompile(`bin\..*\.INFO\.[0-9.-]+$`)
+ logFileRemoveErrorFatalWarningRE := regexp.MustCompile("(ERROR|FATAL|WARNING)")
for _, tc := range testcases {
results := doGlob(t, tc.name, tc.pattern)
- for i, name := range results {
- results[i] = re.ReplaceAllString(name, "$1-<timestamp>")
+ filteredResults := []string{}
+ for _, name := range results {
+ if logFileRemoveErrorFatalWarningRE.MatchString(name) {
+ continue
+ }
+ name = logFileTimeStampRE.ReplaceAllString(name, "$1-<timestamp>")
+ name = logFileTrimINFORE.ReplaceAllString(name, "bin.<*>.INFO.<timestamp>")
+ filteredResults = append(filteredResults, name)
}
- if !reflect.DeepEqual(results, tc.expected) {
- t.Errorf("unexpected result for (%q, %q). Got %q, want %q", tc.name, tc.pattern, results, tc.expected)
+ if !reflect.DeepEqual(filteredResults, tc.expected) {
+ t.Errorf("unexpected result for (%q, %q). Got %q, want %q", tc.name, tc.pattern, filteredResults, tc.expected)
}
}
- // Call Size() on the log file objects
+ // Call Size() on the log file objects.
files := doGlob(t, "nm", "apps/google naps/"+installID+"/"+instance1ID+"/logs/*")
for _, file := range files {
name := naming.Join("nm", file)
diff --git a/services/mgmt/suidhelper/impl/args.go b/services/mgmt/suidhelper/impl/args.go
index 34ec8f6..3178e1e 100644
--- a/services/mgmt/suidhelper/impl/args.go
+++ b/services/mgmt/suidhelper/impl/args.go
@@ -102,7 +102,7 @@
wp.argv0 = *flagRun
wp.stdoutLog = *flagStdoutLog
wp.stderrLog = *flagStderrLog
- wp.argv = fs.Args()
+ wp.argv = append([]string{wp.argv0}, fs.Args()...)
// TODO(rjkroege): Reduce the environment to the absolute minimum needed.
wp.envv = env
diff --git a/services/mgmt/suidhelper/impl/args_test.go b/services/mgmt/suidhelper/impl/args_test.go
index a209c87..b3a86b1 100644
--- a/services/mgmt/suidhelper/impl/args_test.go
+++ b/services/mgmt/suidhelper/impl/args_test.go
@@ -33,7 +33,7 @@
stderrLog: "",
stdoutLog: "",
argv0: "",
- argv: []string{},
+ argv: []string{""},
envv: []string{"A=B"},
},
},
@@ -50,7 +50,7 @@
stderrLog: "/stderr",
stdoutLog: "/stdout",
argv0: "/bin/veyron",
- argv: []string{"one", "two"},
+ argv: []string{"/bin/veyron", "one", "two"},
envv: []string{"A=B"},
},
},