aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-09-24 12:50:55 -0400
committerMike Frysinger <vapier@google.com>2019-09-24 13:40:12 -0400
commit3e6a12c4c73bbcd1c9cbf5dfae2a7588e921afa8 (patch)
treed42a4d37712f9808a85b805cdf5609ccf718b6a1
parenta45ade8b5f85db43bc035439b652d0d61fbba79f (diff)
downloadplatform_external_minijail-3e6a12c4c73bbcd1c9cbf5dfae2a7588e921afa8.tar.gz
platform_external_minijail-3e6a12c4c73bbcd1c9cbf5dfae2a7588e921afa8.tar.bz2
platform_external_minijail-3e6a12c4c73bbcd1c9cbf5dfae2a7588e921afa8.zip
minijail0: add --logging=auto setting
We've adjusted CrOS daemons to default to logging to stderr if it's connected to a tty on the assumption it's being run by a developer for testing. Add a --logging=auto setting for that too so we can autoselect between stderr & syslog. Bug: https://crbug.com/1007098 Test: `./minijail0 -p /bin/ls` writes errors to stderr Test: `./minijail0 -p /bin/ls </dev/null` writes errors to syslog Change-Id: I65c52fb4a153b4ff8ffe9c3425f1f9116795189b
-rw-r--r--minijail0.15
-rw-r--r--minijail0_cli.c14
2 files changed, 14 insertions, 5 deletions
diff --git a/minijail0.1 b/minijail0.1
index d23f14a5..b8a7752b 100644
--- a/minijail0.1
+++ b/minijail0.1
@@ -282,7 +282,10 @@ namespace to \fIhostname\fR.
.TP
\fB--logging=<system>\fR
Use \fIsystem\fR as the logging system. \fIsystem\fR must be one of
-\fBsyslog\fR (the default) or \fBstderr\fR.
+\fBauto\fR (the default), \fBsyslog\fR, or \fBstderr\fR.
+
+\fBauto\fR will use \fBstderr\fR if connected to a tty (e.g. run directly by a
+user), otherwise it will use \fBsyslog\fR.
.TP
\fB--profile <profile>\fR
Choose from one of the available sandboxing profiles, which are simple way to
diff --git a/minijail0_cli.c b/minijail0_cli.c
index 1b92b090..71d40bdb 100644
--- a/minijail0_cli.c
+++ b/minijail0_cli.c
@@ -547,7 +547,7 @@ static void usage(const char *progn)
" --ambient: Raise ambient capabilities. Requires -c.\n"
" --uts[=name]: Enter a new UTS namespace (and set hostname).\n"
" --logging=<s>:Use <s> as the logging system.\n"
- " <s> must be 'syslog' (default) or 'stderr'.\n"
+ " <s> must be 'auto' (default), 'syslog', or 'stderr'.\n"
" --profile <p>:Configure minijail0 to run with the <p> sandboxing profile,\n"
" which is a convenient way to express multiple flags\n"
" that are typically used together.\n"
@@ -593,7 +593,7 @@ int parse_args(struct minijail *j, int argc, char *const argv[],
int set_uidmap = 0, set_gidmap = 0;
size_t tmp_size = 0;
const char *filter_path = NULL;
- int log_to_stderr = 0;
+ int log_to_stderr = -1;
const char *optstring =
"+u:g:sS:c:C:P:b:B:V:f:m::M::k:a:e::R:T:vrGhHinNplLt::IUK::wyYzd";
@@ -829,9 +829,11 @@ int parse_args(struct minijail *j, int argc, char *const argv[],
minijail_namespace_set_hostname(j, optarg);
break;
case 130: /* Logging. */
- if (!strcmp(optarg, "syslog"))
+ if (!strcmp(optarg, "auto")) {
+ log_to_stderr = -1;
+ } else if (!strcmp(optarg, "syslog")) {
log_to_stderr = 0;
- else if (!strcmp(optarg, "stderr")) {
+ } else if (!strcmp(optarg, "stderr")) {
log_to_stderr = 1;
} else {
fprintf(stderr, "--logger must be 'syslog' or "
@@ -863,6 +865,10 @@ int parse_args(struct minijail *j, int argc, char *const argv[],
}
}
+ if (log_to_stderr == -1) {
+ /* Autodetect default logging output. */
+ log_to_stderr = isatty(STDERR_FILENO) ? 1 : 0;
+ }
if (log_to_stderr) {
init_logging(LOG_TO_FD, STDERR_FILENO, LOG_INFO);
/*