plymouth/SOURCES/0001-logger-Add-a-separator-between-different-boot-logs.patch
2021-09-10 02:05:30 +00:00

182 lines
4.7 KiB
Diff

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