Skip to content

Commit

Permalink
build: fixing unused-result warning
Browse files Browse the repository at this point in the history
The results of calls to methods write() and read() are now checked in the debug build, which will help diagnose potential problems.

Signed-off-by: Aleksandr Golubev <[email protected]>
  • Loading branch information
Aleksandr Golubev committed Jun 7, 2024
1 parent 7f4f9f1 commit b4abebc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions tests/vhost_user_blk_test_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ static int resize(struct disk *d, uint64_t new_size)
static bool monitor_serve_fd(FILE *f_in, FILE *f_out,
struct disks_context *ctx)
{
const char *help = "Commands:\n"
" help - print this message\n"
" stop - stop the server and quit\n"
" stat - print statistics\n"
" resize <new_size> - resize the disk\n";
const char *const help = "Commands:\n"

This comment has been minimized.

Copy link
@den-plotnikov

den-plotnikov Jun 9, 2024

Contributor

I'd rather not mixing fixes: read/write result code checks with variables definition changing. Although the later seems to be legit it's better make a separate patch with a commit message addressing the problem.

" help - print this message\n"
" stop - stop the server and quit\n"
" stat - print statistics\n"
" resize <new_size> - resize the disk\n";

bool interactive = (f_in == stdin && f_out == stdout);

Expand Down Expand Up @@ -1035,8 +1035,9 @@ static void monitor_serve_unix_socket(const char *path,

static void interactive_sigint(int sig)
{
const char *msg = "\nUse 'stop' command or Ctrl+D to exit\n";
write(2, msg, strlen(msg));
const char *const msg = "\nUse 'stop' command or Ctrl+D to exit\n";
ssize_t res = write(2, msg, strlen(msg));
VHD_ASSERT(res == strlen(msg));
}

static void monitor_serve_stdio(struct disks_context *ctx)
Expand Down
3 changes: 2 additions & 1 deletion vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,8 @@ static int timer_read(void *opaque)
uint64_t count;

/* Read the count to rearm the periodic timer, but ignore the result */
(void)read(vdev->timerfd, &count, sizeof(count));
ssize_t res = read(vdev->timerfd, &count, sizeof(count));
VHD_ASSERT(res == sizeof(count));

This comment has been minimized.

Copy link
@den-plotnikov

den-plotnikov Jun 9, 2024

Contributor

May be it has more sense to check for res == -1 and report errno if we really want to care about errors on reading from this timer?
In the other hand the timer is initialized as NONBLOCK which means that the read can fail with errno=EAGAIN if no timer expirations have occurred. So, in order to catch a real error we have to check errno for specific codes.

Anyway, the comment above (+1942) needs reformulation due to the current changes: now we do check the result.


elapsed_time(vdev, &elapsed);

Expand Down

0 comments on commit b4abebc

Please sign in to comment.