Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverity: minor fixes dealing with return codes #60

Merged
merged 3 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions src/resource/ubridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,10 @@ static int _export_kv_store(sid_resource_t *cmd_res)
export_fd = memfd_create("kv_store_export", MFD_CLOEXEC);

/* Reserve space to write the overall data size. */
lseek(export_fd, sizeof(bytes_written), SEEK_SET);
if (lseek(export_fd, sizeof(bytes_written), SEEK_SET) < 0) {
log_error_errno(ID(cmd_res), errno, "lseek failed");
goto out;
};

// FIXME: maybe buffer first so there's only single write
while ((value = kv_store_iter_next(iter, &size, &flags))) {
Expand Down Expand Up @@ -3247,53 +3250,75 @@ static int _export_kv_store(sid_resource_t *cmd_res)
/* FIXME: Try to reduce the "write" calls. */
if ((r_wr = write(export_fd, &flags, sizeof(flags))) == sizeof(flags))
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}


if ((r_wr = write(export_fd, &key_size, sizeof(key_size))) == sizeof(key_size))
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}

if ((r_wr = write(export_fd, &size, sizeof(size))) == sizeof(size))
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}

if ((r_wr = write(export_fd, key, strlen(key) + 1)) == strlen(key) + 1)
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}

if (vector) {
for (i = 0, size = 0; i < iov_size; i++) {
size += iov[i].iov_len;

if ((r_wr = write(export_fd, &iov[i].iov_len, sizeof(iov->iov_len))) == sizeof(iov->iov_len))
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}

if ((r_wr = write(export_fd, iov[i].iov_base, iov[i].iov_len)) == iov[i].iov_len)
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}
}
} else {
if ((r_wr = write(export_fd, kv_value, size)) == size)
bytes_written += r_wr;
else
else {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}
}


}

lseek(export_fd, 0, SEEK_SET);
if (write(export_fd, &bytes_written, sizeof(bytes_written)) < 0)
if (lseek(export_fd, 0, SEEK_SET) < 0) {
log_error_errno(ID(cmd_res), errno, "lseek failed");
goto out;
lseek(export_fd, 0, SEEK_SET);
}
if (write(export_fd, &bytes_written, sizeof(bytes_written)) < 0) {
log_error_errno(ID(cmd_res), errno, "write failed");
goto out;
}
if (lseek(export_fd, 0, SEEK_SET) < 0) {
log_error_errno(ID(cmd_res), errno, "lseek failed");
goto out;
}

data_spec.data = NULL;
data_spec.data_size = 0;
Expand Down
7 changes: 5 additions & 2 deletions src/resource/worker-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ static int _setup_channel(sid_resource_t *owner, const char *alt_id, bool is_wor
}

if (chan->spec->wire.ext.used && chan->spec->wire.ext.pipe.fd_redir >= 0) {
dup2(chan->fd, chan->spec->wire.ext.pipe.fd_redir);
if (dup2(chan->fd, chan->spec->wire.ext.pipe.fd_redir) < 0) {
log_error_errno(id, errno, "Failed to redirect FD %d through channel %s : WORKER_WIRE_SOCKET",
chan->spec->wire.ext.pipe.fd_redir, chan->spec->id);
}
close(chan->fd);
}
break;
Expand Down Expand Up @@ -1153,7 +1156,7 @@ static int _set_channel_specs(struct worker_control *worker_control, const struc
return 0;
fail:
worker_control->channel_specs = mem_freen(worker_control->channel_specs);
return -1;
return r;
}

static int _init_worker_control(sid_resource_t *worker_control_res, const void *kickstart_data, void **data)
Expand Down