Merge pull request #10461 from yuwata/small-cleanups

Fixes recent defects reported by coverity
This commit is contained in:
Lennart Poettering 2018-10-24 10:36:20 +02:00 committed by GitHub
commit 086712f99f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 17 deletions

View file

@ -2207,7 +2207,7 @@ static int unit_log_resources(Unit *u) {
/* Format the CPU time for inclusion in the human language message string */
format_timespan(buf, sizeof(buf), nsec / NSEC_PER_USEC, USEC_PER_MSEC);
t = strjoin(n_message_parts > 0 ? "consumed " : "Consumed ", buf, " CPU time");
t = strjoin("consumed ", buf, " CPU time");
if (!t) {
r = log_oom();
goto finish;
@ -2239,18 +2239,14 @@ static int unit_log_resources(Unit *u) {
* bytes counters (and not for the packets counters) */
if (m == CGROUP_IP_INGRESS_BYTES) {
assert(!igress);
igress = strjoin(n_message_parts > 0 ? "received " : "Received ",
format_bytes(buf, sizeof(buf), value),
" IP traffic");
igress = strjoin("received ", format_bytes(buf, sizeof(buf), value), " IP traffic");
if (!igress) {
r = log_oom();
goto finish;
}
} else if (m == CGROUP_IP_EGRESS_BYTES) {
assert(!egress);
egress = strjoin(igress || n_message_parts > 0 ? "sent " : "Sent ",
format_bytes(buf, sizeof(buf), value),
" IP traffic");
egress = strjoin("sent ", format_bytes(buf, sizeof(buf), value), " IP traffic");
if (!egress) {
r = log_oom();
goto finish;
@ -2266,7 +2262,7 @@ static int unit_log_resources(Unit *u) {
} else {
char *k;
k = strdup(n_message_parts > 0 ? "no IP traffic" : "No IP traffic");
k = strdup("no IP traffic");
if (!k) {
r = log_oom();
goto finish;
@ -2294,6 +2290,7 @@ static int unit_log_resources(Unit *u) {
goto finish;
}
joined[0] = ascii_toupper(joined[0]);
t = strjoina("MESSAGE=", u->id, ": ", joined, ".");
}

View file

@ -81,10 +81,10 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
char *l;
int k;
r = read_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(errno, "Failed to read file '%s': %m", path);
if (r == 0)
k = read_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", path);
if (k == 0)
break;
l = strstrip(line);
@ -94,7 +94,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
continue;
k = module_load_and_warn(ctx, l, true);
if (k < 0 && r == 0)
if (k < 0 && r >= 0)
r = k;
}

View file

@ -37,7 +37,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s
int main(int argc, char *argv[]) {
_cleanup_free_ char *packet = NULL;
_cleanup_close_ int fd = -1;
size_t length;
size_t length = 0;
int r;
log_set_target(LOG_TARGET_AUTO);

View file

@ -331,8 +331,8 @@ int info_main(int argc, char *argv[], void *userdata) {
break;
case 'd':
action = ACTION_DEVICE_ID_FILE;
name = strdup(optarg);
if (!name)
r = free_and_strdup(&name, optarg);
if (r < 0)
return log_oom();
break;
case 'a':

View file

@ -200,7 +200,7 @@ static int parse_argv(int argc, char *argv[]) {
int monitor_main(int argc, char *argv[], void *userdata) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *kernel_monitor = NULL, *udev_monitor = NULL;
_cleanup_(sd_event_unrefp) sd_event *event;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
int r;
r = parse_argv(argc, argv);