Blame SOURCES/0001-logger-Add-a-separator-between-different-boot-logs.patch

ff210d
From 5fc9f555176bbbc354d651e6e31f618aea0b2b7d Mon Sep 17 00:00:00 2001
ff210d
From: Hans de Goede <hdegoede@redhat.com>
ff210d
Date: Tue, 17 Jul 2018 09:46:12 +0200
ff210d
Subject: [PATCH] logger: Add a separator between different boot logs
ff210d
ff210d
Since we concatenate boot logs one after the other in /var/log/boot.log
ff210d
it is hard to tell where the logs from one boot end the next boot starts.
ff210d
ff210d
This commit makes plymouth write out a separator including a time + date
ff210d
of the date, when the log file gets opened to add new boot messages to it.
ff210d
ff210d
Note ply_logger_open_file() is only called from ply_terminal_session_open_log()
ff210d
which in turn is only used for /var/log/boot.log, so this only effects
ff210d
/var/log/boot.log.
ff210d
ff210d
Closes #29
ff210d
ff210d
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ff210d
---
ff210d
 src/libply/ply-logger.c | 13 +++++++++++++
ff210d
 1 file changed, 13 insertions(+)
ff210d
ff210d
diff --git a/src/libply/ply-logger.c b/src/libply/ply-logger.c
ff210d
index 1b56ea8..3dbc3ca 100644
ff210d
--- a/src/libply/ply-logger.c
ff210d
+++ b/src/libply/ply-logger.c
ff210d
@@ -7,60 +7,61 @@
ff210d
  * the Free Software Foundation; either version 2, or (at your option)
ff210d
  * any later version.
ff210d
  *
ff210d
  * This program is distributed in the hope that it will be useful,
ff210d
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff210d
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ff210d
  * GNU General Public License for more details.
ff210d
  *
ff210d
  * You should have received a copy of the GNU General Public License
ff210d
  * along with this program; if not, write to the Free Software
ff210d
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ff210d
  * 02111-1307, USA.
ff210d
  *
ff210d
  * Written by: Ray Strode <rstrode@redhat.com>
ff210d
  */
ff210d
 #include "config.h"
ff210d
 #include "ply-logger.h"
ff210d
 
ff210d
 #include <assert.h>
ff210d
 #include <ctype.h>
ff210d
 #include <errno.h>
ff210d
 #include <fcntl.h>
ff210d
 #include <stdarg.h>
ff210d
 #include <stdio.h>
ff210d
 #include <stdlib.h>
ff210d
 #include <string.h>
ff210d
 #include <sys/fcntl.h>
ff210d
 #include <sys/file.h>
ff210d
 #include <sys/stat.h>
ff210d
 #include <sys/types.h>
ff210d
+#include <time.h>
ff210d
 #include <unistd.h>
ff210d
 
ff210d
 #include "ply-utils.h"
ff210d
 #include "ply-list.h"
ff210d
 
ff210d
 #ifndef PLY_LOGGER_OPEN_FLAGS
ff210d
 #define PLY_LOGGER_OPEN_FLAGS (O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW | O_CLOEXEC)
ff210d
 #endif
ff210d
 
ff210d
 #ifndef PLY_LOGGER_MAX_INJECTION_SIZE
ff210d
 #define PLY_LOGGER_MAX_INJECTION_SIZE 4096
ff210d
 #endif
ff210d
 
ff210d
 #ifndef PLY_LOGGER_MAX_BUFFER_CAPACITY
ff210d
 #define PLY_LOGGER_MAX_BUFFER_CAPACITY (8 * 4096)
ff210d
 #endif
ff210d
 
ff210d
 typedef struct
ff210d
 {
ff210d
         ply_logger_filter_handler_t handler;
ff210d
         void                       *user_data;
ff210d
 } ply_logger_filter_t;
ff210d
 
ff210d
 struct _ply_logger
ff210d
 {
ff210d
         int                       output_fd;
ff210d
         char                     *filename;
ff210d
 
ff210d
         char                     *buffer;
ff210d
         size_t                    buffer_size;
ff210d
@@ -285,77 +286,89 @@ ply_logger_free_filters (ply_logger_t *logger)
ff210d
                 free (filter);
ff210d
                 node = next_node;
ff210d
         }
ff210d
 
ff210d
         ply_list_free (logger->filters);
ff210d
 }
ff210d
 
ff210d
 void
ff210d
 ply_logger_free (ply_logger_t *logger)
ff210d
 {
ff210d
         if (logger == NULL)
ff210d
                 return;
ff210d
 
ff210d
         if (logger->output_fd >= 0) {
ff210d
                 if (ply_logger_is_logging (logger))
ff210d
                         ply_logger_flush (logger);
ff210d
                 close (logger->output_fd);
ff210d
         }
ff210d
 
ff210d
         ply_logger_free_filters (logger);
ff210d
 
ff210d
         free (logger->filename);
ff210d
         free (logger->buffer);
ff210d
         free (logger);
ff210d
 }
ff210d
 
ff210d
 bool
ff210d
 ply_logger_open_file (ply_logger_t *logger,
ff210d
                       const char   *filename)
ff210d
 {
ff210d
+        char header[80];
ff210d
+        struct tm* tm;
ff210d
+        time_t t;
ff210d
         int fd;
ff210d
         mode_t mode;
ff210d
 
ff210d
         assert (logger != NULL);
ff210d
         assert (filename != NULL);
ff210d
 
ff210d
         fd = open (filename, PLY_LOGGER_OPEN_FLAGS, 0600);
ff210d
 
ff210d
         if (fd < 0)
ff210d
                 return false;
ff210d
 
ff210d
         ply_logger_set_output_fd (logger, fd);
ff210d
 
ff210d
         free (logger->filename);
ff210d
 
ff210d
         logger->filename = strdup (filename);
ff210d
 
ff210d
+        time (&t);
ff210d
+        tm = localtime (&t);
ff210d
+        if (tm) {
ff210d
+                /* This uses uname -v date format */
ff210d
+                strftime (header, sizeof(header),
ff210d
+                         "------------ %a %b %d %T %Z %Y ------------\n", tm);
ff210d
+                ply_logger_write (logger, header, strlen(header), true);
ff210d
+        }
ff210d
+
ff210d
         return true;
ff210d
 }
ff210d
 
ff210d
 void
ff210d
 ply_logger_close_file (ply_logger_t *logger)
ff210d
 {
ff210d
         assert (logger != NULL);
ff210d
 
ff210d
         if (logger->output_fd < 0)
ff210d
                 return;
ff210d
 
ff210d
         close (logger->output_fd);
ff210d
         ply_logger_set_output_fd (logger, -1);
ff210d
 }
ff210d
 
ff210d
 void
ff210d
 ply_logger_set_output_fd (ply_logger_t *logger,
ff210d
                           int           fd)
ff210d
 {
ff210d
         assert (logger != NULL);
ff210d
 
ff210d
         logger->output_fd = fd;
ff210d
 }
ff210d
 
ff210d
 int
ff210d
 ply_logger_get_output_fd (ply_logger_t *logger)
ff210d
 {
ff210d
         assert (logger != NULL);
ff210d
 
ff210d
         return logger->output_fd;
ff210d
-- 
ff210d
2.18.1
ff210d