summaryrefslogtreecommitdiff
path: root/futility
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-09-04 16:18:15 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-12 03:39:30 +0000
commitee53d65ac033da640034bc2d04bc09020435c072 (patch)
treebc3a54bb34b897f6c7fd76df26a095c3587b534b /futility
parent08efd1ee358c546c968918a24b45219d7003ceca (diff)
downloadvboot-ee53d65ac033da640034bc2d04bc09020435c072.tar.gz
futility: slight tweak to the logging implementation
Just reporting that the parent process is "/bin/bash" doesn't help much. Let's also report the cmdline args given to the parent and the cwd. This will help us identify which shell script is calling futility with the wrong args. BUG=chromium:231547 BRANCH=ToT TEST=make runtests Signed-off-by: Bill Richardson <wfrichar@chromium.org> Change-Id: I800995ff269ab8d8c56cad8827d8de48a53cd150 Reviewed-on: https://chromium-review.googlesource.com/216715
Diffstat (limited to 'futility')
-rw-r--r--futility/futility.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/futility/futility.c b/futility/futility.c
index f18edb50..1a132202 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -99,7 +99,7 @@ static void deprecated(const char *depname)
static int log_fd = -1;
/* Write the string and a newline. Silently give up on errors */
-static void log_str(char *str)
+static void log_str(char *prefix, char *str)
{
int len, done, n;
@@ -109,6 +109,15 @@ static void log_str(char *str)
if (!str)
str = "(NULL)";
+ if (prefix && *prefix) {
+ len = strlen(prefix);
+ for (done = 0; done < len; done += n) {
+ n = write(log_fd, prefix + done, len - done);
+ if (n < 0)
+ return;
+ }
+ }
+
len = strlen(str);
if (len == 0) {
str = "(EMPTY)";
@@ -176,35 +185,58 @@ static void log_open(void)
log_close();
}
-#define CALLER_PREFIX "CALLER:"
static void log_args(int argc, char *argv[])
{
int i;
ssize_t r;
pid_t parent;
char buf[80];
- char str_caller[PATH_MAX + sizeof(CALLER_PREFIX)] = CALLER_PREFIX;
- char *truename = str_caller + sizeof(CALLER_PREFIX) - 1;
- /* Note: truename starts on the \0 from CALLER_PREFIX, so we can write
- * PATH_MAX chars into truename and still append a \0 at the end. */
+ FILE *fp;
+ char caller_buf[PATH_MAX];
log_open();
/* delimiter */
- log_str("##### HEY #####");
+ log_str(NULL, "##### HEY #####");
/* Can we tell who called us? */
parent = getppid();
snprintf(buf, sizeof(buf), "/proc/%d/exe", parent);
- r = readlink(buf, truename, PATH_MAX);
+ r = readlink(buf, caller_buf, sizeof(caller_buf) - 1);
if (r >= 0) {
- truename[r] = '\0';
- log_str(str_caller);
+ caller_buf[r] = '\0';
+ log_str("CALLER:", caller_buf);
+ }
+
+ /* From where? */
+ snprintf(buf, sizeof(buf), "/proc/%d/cwd", parent);
+ r = readlink(buf, caller_buf, sizeof(caller_buf) - 1);
+ if (r >= 0) {
+ caller_buf[r] = '\0';
+ log_str("DIR:", caller_buf);
+ }
+
+ /* And maybe the args? */
+ snprintf(buf, sizeof(buf), "/proc/%d/cmdline", parent);
+ fp = fopen(buf, "r");
+ if (fp) {
+ memset(caller_buf, 0, sizeof(caller_buf));
+ r = fread(caller_buf, 1, sizeof(caller_buf) - 1, fp);
+ if (r > 0) {
+ char *s = caller_buf;
+ for (i = 0; i < r && *s; ) {
+ log_str("CMDLINE:", s);
+ while (i < r && *s)
+ i++, s++;
+ i++, s++;
+ }
+ }
+ fclose(fp);
}
/* Now log the stuff about ourselves */
for (i = 0; i < argc; i++)
- log_str(argv[i]);
+ log_str(NULL, argv[i]);
log_close();
}