~lightdm-team/lightdm/1.14

« back to all changes in this revision

Viewing changes to src/process.c

  • Committer: Robert Ancell
  • Date: 2015-10-28 03:28:13 UTC
  • Revision ID: robert.ancell@canonical.com-20151028032813-yh3hnigb4b41e4bg
Add a backup-logs option that can be used to disable existing logging files having a .old suffix added to them

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <fcntl.h>
18
18
#include <signal.h>
19
19
#include <grp.h>
20
 
#include <glib/gstdio.h>
21
20
#include <config.h>
22
21
 
 
22
#include "log-file.h"
23
23
#include "process.h"
24
24
 
25
25
enum {
39
39
    /* File to log to */
40
40
    gchar *log_file;
41
41
    gboolean log_stdout;
 
42
    LogMode log_mode;
42
43
 
43
44
    /* Command to run */
44
45
    gchar *command;
90
91
    Process *process = g_object_new (PROCESS_TYPE, NULL);
91
92
    process->priv->run_func = run_func;
92
93
    process->priv->run_func_data = run_func_data;
 
94
    process->priv->log_mode = LOG_MODE_INVALID;
93
95
    return process;
94
96
}
95
97
 
96
98
void
97
 
process_set_log_file (Process *process, const gchar *path, gboolean log_stdout)
 
99
process_set_log_file (Process *process, const gchar *path, gboolean log_stdout, LogMode log_mode)
98
100
{
99
101
    g_return_if_fail (process != NULL);
100
102
    g_free (process->priv->log_file);
101
103
    process->priv->log_file = g_strdup (path);
102
104
    process->priv->log_stdout = log_stdout;
 
105
    process->priv->log_mode = log_mode;
103
106
}
104
107
 
105
108
void
193
196
    }
194
197
 
195
198
    if (process->priv->log_file)
196
 
    {
197
 
        gchar *old_filename;
198
 
 
199
 
        /* Move old file out of the way */
200
 
        old_filename = g_strdup_printf ("%s.old", process->priv->log_file);
201
 
        rename (process->priv->log_file, old_filename);
202
 
        g_free (old_filename);
203
 
 
204
 
        /* Create new file and log to it */
205
 
        log_fd = g_open (process->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
206
 
        if (log_fd < 0)
207
 
            g_warning ("Failed to open log file %s: %s", process->priv->log_file, g_strerror (errno));
208
 
    }
 
199
        log_fd = log_file_open (process->priv->log_file, process->priv->log_mode);
209
200
 
210
201
    /* Work out variables to set */
211
202
    env_length = g_hash_table_size (process->priv->env);