summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-02-25 14:09:43 -0800
committerBill Richardson <wfrichar@chromium.org>2013-02-25 14:12:31 -0800
commit7f73c9c38468faf03464ac0d22d5bf1f999b2ffe (patch)
tree6e7ca5e7bb93cbd57ec83f96700afd15b765a52b
parent560b3b043e5d88679b365fcb047e929ef5bd4756 (diff)
downloadvboot-7f73c9c38468faf03464ac0d22d5bf1f999b2ffe.tar.gz
Isolate logging for easy removal. Leave it on for now, though.
BUG=none BRANCH=none TEST=none Change-Id: I8c5da7988f05c3df77f0a64d920a82db45892ca9 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/43946
-rw-r--r--Makefile5
-rw-r--r--futility/futility.c58
2 files changed, 41 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 9ac7499a..af1234a9 100644
--- a/Makefile
+++ b/Makefile
@@ -138,6 +138,10 @@ ifeq (${DISABLE_NDEBUG},)
CFLAGS += -DNDEBUG
endif
+ifneq (${WITH_LOGGING},)
+CFLAGS += -DWITH_LOGGING
+endif
+
# Create / use dependency files
CFLAGS += -MMD -MF $@.d
@@ -1074,4 +1078,3 @@ coverage:
else
coverage: coverage_init runtests coverage_html
endif
-
diff --git a/futility/futility.c b/futility/futility.c
index 404b6b06..dd70b686 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -20,7 +20,10 @@
#define MYNAME "futility"
#define SUBDIR "old_bins"
-#define LOGFILE "/tmp/futility.log"
+/* HEY: FIXME: Hardcoding logs on for now. Delete these lines for real use. */
+#ifndef WITH_LOGGING
+#define WITH_LOGGING
+#endif
/******************************************************************************/
@@ -69,9 +72,12 @@ static int help(int argc, char *argv[])
DECLARE_FUTIL_COMMAND(help, help, "Show a bit of help");
+#ifdef WITH_LOGGING
/******************************************************************************/
/* Logging stuff */
+#define LOGFILE "/tmp/futility.log"
+
static int log_fd = -1;
/* Write the string and a newline. Silently give up on errors */
@@ -143,29 +149,43 @@ static void log_open(void)
lock.l_whence = SEEK_END;
ret = fcntl(log_fd, F_SETLKW, &lock); /* this blocks */
- if (ret < 0) {
+ if (ret < 0)
log_close();
- return;
- }
+}
+
+static void log_args(int argc, char *argv[])
+{
+ int i;
+ ssize_t r;
+ pid_t parent;
+ char buf[80];
+ char truename[PATH_MAX+10];
+
+ log_open();
/* delimiter */
log_str("##### HEY #####");
- {
/* Can we tell who called us? */
- char truename[PATH_MAX+10];
- char buf[80];
- ssize_t r;
- pid_t parent = getppid();
- snprintf(buf, 80, "/proc/%d/exe", parent);
- strncat(truename, "CALLER:", 7);
- r = readlink(buf, truename+7, PATH_MAX-1);
- if (r >= 0) {
- truename[r+7] = '\0';
- log_str(truename);
- }
+ parent = getppid();
+ snprintf(buf, 80, "/proc/%d/exe", parent);
+ strncat(truename, "CALLER:", 7);
+ r = readlink(buf, truename+7, PATH_MAX-1);
+ if (r >= 0) {
+ truename[r+7] = '\0';
+ log_str(truename);
}
+
+ /* Now log the stuff about ourselves */
+ for (i = 0; i < argc; i++)
+ log_str(argv[i]);
+
+ log_close();
}
+#else
+#define log_args(...)
+#endif /* WITH_LOGGING */
+
/******************************************************************************/
/* Here we go */
@@ -179,13 +199,9 @@ int main(int argc, char *argv[], char *envp[])
pid_t myproc;
ssize_t r;
char *s;
- int i;
futil_cmd_t *cmd;
- log_open();
- for (i = 0; i < argc; i++)
- log_str(argv[i]);
- log_close();
+ log_args(argc, argv);
/* How were we invoked? */
progname = strrchr(argv[0], '/');