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
diff --git a/Makefile b/Makefile
index 9ac7499..af1234a 100644
--- a/Makefile
+++ b/Makefile
@@ -138,6 +138,10 @@
 CFLAGS += -DNDEBUG
 endif
 
+ifneq (${WITH_LOGGING},)
+CFLAGS += -DWITH_LOGGING
+endif
+
 # Create / use dependency files
 CFLAGS += -MMD -MF $@.d
 
@@ -1074,4 +1078,3 @@
 else
 coverage: coverage_init runtests coverage_html
 endif
-
diff --git a/futility/futility.c b/futility/futility.c
index 404b6b0..dd70b68 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 @@
 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 @@
   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 @@
   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], '/');