* mu-log: create log dir if needed; don't try to close -1 sockets
This commit is contained in:
18
src/mu-log.c
18
src/mu-log.c
@ -29,6 +29,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mu-log.h"
|
#include "mu-log.h"
|
||||||
|
#include "mu-util.h"
|
||||||
|
|
||||||
#define MU_LOG_FILE "mu.log"
|
#define MU_LOG_FILE "mu.log"
|
||||||
|
|
||||||
@ -46,11 +47,15 @@ static void log_write (const char* domain, GLogLevelFlags level,
|
|||||||
|
|
||||||
static MuLog* MU_LOG = NULL;
|
static MuLog* MU_LOG = NULL;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
try_close (int fd)
|
_try_close (int fd)
|
||||||
{
|
{
|
||||||
|
if (fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (close (fd) < 0)
|
if (close (fd) < 0)
|
||||||
fprintf (stderr, "%s: close() of fd %d failed: %s\n",
|
g_printerr ("%s: close() of fd %d failed: %s\n",
|
||||||
__FUNCTION__, fd, strerror(errno));
|
__FUNCTION__, fd, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +119,11 @@ mu_log_init (const char* muhome, gboolean append, gboolean debug)
|
|||||||
g_return_val_if_fail (!MU_LOG, FALSE);
|
g_return_val_if_fail (!MU_LOG, FALSE);
|
||||||
g_return_val_if_fail (muhome, FALSE);
|
g_return_val_if_fail (muhome, FALSE);
|
||||||
|
|
||||||
|
if (!mu_util_create_dir_maybe(muhome)) {
|
||||||
|
g_warning ("Failed to init log in %s", muhome);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
logfile = g_strdup_printf ("%s%c%s", muhome,
|
logfile = g_strdup_printf ("%s%c%s", muhome,
|
||||||
G_DIR_SEPARATOR, MU_LOG_FILE);
|
G_DIR_SEPARATOR, MU_LOG_FILE);
|
||||||
fd = open (logfile, O_WRONLY|O_CREAT|(append ? O_APPEND : O_TRUNC),
|
fd = open (logfile, O_WRONLY|O_CREAT|(append ? O_APPEND : O_TRUNC),
|
||||||
@ -124,7 +134,7 @@ mu_log_init (const char* muhome, gboolean append, gboolean debug)
|
|||||||
g_free (logfile);
|
g_free (logfile);
|
||||||
|
|
||||||
if (fd < 0 || !mu_log_init_with_fd (fd, FALSE, debug)) {
|
if (fd < 0 || !mu_log_init_with_fd (fd, FALSE, debug)) {
|
||||||
try_close (fd);
|
_try_close (fd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +149,7 @@ mu_log_uninit (void)
|
|||||||
g_return_if_fail (MU_LOG);
|
g_return_if_fail (MU_LOG);
|
||||||
|
|
||||||
if (MU_LOG->_own)
|
if (MU_LOG->_own)
|
||||||
try_close (MU_LOG->_fd);
|
_try_close (MU_LOG->_fd);
|
||||||
|
|
||||||
g_free (MU_LOG);
|
g_free (MU_LOG);
|
||||||
MU_LOG = NULL;
|
MU_LOG = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user