Skip to content

Commit

Permalink
qemu-nbd: changes towards enabling -Wshadow=local
Browse files Browse the repository at this point in the history
Address all compiler complaints from -Wshadow in qemu-nbd.  Several
instances of 'int ret' became shadows when commit 4fbec26 added 'ret'
at a higher scope in main.  More interesting was the 'void *ret'
capturing the result of a pthread; where we were conceptually doing
'(void*)(intptr_t)EXIT_FAILURE != NULL' which just feels wrong (even
though it happens to compile correctly), so it was worth a better
cleanup.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-ID: <20230922205019.2755352-2-eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
ebblake authored and Markus Armbruster committed Sep 29, 2023
1 parent 0d57919 commit e161785
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions qemu-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ int main(int argc, char **argv)
g_autoptr(GError) err = NULL;
int stderr_fd[2];
pid_t pid;
int ret;

if (!g_unix_open_pipe(stderr_fd, FD_CLOEXEC, &err)) {
error_report("Error setting up communication pipe: %s",
Expand Down Expand Up @@ -1172,7 +1171,6 @@ int main(int argc, char **argv)

if (opts.device) {
#if HAVE_NBD_DEVICE
int ret;
ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
if (ret != 0) {
error_report("Failed to create client thread: %s", strerror(ret));
Expand Down Expand Up @@ -1219,9 +1217,10 @@ int main(int argc, char **argv)
qemu_opts_del(sn_opts);

if (opts.device) {
void *ret;
pthread_join(client_thread, &ret);
exit(ret != NULL);
void *result;
pthread_join(client_thread, &result);
ret = (intptr_t)result;
exit(ret);
} else {
exit(EXIT_SUCCESS);
}
Expand Down

0 comments on commit e161785

Please sign in to comment.