Fix command-line parsing of loggingPath

The "-l" option for loggingPath was not enabling logging when given,
as it should have been. Now, logging can be enabled either by use of
command line or by existence of sentinel file, as intended.

Thanks to Anton Kachalov and Konstantin Klubnichkin for catching this
bug.

Also cleaned up the printing of the informational lines printed, for
loggingEnabled and tuningEnabled, to be correct as originally
intended: printed when enabled, no output when disabled.

Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: I3f20a4dee997e04985d32cd6020b719e0b4d117e
diff --git a/main.cpp b/main.cpp
index 342b27e..6e757aa 100644
--- a/main.cpp
+++ b/main.cpp
@@ -232,19 +232,37 @@
     static constexpr auto loggingEnablePath = "/etc/thermal.d/logging";
     static constexpr auto tuningEnablePath = "/etc/thermal.d/tuning";
 
+    // Set up default logging path, preferring command line if it was given
+    std::string defLoggingPath(loggingPath);
+    if (defLoggingPath.empty())
+    {
+        defLoggingPath = std::filesystem::temp_directory_path();
+    }
+    else
+    {
+        // Enable logging, if user explicitly gave path on command line
+        loggingEnabled = true;
+    }
+
     // If this file exists, enable logging at runtime
     std::ifstream fsLogging(loggingEnablePath);
     if (fsLogging)
     {
-        // Unless file contents are a valid directory path, use system default
+        // The first line of file might be a valid directory path
         std::getline(fsLogging, loggingPath);
-        if (!(std::filesystem::exists(loggingPath)))
-        {
-            loggingPath = std::filesystem::temp_directory_path();
-        }
         fsLogging.close();
 
+        // If so, use it, otherwise use default logging path instead
+        if (!(std::filesystem::exists(loggingPath)))
+        {
+            loggingPath = defLoggingPath;
+        }
+
         loggingEnabled = true;
+    }
+
+    if (loggingEnabled)
+    {
         std::cerr << "Logging enabled: " << loggingPath << "\n";
     }
 
@@ -252,6 +270,11 @@
     if (std::filesystem::exists(tuningEnablePath))
     {
         tuningEnabled = true;
+    }
+
+    // This can also be enabled from the command line
+    if (tuningEnabled)
+    {
         std::cerr << "Tuning enabled\n";
     }