Skip to content

Commit 2d88def

Browse files
authored
Merge pull request systemd#4133 from keszybz/strerror-removal
Strerror removal and other janitorial cleanups
2 parents 34210af + e031c22 commit 2d88def

File tree

19 files changed

+98
-103
lines changed

19 files changed

+98
-103
lines changed

TODO

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ External:
2323

2424
Janitorial Clean-ups:
2525

26-
* code cleanup: retire FOREACH_WORD_QUOTED, port to extract_first_word() loops instead
26+
* code cleanup: retire FOREACH_WORD_QUOTED, port to extract_first_word() loops instead.
27+
For example, most conf parsing callbacks should use it.
2728

2829
* replace manual readdir() loops with FOREACH_DIRENT or FOREACH_DIRENT_ALL
2930

30-
* Get rid of the last strerror() invocations in favour of %m and strerror_r()
31-
3231
* Rearrange tests so that the various test-xyz.c match a specific src/basic/xyz.c again
3332

3433
Features:
@@ -114,8 +113,6 @@ Features:
114113
* journald: sigbus API via a signal-handler safe function that people may call
115114
from the SIGBUS handler
116115

117-
* when using UTF8, ellipsize with "…" rather than "...", so that we can show more contents before truncating
118-
119116
* move specifier expansion from service_spawn() into load-fragment.c
120117

121118
* optionally, also require WATCHDOG=1 notifications during service start-up and shutdown
@@ -200,7 +197,7 @@ Features:
200197
* synchronize console access with BSD locks:
201198
http://lists.freedesktop.org/archives/systemd-devel/2014-October/024582.html
202199

203-
* as soon as we have kdbus, and sender timestamps, revisit coalescing multiple parallel daemon reloads:
200+
* as soon as we have sender timestamps, revisit coalescing multiple parallel daemon reloads:
204201
http://lists.freedesktop.org/archives/systemd-devel/2014-December/025862.html
205202

206203
* in systemctl list-unit-files: show the install value the presets would suggest for a service in a third column
@@ -240,10 +237,6 @@ Features:
240237

241238
* timesyncd: add ugly bus calls to set NTP servers per-interface, for usage by NM
242239

243-
* extract_many_words() should probably be used by a lot of code that
244-
currently uses FOREACH_WORD and friends. For example, most conf
245-
parsing callbacks should use it.
246-
247240
* merge ~/.local/share and ~/.local/lib into one similar /usr/lib and /usr/share....
248241

249242
* systemd.show_status= should probably have a mode where only failed

man/dnssec-trust-anchors.d.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,12 @@
160160
<refsect1>
161161
<title>Negative Trust Anchors</title>
162162

163-
<para>Negative trust anchors define domains where DNSSEC
164-
validation shall be turned off. Negative trust anchor files are
165-
found at the same location as positive trust anchor files, and
166-
follow the same overriding rules. They are text files with the
167-
<filename>.negative</filename> suffix. Empty lines and lines whose
168-
first character is <literal>;</literal> are ignored. Each line
169-
specifies one domain name where DNSSEC validation shall be
170-
disabled on.</para>
163+
<para>Negative trust anchors define domains where DNSSEC validation shall be turned
164+
off. Negative trust anchor files are found at the same location as positive trust anchor files,
165+
and follow the same overriding rules. They are text files with the
166+
<filename>.negative</filename> suffix. Empty lines and lines whose first character is
167+
<literal>;</literal> are ignored. Each line specifies one domain name which is the root of a DNS
168+
subtree where validation shall be disabled.</para>
171169

172170
<para>Negative trust anchors are useful to support private DNS
173171
subtrees that are not referenced from the Internet DNS hierarchy,

src/basic/string-util.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
443443
if (old_length <= 3 || old_length <= new_length)
444444
return strndup(s, old_length);
445445

446-
r = new0(char, new_length+1);
446+
r = new0(char, new_length+3);
447447
if (!r)
448448
return NULL;
449449

@@ -453,12 +453,12 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
453453
x = new_length - 3;
454454

455455
memcpy(r, s, x);
456-
r[x] = '.';
457-
r[x+1] = '.';
458-
r[x+2] = '.';
456+
r[x] = 0xe2; /* tri-dot ellipsis: … */
457+
r[x+1] = 0x80;
458+
r[x+2] = 0xa6;
459459
memcpy(r + x + 3,
460-
s + old_length - (new_length - x - 3),
461-
new_length - x - 3);
460+
s + old_length - (new_length - x - 1),
461+
new_length - x - 1);
462462

463463
return r;
464464
}

src/hostname/hostnamed.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int method_set_hostname(sd_bus_message *m, void *userdata, sd_bus_error *
451451
r = context_update_kernel_hostname(c);
452452
if (r < 0) {
453453
log_error_errno(r, "Failed to set host name: %m");
454-
return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %s", strerror(-r));
454+
return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %m");
455455
}
456456

457457
log_info("Changed host name to '%s'", strna(c->data[PROP_HOSTNAME]));
@@ -512,13 +512,13 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
512512
r = context_update_kernel_hostname(c);
513513
if (r < 0) {
514514
log_error_errno(r, "Failed to set host name: %m");
515-
return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %s", strerror(-r));
515+
return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %m");
516516
}
517517

518518
r = context_write_data_static_hostname(c);
519519
if (r < 0) {
520520
log_error_errno(r, "Failed to write static host name: %m");
521-
return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %s", strerror(-r));
521+
return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %m");
522522
}
523523

524524
log_info("Changed static host name to '%s'", strna(c->data[PROP_STATIC_HOSTNAME]));
@@ -593,7 +593,7 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
593593
r = context_write_data_machine_info(c);
594594
if (r < 0) {
595595
log_error_errno(r, "Failed to write machine info: %m");
596-
return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %s", strerror(-r));
596+
return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %m");
597597
}
598598

599599
log_info("Changed %s to '%s'",

src/journal-remote/journal-gatewayd.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,20 @@ static int request_handler_entries(
475475

476476
r = open_journal(m);
477477
if (r < 0)
478-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %s\n", strerror(-r));
478+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %m");
479479

480480
if (request_parse_accept(m, connection) < 0)
481-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Accept header.\n");
481+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Accept header.");
482482

483483
if (request_parse_range(m, connection) < 0)
484-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Range header.\n");
484+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Range header.");
485485

486486
if (request_parse_arguments(m, connection) < 0)
487-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse URL arguments.\n");
487+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse URL arguments.");
488488

489489
if (m->discrete) {
490490
if (!m->cursor)
491-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Discrete seeks require a cursor specification.\n");
491+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Discrete seeks require a cursor specification.");
492492

493493
m->n_entries = 1;
494494
m->n_entries_set = true;
@@ -501,7 +501,7 @@ static int request_handler_entries(
501501
else if (m->n_skip < 0)
502502
r = sd_journal_seek_tail(m->journal);
503503
if (r < 0)
504-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to seek in journal.\n");
504+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to seek in journal.");
505505

506506
response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 4*1024, request_reader_entries, m, NULL);
507507
if (!response)
@@ -633,14 +633,14 @@ static int request_handler_fields(
633633

634634
r = open_journal(m);
635635
if (r < 0)
636-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %s\n", strerror(-r));
636+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %m");
637637

638638
if (request_parse_accept(m, connection) < 0)
639-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Accept header.\n");
639+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Accept header.");
640640

641641
r = sd_journal_query_unique(m->journal, field);
642642
if (r < 0)
643-
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to query unique fields.\n");
643+
return mhd_respond(connection, MHD_HTTP_BAD_REQUEST, "Failed to query unique fields.");
644644

645645
response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 4*1024, request_reader_fields, m, NULL);
646646
if (!response)
@@ -699,10 +699,10 @@ static int request_handler_file(
699699

700700
fd = open(path, O_RDONLY|O_CLOEXEC);
701701
if (fd < 0)
702-
return mhd_respondf(connection, MHD_HTTP_NOT_FOUND, "Failed to open file %s: %m\n", path);
702+
return mhd_respondf(connection, errno, MHD_HTTP_NOT_FOUND, "Failed to open file %s: %m", path);
703703

704704
if (fstat(fd, &st) < 0)
705-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to stat file: %m\n");
705+
return mhd_respondf(connection, errno, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to stat file: %m");
706706

707707
response = MHD_create_response_from_fd_at_offset64(st.st_size, fd, 0);
708708
if (!response)
@@ -766,27 +766,27 @@ static int request_handler_machine(
766766

767767
r = open_journal(m);
768768
if (r < 0)
769-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %s\n", strerror(-r));
769+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to open journal: %m");
770770

771771
r = sd_id128_get_machine(&mid);
772772
if (r < 0)
773-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine machine ID: %s\n", strerror(-r));
773+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine machine ID: %m");
774774

775775
r = sd_id128_get_boot(&bid);
776776
if (r < 0)
777-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine boot ID: %s\n", strerror(-r));
777+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine boot ID: %m");
778778

779779
hostname = gethostname_malloc();
780780
if (!hostname)
781781
return respond_oom(connection);
782782

783783
r = sd_journal_get_usage(m->journal, &usage);
784784
if (r < 0)
785-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine disk usage: %s\n", strerror(-r));
785+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine disk usage: %s");
786786

787787
r = sd_journal_get_cutoff_realtime_usec(m->journal, &cutoff_from, &cutoff_to);
788788
if (r < 0)
789-
return mhd_respondf(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine disk usage: %s\n", strerror(-r));
789+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "Failed to determine disk usage: %s");
790790

791791
if (parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &os_name, NULL) == -ENOENT)
792792
(void) parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &os_name, NULL);
@@ -844,8 +844,7 @@ static int request_handler(
844844
assert(method);
845845

846846
if (!streq(method, "GET"))
847-
return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE,
848-
"Unsupported method.\n");
847+
return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE, "Unsupported method.");
849848

850849

851850
if (!*connection_cls) {
@@ -875,7 +874,7 @@ static int request_handler(
875874
if (streq(url, "/machine"))
876875
return request_handler_machine(connection, *connection_cls);
877876

878-
return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.\n");
877+
return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.");
879878
}
880879

881880
static void help(void) {

src/journal-remote/journal-remote.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,12 @@ static int process_http_upload(
524524
log_warning("Failed to process data for connection %p", connection);
525525
if (r == -E2BIG)
526526
return mhd_respondf(connection,
527-
MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
528-
"Entry is too large, maximum is %u bytes.\n",
529-
DATA_SIZE_MAX);
527+
r, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
528+
"Entry is too large, maximum is " STRINGIFY(DATA_SIZE_MAX) " bytes.");
530529
else
531530
return mhd_respondf(connection,
532-
MHD_HTTP_UNPROCESSABLE_ENTITY,
533-
"Processing failed: %s.", strerror(-r));
531+
r, MHD_HTTP_UNPROCESSABLE_ENTITY,
532+
"Processing failed: %m.");
534533
}
535534
}
536535

@@ -541,13 +540,14 @@ static int process_http_upload(
541540

542541
remaining = source_non_empty(source);
543542
if (remaining > 0) {
544-
log_warning("Premature EOFbyte. %zu bytes lost.", remaining);
545-
return mhd_respondf(connection, MHD_HTTP_EXPECTATION_FAILED,
543+
log_warning("Premature EOF byte. %zu bytes lost.", remaining);
544+
return mhd_respondf(connection,
545+
0, MHD_HTTP_EXPECTATION_FAILED,
546546
"Premature EOF. %zu bytes of trailing data not processed.",
547547
remaining);
548548
}
549549

550-
return mhd_respond(connection, MHD_HTTP_ACCEPTED, "OK.\n");
550+
return mhd_respond(connection, MHD_HTTP_ACCEPTED, "OK.");
551551
};
552552

553553
static int request_handler(
@@ -577,19 +577,16 @@ static int request_handler(
577577
*connection_cls);
578578

579579
if (!streq(method, "POST"))
580-
return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE,
581-
"Unsupported method.\n");
580+
return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE, "Unsupported method.");
582581

583582
if (!streq(url, "/upload"))
584-
return mhd_respond(connection, MHD_HTTP_NOT_FOUND,
585-
"Not found.\n");
583+
return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.");
586584

587585
header = MHD_lookup_connection_value(connection,
588586
MHD_HEADER_KIND, "Content-Type");
589587
if (!header || !streq(header, "application/vnd.fdo.journal"))
590588
return mhd_respond(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE,
591-
"Content-Type: application/vnd.fdo.journal"
592-
" is required.\n");
589+
"Content-Type: application/vnd.fdo.journal is required.");
593590

594591
{
595592
const union MHD_ConnectionInfo *ci;
@@ -599,7 +596,7 @@ static int request_handler(
599596
if (!ci) {
600597
log_error("MHD_get_connection_info failed: cannot get remote fd");
601598
return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
602-
"Cannot check remote address");
599+
"Cannot check remote address.");
603600
}
604601

605602
fd = ci->connect_fd;
@@ -614,7 +611,7 @@ static int request_handler(
614611
r = getpeername_pretty(fd, false, &hostname);
615612
if (r < 0)
616613
return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
617-
"Cannot check remote hostname");
614+
"Cannot check remote hostname.");
618615
}
619616

620617
assert(hostname);
@@ -623,8 +620,7 @@ static int request_handler(
623620
if (r == -ENOMEM)
624621
return respond_oom(connection);
625622
else if (r < 0)
626-
return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
627-
strerror(-r));
623+
return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "%m");
628624

629625
hostname = NULL;
630626
return MHD_YES;

src/journal-remote/microhttpd-util.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ void microhttpd_logger(void *arg, const char *fmt, va_list ap) {
4848

4949
static int mhd_respond_internal(struct MHD_Connection *connection,
5050
enum MHD_RequestTerminationCode code,
51-
char *buffer,
51+
const char *buffer,
5252
size_t size,
5353
enum MHD_ResponseMemoryMode mode) {
5454
struct MHD_Response *response;
5555
int r;
5656

5757
assert(connection);
5858

59-
response = MHD_create_response_from_buffer(size, buffer, mode);
59+
response = MHD_create_response_from_buffer(size, (char*) buffer, mode);
6060
if (!response)
6161
return MHD_NO;
6262

@@ -72,28 +72,38 @@ int mhd_respond(struct MHD_Connection *connection,
7272
enum MHD_RequestTerminationCode code,
7373
const char *message) {
7474

75+
const char *fmt;
76+
77+
fmt = strjoina(message, "\n");
78+
7579
return mhd_respond_internal(connection, code,
76-
(char*) message, strlen(message),
80+
fmt, strlen(message) + 1,
7781
MHD_RESPMEM_PERSISTENT);
7882
}
7983

8084
int mhd_respond_oom(struct MHD_Connection *connection) {
81-
return mhd_respond(connection, MHD_HTTP_SERVICE_UNAVAILABLE, "Out of memory.\n");
85+
return mhd_respond(connection, MHD_HTTP_SERVICE_UNAVAILABLE, "Out of memory.");
8286
}
8387

8488
int mhd_respondf(struct MHD_Connection *connection,
89+
int error,
8590
enum MHD_RequestTerminationCode code,
8691
const char *format, ...) {
8792

93+
const char *fmt;
8894
char *m;
8995
int r;
9096
va_list ap;
9197

9298
assert(connection);
9399
assert(format);
94100

101+
if (error < 0)
102+
error = -error;
103+
errno = -error;
104+
fmt = strjoina(format, "\n");
95105
va_start(ap, format);
96-
r = vasprintf(&m, format, ap);
106+
r = vasprintf(&m, fmt, ap);
97107
va_end(ap);
98108

99109
if (r < 0)

0 commit comments

Comments
 (0)