• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jcbf / smf-spf / 21120233602

18 Jan 2026 11:10PM UTC coverage: 14.381% (-0.5%) from 14.867%
21120233602

Pull #106

github

web-flow
Merge be3e4dbae into 6baf0fe8d
Pull Request #106: Fix/logto stderr error

95 of 387 new or added lines in 6 files covered. (24.55%)

3 existing lines in 1 file now uncovered.

108 of 751 relevant lines covered (14.38%)

0.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/utils/logging.c
1
/*
2
 * logging.c - Logging abstraction for smf-spf
3
 *
4
 * This file is part of smf-spf.
5
 *
6
 * smf-spf is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * smf-spf is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 */
16

17
#include "logging.h"
18
#include <stdarg.h>
19
#include <string.h>
20
#include <time.h>
21
#include <unistd.h>
22

23
/* Module state */
24
static const char *g_daemon_name = NULL;
25
static int g_syslog_facility = SYSLOG_DISABLE;
26
static FILE *g_log_file = NULL;
27
static const char *g_hostname = NULL;
28

NEW
29
void log_init(const char *daemon_name, int syslog_facility,
×
30
              FILE *log_file, const char *hostname) {
NEW
31
    g_daemon_name = daemon_name;
×
NEW
32
    g_syslog_facility = syslog_facility;
×
NEW
33
    g_log_file = log_file;
×
NEW
34
    g_hostname = hostname;
×
35

NEW
36
    if (g_syslog_facility != SYSLOG_DISABLE) {
×
NEW
37
        openlog(daemon_name, LOG_PID | LOG_NDELAY, syslog_facility);
×
38
    }
NEW
39
}
×
40

NEW
41
void log_message(int log_level, const char *fmt, ...) {
×
42
    va_list ap;
43

44
    /* Log to file if configured */
NEW
45
    if (g_log_file) {
×
46
        char time_str[32];
47
        struct tm *tm;
NEW
48
        time_t now = time(0);
×
49

NEW
50
        tm = localtime(&now);
×
NEW
51
        strftime(time_str, sizeof(time_str), "%h %e %T", tm);
×
52

NEW
53
        fprintf(g_log_file, "%s %s %s[%d]: ",
×
54
                time_str,
NEW
55
                g_hostname ? g_hostname : "localhost",
×
NEW
56
                g_daemon_name ? g_daemon_name : "smf-spf",
×
NEW
57
                (int)getpid());
×
58

NEW
59
        va_start(ap, fmt);
×
NEW
60
        vfprintf(g_log_file, fmt, ap);
×
NEW
61
        va_end(ap);
×
62

NEW
63
        fprintf(g_log_file, "\n");
×
NEW
64
        fflush(g_log_file);
×
65
    }
66

67
    /* Log to syslog if configured */
NEW
68
    if (g_syslog_facility != SYSLOG_DISABLE) {
×
NEW
69
        va_start(ap, fmt);
×
70
        vsyslog(log_level, fmt, ap);
NEW
71
        va_end(ap);
×
72
    }
NEW
73
}
×
74

NEW
75
void log_shutdown(void) {
×
NEW
76
    if (g_syslog_facility != SYSLOG_DISABLE) {
×
NEW
77
        closelog();
×
78
    }
79

NEW
80
    g_daemon_name = NULL;
×
NEW
81
    g_syslog_facility = SYSLOG_DISABLE;
×
NEW
82
    g_log_file = NULL;
×
NEW
83
    g_hostname = NULL;
×
NEW
84
}
×
85

NEW
86
void log_set_file(FILE *log_file) {
×
NEW
87
    g_log_file = log_file;
×
NEW
88
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc