Coverage Report

Created: 2026-07-30 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/systemd/src/journal-remote/journal-remote-parse.c
Line
Count
Source
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3
#include "sd-event.h"
4
5
#include "alloc-util.h"
6
#include "journal-remote-parse.h"
7
#include "log.h"
8
9
5.99k
RemoteSource* source_free(RemoteSource *source) {
10
5.99k
        if (!source)
11
0
                return NULL;
12
13
5.99k
        journal_importer_cleanup(&source->importer);
14
15
5.99k
        log_trace("Writer ref count %u", source->writer->n_ref);
16
5.99k
        writer_unref(source->writer);
17
18
5.99k
        sd_event_source_unref(source->event);
19
5.99k
        sd_event_source_unref(source->buffer_event);
20
21
5.99k
        free(source->encoding);
22
5.99k
        return mfree(source);
23
5.99k
}
24
25
/**
26
 * Initialize zero-filled source with given values. On success, takes
27
 * ownership of fd and writer, otherwise does not touch them. Always takes
28
 * ownership of name, even on failure.
29
 */
30
5.99k
RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer) {
31
5.99k
        RemoteSource *source;
32
33
5.99k
        log_debug("Creating source for %sfd:%d (%s)",
34
5.99k
                  passive_fd ? "passive " : "", fd, name);
35
36
5.99k
        assert(fd >= 0);
37
38
5.99k
        source = new0(RemoteSource, 1);
39
5.99k
        if (!source) {
40
0
                free(name);
41
0
                return NULL;
42
0
        }
43
44
5.99k
        source->importer = JOURNAL_IMPORTER_MAKE(fd);
45
5.99k
        source->importer.passive_fd = passive_fd;
46
5.99k
        source->importer.name = name;
47
48
5.99k
        source->writer = writer;
49
50
5.99k
        return source;
51
5.99k
}
52
53
1.70M
int process_source(RemoteSource *source, JournalFileFlags file_flags) {
54
1.70M
        int r;
55
56
1.70M
        assert(source);
57
1.70M
        assert(source->writer);
58
59
1.70M
        r = journal_importer_process_data(&source->importer);
60
1.70M
        if (r <= 0)
61
993k
                return r;
62
63
        /* We have a full event */
64
714k
        log_trace("Received full event from source@%p fd:%d (%s)",
65
714k
                  source, source->importer.fd, source->importer.name);
66
67
714k
        if (source->importer.iovw.count == 0) {
68
22.1k
                log_warning("Entry with no payload, skipping");
69
22.1k
                goto freeing;
70
22.1k
        }
71
72
692k
        assert(source->importer.iovw.iovec);
73
74
692k
        r = writer_write(source->writer,
75
692k
                         &source->importer.iovw,
76
692k
                         &source->importer.ts,
77
692k
                         &source->importer.boot_id,
78
692k
                         file_flags);
79
692k
        if (IN_SET(r, -EBADMSG, -EADDRNOTAVAIL)) {
80
5.59k
                log_warning_errno(r, "Entry is invalid, ignoring.");
81
5.59k
                r = 0;
82
686k
        } else if (r < 0)
83
686k
                log_error_errno(r, "Failed to write entry of %zu bytes: %m",
84
686k
                                iovw_size(&source->importer.iovw));
85
686k
        else
86
686k
                r = 1;
87
88
714k
 freeing:
89
714k
        journal_importer_drop_iovw(&source->importer);
90
714k
        return r;
91
692k
}