compel/test: Fix warn_unused_result

gcc -O2 -g -Wall -Werror -I ../../../compel/include/uapi -o spy spy.c ../../../compel/libcompel.a
spy.c: In function ‘check_pipe_ends’:
spy.c:107:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
  107 |  write(wfd, "1", 2);
      |  ^~~~~~~~~~~~~~~~~~
spy.c:108:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
  108 |  read(rfd, aux, sizeof(aux));
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Radostin Stoyanov 2021-01-12 08:49:02 +00:00 committed by Andrei Vagin
parent 8aba7ae9fa
commit 5364ca3da4
3 changed files with 21 additions and 6 deletions

View file

@ -104,8 +104,14 @@ static int check_pipe_ends(int wfd, int rfd)
}
printf("Check pipe ends are connected\n");
write(wfd, "1", 2);
read(rfd, aux, sizeof(aux));
if (write(wfd, "1", 2) != 2) {
fprintf(stderr, "write to pipe failed\n");
return -1;
}
if (read(rfd, aux, sizeof(aux)) != sizeof(aux)) {
fprintf(stderr, "read from pipe failed\n");
return -1;
}
if (aux[0] != '1' || aux[1] != '\0') {
fprintf(stderr, "Pipe connectivity lost\n");
return 0;

View file

@ -64,7 +64,9 @@ static inline int chk(int fd, int val)
{
int v = 0;
read(fd, &v, sizeof(v));
if (read(fd, &v, sizeof(v)) != sizeof(v)) {
fprintf(stderr, "read failed\n");
}
printf("%d, want %d\n", v, val);
return v == val;
}
@ -97,7 +99,10 @@ int main(int argc, char **argv)
* Kick the victim once
*/
i = 0;
write(p_in[1], &i, sizeof(i));
if (write(p_in[1], &i, sizeof(i)) != sizeof(i)) {
fprintf(stderr, "write to pipe failed\n");
return -1;
}
printf("Checking the victim session to be %d\n", sid);
pass = chk(p_out[0], sid);
@ -115,7 +120,10 @@ int main(int argc, char **argv)
/*
* Kick the victim again so it tells new session
*/
write(p_in[1], &i, sizeof(i));
if (write(p_in[1], &i, sizeof(i)) != sizeof(i)) {
fprintf(stderr, "write to pipe failed\n");
return -1;
}
/*
* Stop the victim and check the intrusion went well

View file

@ -9,7 +9,8 @@ int main(int argc, char **argv)
break;
i = getsid(0);
write(1, &i, sizeof(i));
if (write(1, &i, sizeof(i)) != sizeof(i))
break;
}
return 0;