[systemd-commits] 2 commits - src/nspawn src/random-seed src/shared src/timedate
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Apr 21 09:10:49 PDT 2015
src/nspawn/nspawn.c | 11 ++++---
src/random-seed/random-seed.c | 60 +++++++++++++++++++++---------------------
src/shared/logs-show.c | 8 ++---
src/timedate/timedated.c | 6 ++--
4 files changed, 43 insertions(+), 42 deletions(-)
New commits:
commit 1509fb87c0269a76a76e0badb07156c98a053ba2
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Apr 21 18:08:09 2015 +0200
random-seed: minor cleanups, in particular when it comes to logging
diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c
index ce1bd19..92176b1 100644
--- a/src/random-seed/random-seed.c
+++ b/src/random-seed/random-seed.c
@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
ssize_t k;
int r;
FILE *f;
- bool cleanup_seed_file = true;
+ bool refresh_seed_file = true;
if (argc != 2) {
log_error("This program requires one argument.");
@@ -87,33 +87,29 @@ int main(int argc, char *argv[]) {
if (seed_fd < 0) {
seed_fd = open(RANDOM_SEED, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (seed_fd < 0) {
- log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
- r = -errno;
+ r = log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
goto finish;
}
- cleanup_seed_file = false;
+
+ refresh_seed_file = false;
}
random_fd = open("/dev/urandom", O_RDWR|O_CLOEXEC|O_NOCTTY, 0600);
if (random_fd < 0) {
random_fd = open("/dev/urandom", O_WRONLY|O_CLOEXEC|O_NOCTTY, 0600);
if (random_fd < 0) {
- log_error_errno(errno, "Failed to open /dev/urandom: %m");
- r = -errno;
+ r = log_error_errno(errno, "Failed to open /dev/urandom: %m");
goto finish;
}
}
k = loop_read(seed_fd, buf, buf_size, false);
- if (k <= 0) {
-
- if (r != 0)
- log_error_errno(errno, "Failed to read seed from " RANDOM_SEED ": %m");
-
- r = k == 0 ? -EIO : (int) k;
-
- } else {
- lseek(seed_fd, 0, SEEK_SET);
+ if (k < 0)
+ r = log_error_errno(k, "Failed to read seed from " RANDOM_SEED ": %m");
+ else if (k == 0)
+ log_debug("Seed file " RANDOM_SEED " not yet initialized, proceeding.");
+ else {
+ (void) lseek(seed_fd, 0, SEEK_SET);
r = loop_write(random_fd, buf, (size_t) k, false);
if (r < 0)
@@ -124,40 +120,44 @@ int main(int argc, char *argv[]) {
seed_fd = open(RANDOM_SEED, O_WRONLY|O_CLOEXEC|O_NOCTTY|O_CREAT, 0600);
if (seed_fd < 0) {
- log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
- r = -errno;
+ r = log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
goto finish;
}
random_fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (random_fd < 0) {
- log_error_errno(errno, "Failed to open /dev/urandom: %m");
- r = -errno;
+ r = log_error_errno(errno, "Failed to open /dev/urandom: %m");
goto finish;
}
} else {
- log_error("Unknown verb %s.", argv[1]);
+ log_error("Unknown verb '%s'.", argv[1]);
r = -EINVAL;
goto finish;
}
- if (cleanup_seed_file) {
+ if (refresh_seed_file) {
+
/* This is just a safety measure. Given that we are root and
* most likely created the file ourselves the mode and owner
* should be correct anyway. */
- fchmod(seed_fd, 0600);
- fchown(seed_fd, 0, 0);
+ (void) fchmod(seed_fd, 0600);
+ (void) fchown(seed_fd, 0, 0);
k = loop_read(random_fd, buf, buf_size, false);
- if (k <= 0) {
- log_error("Failed to read new seed from /dev/urandom: %s", r < 0 ? strerror(-r) : "EOF");
- r = k == 0 ? -EIO : (int) k;
- } else {
- r = loop_write(seed_fd, buf, (size_t) k, false);
- if (r < 0)
- log_error_errno(r, "Failed to write new random seed file: %m");
+ if (k < 0) {
+ r = log_error_errno(k, "Failed to read new seed from /dev/urandom: %m");
+ goto finish;
}
+ if (k == 0) {
+ log_error("Got EOF while reading from /dev/urandom.");
+ r = -EIO;
+ goto finish;
+ }
+
+ r = loop_write(seed_fd, buf, (size_t) k, false);
+ if (r < 0)
+ log_error_errno(r, "Failed to write new random seed file: %m");
}
finish:
commit 10a8700606d832ba88706f35e63d37b98c409d10
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Apr 21 18:05:44 2015 +0200
tree-wide: get rid of more strerror() calls
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 6d4aadd..1a9b3be 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2139,11 +2139,12 @@ static int reset_audit_loginuid(void) {
r = write_string_file("/proc/self/loginuid", "4294967295");
if (r < 0) {
- log_error("Failed to reset audit login UID. This probably means that your kernel is too\n"
- "old and you have audit enabled. Note that the auditing subsystem is known to\n"
- "be incompatible with containers on old kernels. Please make sure to upgrade\n"
- "your kernel or to off auditing with 'audit=0' on the kernel command line before\n"
- "using systemd-nspawn. Sleeping for 5s... (%s)\n", strerror(-r));
+ log_error_errno(r,
+ "Failed to reset audit login UID. This probably means that your kernel is too\n"
+ "old and you have audit enabled. Note that the auditing subsystem is known to\n"
+ "be incompatible with containers on old kernels. Please make sure to upgrade\n"
+ "your kernel or to off auditing with 'audit=0' on the kernel command line before\n"
+ "using systemd-nspawn. Sleeping for 5s... (%m)");
sleep(5);
}
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 27f4072..54179e9 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -409,8 +409,8 @@ static int output_verbose(
if (r == -ENOENT)
log_debug("Source realtime timestamp not found");
else if (r < 0) {
- log_full(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_ERR,
- "Failed to get source realtime timestamp: %s", strerror(-r));
+ log_full_errno(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_ERR, r,
+ "Failed to get source realtime timestamp: %m");
return r;
} else {
_cleanup_free_ char *value = NULL;
@@ -429,8 +429,8 @@ static int output_verbose(
if (r < 0) {
r = sd_journal_get_realtime_usec(j, &realtime);
if (r < 0) {
- log_full(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_ERR,
- "Failed to get realtime timestamp: %s", strerror(-r));
+ log_full_errno(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_ERR, r,
+ "Failed to get realtime timestamp: %m");
return r;
}
}
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 0d4a9dd..d48fc82 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -326,7 +326,7 @@ static int property_get_rtc_time(
log_debug("/dev/rtc not found.");
t = 0; /* no RTC found */
} else if (r < 0)
- return sd_bus_error_set_errnof(error, r, "Failed to read RTC: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to read RTC: %m");
else
t = (usec_t) timegm(&tm) * USEC_PER_SEC;
@@ -402,7 +402,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, s
r = context_write_data_timezone(c);
if (r < 0) {
log_error_errno(r, "Failed to set time zone: %m");
- return sd_bus_error_set_errnof(error, r, "Failed to set time zone: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set time zone: %m");
}
/* 2. Tell the kernel our timezone */
@@ -465,7 +465,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata,
r = context_write_data_local_rtc(c);
if (r < 0) {
log_error_errno(r, "Failed to set RTC to local/UTC: %m");
- return sd_bus_error_set_errnof(error, r, "Failed to set RTC to local/UTC: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set RTC to local/UTC: %m");
}
/* 2. Tell the kernel our timezone */
More information about the systemd-commits
mailing list