Leave logging off by default.

Disable logging by default. The log file will not be created, but if it
already exists we'll add to it. So

BUG=none
BRANCH=none
TEST=manual

No logging:

  rm -f /tmp/futility.log
  cgpt help
  cat /tmp/futility.log        # file should not exist

With logging:

  touch /tmp/futility.log
  cgpt help
  cat /tmp/futility.log        # file should contain stuff

Change-Id: I2629d98f65c89e636cd78f42a5bf659058a002ae
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44755
diff --git a/Makefile b/Makefile
index 264f65d..9ce42b6 100644
--- a/Makefile
+++ b/Makefile
@@ -138,8 +138,8 @@
 CFLAGS += -DNDEBUG
 endif
 
-ifneq (${WITH_LOGGING},)
-CFLAGS += -DWITH_LOGGING
+ifneq (${FORCE_LOGGING_ON},)
+CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
 endif
 
 # Create / use dependency files
diff --git a/futility/futility.c b/futility/futility.c
index dd70b68..9029493 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -20,10 +20,12 @@
 #define MYNAME "futility"
 #define SUBDIR "old_bins"
 
-/* HEY: FIXME: Hardcoding logs on for now. Delete these lines for real use. */
-#ifndef WITH_LOGGING
-#define WITH_LOGGING
-#endif
+/* File to use for logging, if present */
+#define LOGFILE "/tmp/futility.log"
+
+/* Normally logging will only happen if the logfile already exists. Uncomment
+ * this to force log file creation (and thus logging) always. */
+/* #define FORCE_LOGGING_ON */
 
 /******************************************************************************/
 
@@ -72,12 +74,9 @@
 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 */
@@ -127,7 +126,11 @@
   struct flock lock;
   int ret;
 
+#ifdef FORCE_LOGGING_ON
   log_fd = open(LOGFILE, O_WRONLY|O_APPEND|O_CREAT, 0666);
+#else
+  log_fd = open(LOGFILE, O_WRONLY|O_APPEND);
+#endif
   if (log_fd < 0) {
 
     if (errno != EACCES)
@@ -182,9 +185,6 @@
 
   log_close();
 }
-#else
-#define log_args(...)
-#endif /* WITH_LOGGING */
 
 
 /******************************************************************************/