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

systemd / systemd / 18810271929

25 Oct 2025 04:50PM UTC coverage: 72.26%. Remained the same
18810271929

push

github

YHNdnzj
core/exec-invoke: relax restriction for process name length

Previously, we limit the length of process name by 8.
This relax the restriction then at least process comm or
program_invocation_name contains the untrucated process name.

Closes #38367.

24 of 28 new or added lines in 3 files covered. (85.71%)

486 existing lines in 52 files now uncovered.

304829 of 421852 relevant lines covered (72.26%)

1095984.64 hits per line

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

48.36
/src/shared/qrcode-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "qrcode-util.h"
4

5
#if HAVE_QRENCODE
6
#include <qrencode.h>
7
#endif
8
#include <stdio.h>
9

10
#include "ansi-color.h"
11
#include "dlfcn-util.h"
12
#include "locale-util.h"
13
#include "log.h"
14
#include "strv.h"
15
#include "terminal-util.h"
16

17
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
18
#define UNICODE_FULL_BLOCK       UTF8("â–ˆ")
19
#define UNICODE_LOWER_HALF_BLOCK UTF8("â–„")
20
#define UNICODE_UPPER_HALF_BLOCK UTF8("â–€")
21

22
#if HAVE_QRENCODE
23
static void *qrcode_dl = NULL;
24

25
static DLSYM_PROTOTYPE(QRcode_encodeString) = NULL;
26
static DLSYM_PROTOTYPE(QRcode_free) = NULL;
27
#endif
28

29
int dlopen_qrencode(void) {
2✔
30
#if HAVE_QRENCODE
31
        int r;
2✔
32

33
        ELF_NOTE_DLOPEN("qrencode",
2✔
34
                        "Support for generating QR codes",
35
                        ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
36
                        "libqrencode.so.4", "libqrencode.so.3");
37

38
        FOREACH_STRING(s, "libqrencode.so.4", "libqrencode.so.3") {
2✔
39
                r = dlopen_many_sym_or_warn(
2✔
40
                        &qrcode_dl, s, LOG_DEBUG,
41
                        DLSYM_ARG(QRcode_encodeString),
42
                        DLSYM_ARG(QRcode_free));
43
                if (r >= 0)
2✔
44
                        break;
45
        }
46

47
        return r;
2✔
48
#else
49
        return -EOPNOTSUPP;
50
#endif
51
}
52

53
#if HAVE_QRENCODE
54

55
static void print_border(FILE *output, unsigned width, unsigned row, unsigned column) {
2✔
56
        assert(output);
2✔
57
        assert(width);
2✔
58

59
        if (row != UINT_MAX && column != UINT_MAX) {
2✔
60
                int r, fd;
×
61

62
                fd = fileno(output);
×
63
                if (fd < 0)
×
64
                        return (void)log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
×
65

66
                r = terminal_set_cursor_position(fd, row, column);
×
67
                if (r < 0)
×
68
                        log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
×
69

70
                /* Four rows of border */
71
                for (unsigned y = 0; y < 4; y += 2) {
×
72
                        fputs(ANSI_WHITE_ON_BLACK, output);
×
73

74
                        for (unsigned x = 0; x < 4 + width + 4; x++)
×
75
                                fputs(UNICODE_FULL_BLOCK, output);
×
76

77
                        fputs(ANSI_NORMAL "\n", output);
×
78
                        r = terminal_set_cursor_position(fd, row + 1, column);
×
79
                        if (r < 0)
×
80
                                log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
×
81
                }
82
        } else {
83
                /* Four rows of border */
84
                for (unsigned y = 0; y < 4; y += 2) {
6✔
85
                        fputs(ANSI_WHITE_ON_BLACK, output);
4✔
86

87
                        for (unsigned x = 0; x < 4 + width + 4; x++)
120✔
88
                                fputs(UNICODE_FULL_BLOCK, output);
116✔
89

90
                        fputs(ANSI_NORMAL "\n", output);
4✔
91
                }
92
        }
93
}
94

95
static void write_qrcode(FILE *output, QRcode *qr, unsigned row, unsigned column) {
1✔
96
        assert(qr);
1✔
97

98
        if (!output)
1✔
99
                output = stdout;
×
100

101
        print_border(output, qr->width, row, column);
1✔
102

103
        if (row != UINT_MAX && column != UINT_MAX) {
1✔
104
                /* After printing two rows of top border, we need to move the cursor down two rows before starting to print the actual QR code */
105
                int r, fd, move_down = 2;
×
106
                fd = fileno(output);
×
107
                if (fd < 0)
×
108
                        return (void)log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
×
109

110
                r = terminal_set_cursor_position(fd, row + move_down, column);
×
111
                if (r < 0)
×
112
                        log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
×
113

114
                for (unsigned y = 0; y < (unsigned) qr->width; y += 2) {
×
115
                        const uint8_t *row1 = qr->data + qr->width * y;
×
116
                        const uint8_t *row2 = row1 + qr->width;
×
117

118
                        fputs(ANSI_WHITE_ON_BLACK, output);
×
119

120
                        for (unsigned x = 0; x < 4; x++)
×
121
                                fputs(UNICODE_FULL_BLOCK, output);
×
122

123
                        for (unsigned x = 0; x < (unsigned) qr->width; x++) {
×
124
                                bool a, b;
×
125

126
                                a = row1[x] & 1;
×
127
                                b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;
×
128

129
                                if (a && b)
×
130
                                        fputc(' ', output);
×
131
                                else if (a)
×
132
                                        fputs(UNICODE_LOWER_HALF_BLOCK, output);
×
133
                                else if (b)
×
134
                                        fputs(UNICODE_UPPER_HALF_BLOCK, output);
×
135
                                else
136
                                        fputs(UNICODE_FULL_BLOCK, output);
×
137
                        }
138

139
                        for (unsigned x = 0; x < 4; x++)
×
140
                                fputs(UNICODE_FULL_BLOCK, output);
×
141
                        r = terminal_set_cursor_position(fd, row + move_down, column);
×
142
                        if (r < 0)
×
143
                                log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
×
144
                        move_down += 1;
×
145
                        fputs(ANSI_NORMAL "\n", output);
×
146
                }
147

148
                print_border(output, qr->width, row + move_down, column);
×
149
        } else {
150

151
                for (unsigned y = 0; y < (unsigned) qr->width; y += 2) {
12✔
152
                        const uint8_t *row1 = qr->data + qr->width * y;
11✔
153
                        const uint8_t *row2 = row1 + qr->width;
11✔
154

155
                        fputs(ANSI_WHITE_ON_BLACK, output);
11✔
156
                        for (unsigned x = 0; x < 4; x++)
55✔
157
                                fputs(UNICODE_FULL_BLOCK, output);
44✔
158

159
                        for (unsigned x = 0; x < (unsigned) qr->width; x++) {
242✔
160
                                bool a, b;
231✔
161

162
                                a = row1[x] & 1;
231✔
163
                                b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;
231✔
164

165
                                if (a && b)
210✔
166
                                        fputc(' ', output);
60✔
167
                                else if (a)
171✔
168
                                        fputs(UNICODE_LOWER_HALF_BLOCK, output);
89✔
169
                                else if (b)
82✔
170
                                        fputs(UNICODE_UPPER_HALF_BLOCK, output);
29✔
171
                                else
172
                                        fputs(UNICODE_FULL_BLOCK, output);
53✔
173
                        }
174

175
                        for (unsigned x = 0; x < 4; x++)
55✔
176
                                fputs(UNICODE_FULL_BLOCK, output);
44✔
177
                        fputs(ANSI_NORMAL "\n", output);
11✔
178
                }
179

180
                print_border(output, qr->width, row, column);
1✔
181
        }
182

183
        fflush(output);
1✔
184
}
185

186
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(QRcode*, sym_QRcode_free, QRcode_freep, NULL);
1✔
187

188
#endif
189

190
int print_qrcode_full(
14✔
191
                FILE *out,
192
                const char *header,
193
                const char *string,
194
                unsigned row,
195
                unsigned column,
196
                unsigned tty_width,
197
                unsigned tty_height,
198
                bool check_tty) {
199

200
#if HAVE_QRENCODE
201
        int r;
14✔
202

203
        /* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
204
         * codes */
205
        if (!is_locale_utf8())
14✔
206
                return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not an UTF-8 system, cannot print qrcode");
14✔
207
        if (check_tty && !colors_enabled())
28✔
208
                return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Colors are disabled, cannot print qrcode");
13✔
209

210
        r = dlopen_qrencode();
1✔
211
        if (r < 0)
1✔
212
                return r;
213

214
        _cleanup_(QRcode_freep) QRcode *qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
2✔
215
        if (!qr)
1✔
UNCOV
216
                return log_oom_debug();
×
217

218
        if (row != UINT_MAX && column != UINT_MAX) {
1✔
UNCOV
219
                unsigned qr_code_width, qr_code_height;
×
220

UNCOV
221
                int fd = fileno(out);
×
222
                if (fd < 0)
×
223
                        return log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
×
224

UNCOV
225
                qr_code_width = qr_code_height = qr->width + 8;
×
226
                if (column + qr_code_width > tty_width)
×
227
                        column = tty_width - qr_code_width;
×
228

229
                /* Terminal characters are twice as high as they are wide so it's qr_code_height / 2,
230
                 * our QR code prints an extra new line, so we have -1 as well */
UNCOV
231
                if (row + qr_code_height > tty_height)
×
232
                        row = tty_height - (qr_code_height / 2 ) - 1;
×
233

UNCOV
234
                if (header) {
×
235
                        r = terminal_set_cursor_position(fd, row - 2, tty_width - qr_code_width - 2);
×
236
                        if (r < 0)
×
237
                                log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
×
238

UNCOV
239
                        fprintf(out, "%s:\n\n", header);
×
240
                }
241
        } else
242
                if (header)
1✔
243
                        fprintf(out, "\n%s:\n\n", header);
1✔
244

245
        write_qrcode(out, qr, row, column);
1✔
246
        fputc('\n', out);
1✔
247

248
        return 0;
249
#else
250
        return -EOPNOTSUPP;
251
#endif
252
}
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