Blob Blame History Raw
From a2c6a448d38a5150c593ca388eea8537ec0489ee Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Thu, 11 May 2017 11:10:36 -0400
Subject: [PATCH] Revert "Make boot.log world readable by default"

This reverts commit fc5cd88767db61805519fef53182386ba56c6405.
---
 src/libply/ply-logger.c           | 16 ++--------------
 src/libply/ply-logger.h           |  5 ++---
 src/libply/ply-terminal-session.c |  2 +-
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/libply/ply-logger.c b/src/libply/ply-logger.c
index dfd5c0a..6f25801 100644
--- a/src/libply/ply-logger.c
+++ b/src/libply/ply-logger.c
@@ -292,84 +292,72 @@ ply_logger_free_filters (ply_logger_t *logger)
       next_node = ply_list_get_next_node (logger->filters, node);
       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,
-                      bool             world_readable)
+                      const char      *filename)
 {
   int fd;
-  mode_t mode;
 
   assert (logger != NULL);
   assert (filename != NULL);
 
-  if (world_readable)
-    mode = 0644;
-  else
-    mode = 0600;
-
-  fd = open (filename, PLY_LOGGER_OPEN_FLAGS, mode);
+  fd = open (filename, PLY_LOGGER_OPEN_FLAGS, 0600);
 
   if (fd < 0)
     return false;
 
-  if (fchmod (fd, mode) < 0) {
-    close (fd);
-    return false;
-  }
-
   ply_logger_set_output_fd (logger, fd);
 
   free (logger->filename);
 
   logger->filename = strdup (filename);
 
   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;
 }
 
diff --git a/src/libply/ply-logger.h b/src/libply/ply-logger.h
index 596bed5..fc25db9 100644
--- a/src/libply/ply-logger.h
+++ b/src/libply/ply-logger.h
@@ -19,120 +19,119 @@
  */
 #ifndef PLY_LOGGER_H
 #define PLY_LOGGER_H
 
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 typedef struct _ply_logger ply_logger_t;
 
 typedef enum
 {
   PLY_LOGGER_FLUSH_POLICY_WHEN_ASKED = 0,
   PLY_LOGGER_FLUSH_POLICY_EVERY_TIME
 } ply_logger_flush_policy_t;
 
 typedef void (* ply_logger_filter_handler_t) (void          *user_data,
                                               const void    *in_bytes,
                                               size_t         in_size,
                                               void         **out_bytes,
                                               size_t        *out_size,
                                               ply_logger_t  *logger);
 
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
 ply_logger_t *ply_logger_new (void);
 void ply_logger_free (ply_logger_t *logger);
 bool ply_logger_open_file (ply_logger_t *logger,
-                           const char   *filename,
-                           bool          world_readable);
+                           const char   *filename);
 void ply_logger_close_file (ply_logger_t    *logger);
 void ply_logger_set_output_fd (ply_logger_t *logger,
                                int           fd);
 int ply_logger_get_output_fd (ply_logger_t *logger);
 bool ply_logger_flush (ply_logger_t *logger);
 void ply_logger_set_flush_policy (ply_logger_t              *logger,
                                   ply_logger_flush_policy_t  policy);
 ply_logger_flush_policy_t ply_logger_get_flush_policy (ply_logger_t *logger);
 void ply_logger_toggle_logging (ply_logger_t *logger);
 bool ply_logger_is_logging (ply_logger_t *logger);
 void ply_logger_inject_bytes (ply_logger_t *logger,
                               const void   *bytes,
                               size_t number_of_bytes);
 void ply_logger_add_filter (ply_logger_t                *logger,
                             ply_logger_filter_handler_t  filter_handler,
                             void                        *user_data);
 #define ply_logger_inject(logger, format, args...)                             \
         ply_logger_inject_with_non_literal_format_string (logger,              \
                                                           format "", ##args)
 __attribute__((__format__ (__printf__, 2, 3)))
 void ply_logger_inject_with_non_literal_format_string (ply_logger_t   *logger,
 		                                       const char *format, ...);
 
 ply_logger_t *ply_logger_get_default (void);
 ply_logger_t *ply_logger_get_error_default (void);
 
 /* tracing is a debugging facility that incurs a hefty performance hit on the
  * program, so we conditionally compile support for it
  */
 #ifdef PLY_ENABLE_TRACING
 void ply_logger_toggle_tracing (ply_logger_t *logger);
 bool ply_logger_is_tracing_enabled (ply_logger_t *logger);
 
 #define ply_logger_trace(logger, format, args...)                              \
 do                                                                             \
   {                                                                            \
     int _old_errno;                                                            \
     _old_errno = errno;                                                        \
     if (ply_logger_is_tracing_enabled (logger))                                \
       {                                                                        \
         ply_logger_flush (logger);                                             \
         errno = _old_errno;                                                    \
         ply_logger_inject (logger,                                             \
                            "[%s:%d] %45.45s:" format "\r\n",                   \
                            __FILE__, __LINE__, __func__, ##args);              \
         ply_logger_flush (logger);                                             \
         errno = _old_errno;                                                    \
       }                                                                        \
   }                                                                            \
 while (0)
 #else
 #define ply_logger_trace(logger, format, args...)
 #define ply_logger_toggle_tracing(logger)
 #define ply_logger_is_tracing_enabled(logger) (false)
 #endif /* PLY_ENABLE_TRACING */
 
 /* convenience macros
  */
 #define ply_open_log_file(filename)                                            \
-        ply_logger_open_file (ply_logger_get_default (), filename, false)
+        ply_logger_open_file (ply_logger_get_default (), filename)
 #define ply_close_log_file()                                                   \
         ply_logger_close_file (ply_logger_get_default ())
 #define ply_flush_log()                                                        \
         ply_logger_flush (ply_logger_get_default ())
 #define ply_free_log()                                                         \
         ply_logger_free (ply_logger_get_default ())
 #define ply_log(format, args...)                                               \
         ply_logger_inject (ply_logger_get_default (), format "\n", ##args)
 #define ply_log_without_new_line(format, args...)                              \
         ply_logger_inject (ply_logger_get_default (), format, ##args)
 #define ply_error(format, args...)                                             \
         ply_logger_inject (ply_logger_get_error_default (), format "\n", ##args)
 #define ply_error_without_new_line(format, args...)                            \
         ply_logger_inject (ply_logger_get_error_default (), format, ##args)
 #define ply_free_error_log()                                                   \
         ply_logger_free (ply_logger_get_error_default ())
 
 #define ply_toggle_tracing()                                                   \
         ply_logger_toggle_tracing (ply_logger_get_error_default ())
 #define ply_is_tracing()                                                       \
         ply_logger_is_tracing_enabled (ply_logger_get_error_default ())
 #define ply_trace(format, args...)                                             \
         ply_logger_trace (ply_logger_get_error_default (), format, ##args)
 
 #endif
 
 #endif /* PLY_LOGGER_H */
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
diff --git a/src/libply/ply-terminal-session.c b/src/libply/ply-terminal-session.c
index 143eed6..50ddd28 100644
--- a/src/libply/ply-terminal-session.c
+++ b/src/libply/ply-terminal-session.c
@@ -542,48 +542,48 @@ ply_terminal_session_start_logging (ply_terminal_session_t *session)
 }
 
 static void
 ply_terminal_session_stop_logging (ply_terminal_session_t *session)
 {
   assert (session != NULL);
   assert (session->logger != NULL);
 
   ply_trace ("stopping logging of incoming console messages");
   if (ply_logger_is_logging (session->logger))
     ply_logger_toggle_logging (session->logger);
 
   if (session->loop != NULL &&
       session->fd_watch != NULL)
     ply_event_loop_stop_watching_fd (session->loop,
                                      session->fd_watch);
   session->fd_watch = NULL;
 }
 
 bool
 ply_terminal_session_open_log (ply_terminal_session_t *session,
                                const char             *filename)
 {
   bool log_is_opened;
 
   assert (session != NULL);
   assert (filename != NULL);
   assert (session->logger != NULL);
 
   ply_save_errno ();
-  log_is_opened = ply_logger_open_file (session->logger, filename, true);
+  log_is_opened = ply_logger_open_file (session->logger, filename);
   if (log_is_opened)
     ply_logger_flush (session->logger);
   ply_restore_errno ();
 
   return log_is_opened;
 }
 
 void
 ply_terminal_session_close_log (ply_terminal_session_t *session)
 {
   assert (session != NULL);
   assert (session->logger != NULL);
 
   return ply_logger_close_file (session->logger);
 }
 
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
-- 
2.12.2