1
0
mirror of https://github.com/systemd/systemd.git synced 2025-09-09 17:44:49 +03:00

Merge pull request #2996 from keszybz/coverity-fixes

Coverity fixes
This commit is contained in:
Martin Pitt
2016-04-11 11:19:27 +02:00
13 changed files with 49 additions and 46 deletions

View File

@@ -419,13 +419,17 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
if (!stdout_is_tty) if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
dup2(fd, STDOUT_FILENO); log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
_exit(EXIT_FAILURE);
}
if (!stderr_is_tty) if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
dup2(fd, STDERR_FILENO); log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
_exit(EXIT_FAILURE);
}
if (fd > 2) if (fd > STDERR_FILENO)
close(fd); close(fd);
} }

View File

@@ -110,16 +110,14 @@ int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
} else { } else {
exists = true; exists = true;
/* Path exists, we don't need to watch parent /* Path exists, we don't need to watch parent too closely. */
too closely. */
if (oldslash) { if (oldslash) {
char *cut2 = oldslash + (oldslash == s->path); char *cut2 = oldslash + (oldslash == s->path);
char tmp2 = *cut2; char tmp2 = *cut2;
*cut2 = '\0'; *cut2 = '\0';
inotify_add_watch(s->inotify_fd, s->path, IN_MOVE_SELF); (void) inotify_add_watch(s->inotify_fd, s->path, IN_MOVE_SELF);
/* Error is ignored, the worst can happen is /* Error is ignored, the worst can happen is we get spurious events. */
we get spurious events. */
*cut2 = tmp2; *cut2 = tmp2;
} }

View File

@@ -832,7 +832,7 @@ static int service_load_pid_file(Service *s, bool may_warn) {
return 0; return 0;
} }
static int service_search_main_pid(Service *s) { static void service_search_main_pid(Service *s) {
pid_t pid = 0; pid_t pid = 0;
int r; int r;
@@ -841,30 +841,24 @@ static int service_search_main_pid(Service *s) {
/* If we know it anyway, don't ever fallback to unreliable /* If we know it anyway, don't ever fallback to unreliable
* heuristics */ * heuristics */
if (s->main_pid_known) if (s->main_pid_known)
return 0; return;
if (!s->guess_main_pid) if (!s->guess_main_pid)
return 0; return;
assert(s->main_pid <= 0); assert(s->main_pid <= 0);
r = unit_search_main_pid(UNIT(s), &pid); if (unit_search_main_pid(UNIT(s), &pid) < 0)
if (r < 0) return;
return r;
log_unit_debug(UNIT(s), "Main PID guessed: "PID_FMT, pid); log_unit_debug(UNIT(s), "Main PID guessed: "PID_FMT, pid);
r = service_set_main_pid(s, pid); if (service_set_main_pid(s, pid) < 0)
if (r < 0) return;
return r;
r = unit_watch_pid(UNIT(s), pid); r = unit_watch_pid(UNIT(s), pid);
if (r < 0) { if (r < 0)
/* FIXME: we need to do something here */ /* FIXME: we need to do something here */
log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" from: %m", pid); log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" from: %m", pid);
return r;
}
return 0;
} }
static void service_set_state(Service *s, ServiceState state) { static void service_set_state(Service *s, ServiceState state) {
@@ -2729,7 +2723,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
break; break;
} }
} else } else
(void) service_search_main_pid(s); service_search_main_pid(s);
service_enter_start_post(s); service_enter_start_post(s);
break; break;
@@ -2751,16 +2745,15 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
break; break;
} }
} else } else
(void) service_search_main_pid(s); service_search_main_pid(s);
service_enter_running(s, SERVICE_SUCCESS); service_enter_running(s, SERVICE_SUCCESS);
break; break;
case SERVICE_RELOAD: case SERVICE_RELOAD:
if (f == SERVICE_SUCCESS) { if (f == SERVICE_SUCCESS)
service_load_pid_file(s, true); if (service_load_pid_file(s, true) < 0)
(void) service_search_main_pid(s); service_search_main_pid(s);
}
s->reload_result = f; s->reload_result = f;
service_enter_running(s, SERVICE_SUCCESS); service_enter_running(s, SERVICE_SUCCESS);

View File

@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
goto error; goto error;
} }
cg_get_root_path(&cgroup); (void) cg_get_root_path(&cgroup);
use_watchdog = !!getenv("WATCHDOG_USEC"); use_watchdog = !!getenv("WATCHDOG_USEC");

View File

@@ -137,7 +137,7 @@ static int curl_glue_socket_callback(CURLM *curl, curl_socket_t s, int action, v
if (sd_event_add_io(g->event, &io, fd, events, curl_glue_on_io, g) < 0) if (sd_event_add_io(g->event, &io, fd, events, curl_glue_on_io, g) < 0)
return -1; return -1;
sd_event_source_set_description(io, "curl-io"); (void) sd_event_source_set_description(io, "curl-io");
r = hashmap_put(g->ios, FD_TO_PTR(s), io); r = hashmap_put(g->ios, FD_TO_PTR(s), io);
if (r < 0) { if (r < 0) {
@@ -204,7 +204,7 @@ static int curl_glue_timer_callback(CURLM *curl, long timeout_ms, void *userdata
if (sd_event_add_time(g->event, &g->timer, clock_boottime_or_monotonic(), usec, 0, curl_glue_on_timer, g) < 0) if (sd_event_add_time(g->event, &g->timer, clock_boottime_or_monotonic(), usec, 0, curl_glue_on_timer, g) < 0)
return -1; return -1;
sd_event_source_set_description(g->timer, "curl-timer"); (void) sd_event_source_set_description(g->timer, "curl-timer");
} }
return 0; return 0;

View File

@@ -58,7 +58,7 @@ static gcry_mpi_t mpi_import(const void *buf, size_t buflen) {
gcry_mpi_t h; gcry_mpi_t h;
unsigned len; unsigned len;
gcry_mpi_scan(&h, GCRYMPI_FMT_USG, buf, buflen, NULL); assert_se(gcry_mpi_scan(&h, GCRYMPI_FMT_USG, buf, buflen, NULL) == 0);
len = (gcry_mpi_get_nbits(h) + 7) / 8; len = (gcry_mpi_get_nbits(h) + 7) / 8;
assert(len <= buflen); assert(len <= buflen);
assert(gcry_mpi_cmp_ui(h, 0) >= 0); assert(gcry_mpi_cmp_ui(h, 0) >= 0);

View File

@@ -579,9 +579,10 @@ static void resolve_free(sd_resolve *resolve) {
(void) send(resolve->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL); (void) send(resolve->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL);
} }
/* Now terminate them and wait until they are gone. */ /* Now terminate them and wait until they are gone.
If we get an error than most likely the thread already exited. */
for (i = 0; i < resolve->n_valid_workers; i++) for (i = 0; i < resolve->n_valid_workers; i++)
pthread_join(resolve->workers[i], NULL); (void) pthread_join(resolve->workers[i], NULL);
/* Close all communication channels */ /* Close all communication channels */
for (i = 0; i < _FD_MAX; i++) for (i = 0; i < _FD_MAX; i++)

View File

@@ -148,8 +148,12 @@ int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union
for (;;) { for (;;) {
if (!address_pool_prefix_is_taken(p, &u, prefixlen)) { if (!address_pool_prefix_is_taken(p, &u, prefixlen)) {
_cleanup_free_ char *s = NULL; _cleanup_free_ char *s = NULL;
int r;
r = in_addr_to_string(p->family, &u, &s);
if (r < 0)
return r;
in_addr_to_string(p->family, &u, &s);
log_debug("Found range %s/%u", strna(s), prefixlen); log_debug("Found range %s/%u", strna(s), prefixlen);
*found = u; *found = u;

View File

@@ -2648,7 +2648,8 @@ static int inner_child(
execvpe(arg_parameters[0], arg_parameters, env_use); execvpe(arg_parameters[0], arg_parameters, env_use);
else { else {
if (!arg_chdir) if (!arg_chdir)
chdir(home ?: "/root"); /* If we cannot change the directory, we'll end up in /, that is expected. */
(void) chdir(home ?: "/root");
execle("/bin/bash", "-bash", NULL, env_use); execle("/bin/bash", "-bash", NULL, env_use);
execle("/bin/sh", "-sh", NULL, env_use); execle("/bin/sh", "-sh", NULL, env_use);

View File

@@ -424,8 +424,9 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
if (added <= 0) { if (added <= 0) {
_cleanup_free_ char *ip = NULL; _cleanup_free_ char *ip = NULL;
in_addr_to_string(q->request_family, &q->request_address, &ip); (void) in_addr_to_string(q->request_family, &q->request_address, &ip);
r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR, "Address '%s' does not have any RR of requested type", strna(ip)); r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR,
"Address '%s' does not have any RR of requested type", strnull(ip));
goto finish; goto finish;
} }

View File

@@ -262,7 +262,7 @@ static void dns_transaction_tentative(DnsTransaction *t, DnsPacket *p) {
if (manager_our_packet(t->scope->manager, p) != 0) if (manager_our_packet(t->scope->manager, p) != 0)
return; return;
in_addr_to_string(p->family, &p->sender, &pretty); (void) in_addr_to_string(p->family, &p->sender, &pretty);
log_debug("Transaction %" PRIu16 " for <%s> on scope %s on %s/%s got tentative packet from %s.", log_debug("Transaction %" PRIu16 " for <%s> on scope %s on %s/%s got tentative packet from %s.",
t->id, t->id,
@@ -270,7 +270,7 @@ static void dns_transaction_tentative(DnsTransaction *t, DnsPacket *p) {
dns_protocol_to_string(t->scope->protocol), dns_protocol_to_string(t->scope->protocol),
t->scope->link ? t->scope->link->name : "*", t->scope->link ? t->scope->link->name : "*",
af_to_name_short(t->scope->family), af_to_name_short(t->scope->family),
pretty); strnull(pretty));
/* RFC 4795, Section 4.1 says that the peer with the /* RFC 4795, Section 4.1 says that the peer with the
* lexicographically smaller IP address loses */ * lexicographically smaller IP address loses */

View File

@@ -40,7 +40,7 @@ static void sig_handler(int signum) {
static void print_device(struct udev_device *device, const char *source, int prop) { static void print_device(struct udev_device *device, const char *source, int prop) {
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n", printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
source, source,
ts.tv_sec, ts.tv_nsec/1000, ts.tv_sec, ts.tv_nsec/1000,

View File

@@ -400,10 +400,11 @@ static void worker_spawn(Manager *manager, struct event *event) {
goto out; goto out;
} }
/* request TERM signal if parent exits */ /* Request TERM signal if parent exits.
prctl(PR_SET_PDEATHSIG, SIGTERM); Ignore error, not much we can do in that case. */
(void) prctl(PR_SET_PDEATHSIG, SIGTERM);
/* reset OOM score, we only protect the main daemon */ /* Reset OOM score, we only protect the main daemon. */
write_string_file("/proc/self/oom_score_adj", "0", 0); write_string_file("/proc/self/oom_score_adj", "0", 0);
for (;;) { for (;;) {