]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Backup lightdm.log, X logs and unity-system-compositor.log when writing new logs
authorRobert Ancell <robert.ancell@canonical.com>
Thu, 22 Aug 2013 08:27:30 +0000 (20:27 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Thu, 22 Aug 2013 08:27:30 +0000 (20:27 +1200)
src/lightdm.c
src/seat-unity.c
src/x-server-local.c

index f92bc5efc182626be7eb7203a700561e9a56f3f2..69c52095a946726b67f1c0435681361bab20bbec 100644 (file)
@@ -115,7 +115,7 @@ log_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message,
 static void
 log_init (void)
 {
-    gchar *log_dir, *path;
+    gchar *log_dir, *path, *old_path;
 
     log_timer = g_timer_new ();
 
@@ -124,6 +124,12 @@ log_init (void)
     path = g_build_filename (log_dir, "lightdm.log", NULL);
     g_free (log_dir);
 
+    /* Move old file out of the way */
+    old_path = g_strdup_printf ("%s.old", path);
+    rename (path, old_path);
+    g_free (old_path);
+
+    /* Create new file and log to it */
     log_fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
     fcntl (log_fd, F_SETFD, FD_CLOEXEC);
     g_log_set_default_handler (log_cb, NULL);
index a449aece548485ea05dad3c047db9b2d3b1969b6..7de61a4269336130ea09b1fa4c56ded25ca015c9 100644 (file)
@@ -133,7 +133,14 @@ compositor_run_cb (Process *process, SeatUnity *seat)
     if (seat->priv->log_file)
     {
          int fd;
+         gchar *old_filename;
 
+         /* Move old file out of the way */
+         old_filename = g_strdup_printf ("%s.old", seat->priv->log_file);
+         rename (seat->priv->log_file, old_filename);
+         g_free (old_filename);
+
+         /* Create new file and log to it */
          fd = g_open (seat->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
              l_warning (seat, "Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno));
index 12c32e15fcd8b2bc495b413abf5740e3db33b70c..646a9e72857edc46d03d2c5d6d088243454c4caa 100644 (file)
@@ -330,7 +330,14 @@ run_cb (Process *process, XServerLocal *server)
     if (server->priv->log_file)
     {
          int fd;
+         gchar *old_filename;
 
+         /* Move old file out of the way */
+         old_filename = g_strdup_printf ("%s.old", server->priv->log_file);
+         rename (server->priv->log_file, old_filename);
+         g_free (old_filename);
+
+         /* Create new file and log to it */
          fd = g_open (server->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
              l_warning (server, "Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno));