2 * Copyright (C) 2015 Alexandros Frantzis
3 * Author: Alexandros Frantzis <alexandros.frantzis@canonical.com>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
19 log_file_open (const gchar *log_filename, LogMode log_mode)
21 int open_flags = O_WRONLY | O_CREAT;
24 if (log_mode == LOG_MODE_BACKUP_AND_TRUNCATE)
26 /* Move old file out of the way */
29 old_filename = g_strdup_printf ("%s.old", log_filename);
30 rename (log_filename, old_filename);
31 g_free (old_filename);
33 open_flags |= O_TRUNC;
35 else if (log_mode == LOG_MODE_APPEND)
37 /* Keep appending to it */
38 open_flags |= O_APPEND;
42 g_warning ("Failed to open log file %s: invalid log mode %d specified",
43 log_filename, log_mode);
47 /* Open file and log to it */
48 log_fd = open (log_filename, open_flags, 0600);
50 g_warning ("Failed to open log file %s: %s", log_filename, g_strerror (errno));