Requested by Facebook to avoid difficult quoting, but something we should do anyway just to match logger(1).
Bug: https://issuetracker.google.com/199939602 --- toys/android/log.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
From 35b1da573a280e2e47552a12d0de5214356e9b1f Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Thu, 16 Sep 2021 18:55:57 -0700 Subject: [PATCH] log(1): add no-arguments=>stdin behavior to match logger(1). Requested by Facebook to avoid difficult quoting, but something we should do anyway just to match logger(1). Bug: https://issuetracker.google.com/199939602 --- toys/android/log.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/toys/android/log.c b/toys/android/log.c index 3fbc95a0..0f7b387e 100644 --- a/toys/android/log.c +++ b/toys/android/log.c @@ -2,16 +2,16 @@ * * Copyright 2016 The Android Open Source Project -USE_LOG(NEWTOY(log, "<1p:t:", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_LOG(NEWTOY(log, "p:t:", TOYFLAG_USR|TOYFLAG_SBIN)) config LOG bool "log" depends on TOYBOX_ON_ANDROID default y help - usage: log [-p PRI] [-t TAG] MESSAGE... + usage: log [-p PRI] [-t TAG] [MESSAGE...] - Logs message to logcat. + Logs message (or stdin) to logcat. -p Use the given priority instead of INFO: d: DEBUG e: ERROR f: FATAL i: INFO v: VERBOSE w: WARN s: SILENT @@ -40,17 +40,18 @@ void log_main(void) } if (!TT.t) TT.t = "log"; - for (i = 0; toys.optargs[i]; i++) { - if (i) *s++ = ' '; - if ((s-toybuf)+strlen(toys.optargs[i])>=1024) { - memcpy(s, toys.optargs[i], 1024-(s-toybuf)); - toybuf[1024] = 0; - error_msg("log cut at 1024 bytes"); - - break; + if (toys.optc) { + for (i = 0; toys.optargs[i]; i++) { + if (i) *s++ = ' '; + if ((s-toybuf)+strlen(toys.optargs[i])>=1024) { + memcpy(s, toys.optargs[i], 1024-(s-toybuf)); + toybuf[1024] = 0; + error_msg("log cut at 1024 bytes"); + break; + } + s = stpcpy(s, toys.optargs[i]); } - s = stpcpy(s, toys.optargs[i]); - } + } else toybuf[readall(0, toybuf, 1024-1)] = 0; __android_log_write(pri, TT.t, toybuf); } -- 2.33.0.464.g1972c5931b-goog
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
