Skip to content

Commit 589aad1

Browse files
committed
stress-chroot: fix failure return variable ret defaults
The error exit path via a break resets ret to EXIT_SUCCESS which is incorrect. Set ret to EXIT_SUCCESS at start and allow it to be set appropriately on exit paths. Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent b4ad963 commit 589aad1

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

stress-chroot.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static int stress_chroot(stress_args_t *args)
437437
{
438438
size_t i = 0;
439439
int fd;
440-
int ret = EXIT_FAILURE;
440+
int ret = EXIT_SUCCESS;
441441
double rate;
442442
chroot_shared_data_t *data;
443443

@@ -462,11 +462,13 @@ static int stress_chroot(stress_args_t *args)
462462
if (mkdir(temppath, S_IRWXU) < 0) {
463463
pr_fail("%s: mkdir '%s' failed, errno=%d (%s)\n",
464464
args->name, temppath, errno, strerror(errno));
465+
ret = EXIT_FAILURE;
465466
goto tidy_ret;
466467
}
467468
if ((fd = creat(filename, S_IRUSR | S_IWUSR)) < 0) {
468469
pr_fail("%s: creat '%s' failed, errno=%d (%s)\n",
469470
args->name, filename, errno, strerror(errno));
471+
ret = EXIT_FAILURE;
470472
goto tidy_dir;
471473
}
472474
(void)close(fd);
@@ -481,10 +483,8 @@ static int stress_chroot(stress_args_t *args)
481483

482484
pid = stress_retry_fork(args, 0);
483485
if (pid < 0) {
484-
if (UNLIKELY(!stress_continue(args))) {
485-
ret = EXIT_SUCCESS;
486+
if (UNLIKELY(!stress_continue(args)))
486487
break;
487-
}
488488
pr_fail("%s: fork failed, errno=%d (%s)\n",
489489
args->name, errno, strerror(errno));
490490
ret = EXIT_FAILURE;
@@ -527,8 +527,6 @@ static int stress_chroot(stress_args_t *args)
527527
rate = (data->metrics.duration > 0.0) ? data->metrics.count / data->metrics.duration : 0.0;
528528
stress_metrics_set(args, "chroot calls per sec", rate, STRESS_METRIC_HARMONIC_MEAN);
529529

530-
ret = EXIT_SUCCESS;
531-
532530
if (data->cwd_fd != -1)
533531
(void)close(data->cwd_fd);
534532
tidy_all:

0 commit comments

Comments
 (0)