From: Ari Sundholm Date: Wed, 20 Dec 2017 17:00:11 +0000 (+0200) Subject: fsstress: getcwd() return value fixes X-Git-Tag: v2022.05.01~1727 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=db71085194be8e96d4d94156f4c88f47a747e395;p=users%2Fhch%2Fxfstests-dev.git fsstress: getcwd() return value fixes Add a check for the return value of getcwd(). Fix another check which mistakenly checks if the return value is less than zero instead of checking whether the return value is NULL. Signed-off-by: Ari Sundholm Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 13d5dd54b..028c232c1 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -495,7 +495,7 @@ int main(int argc, char **argv) (void)mkdir(dirname, 0777); if (logname && logname[0] != '/') { - if (getcwd(rpath, sizeof(rpath)) < 0){ + if (!getcwd(rpath, sizeof(rpath))){ perror("getcwd failed"); exit(1); } @@ -970,6 +970,10 @@ doproc(void) } top_ino = statbuf.st_ino; homedir = getcwd(NULL, 0); + if (!homedir) { + perror("getcwd failed"); + _exit(1); + } seed += procid; srandom(seed); if (namerand)