sfdisk: save errno before calling perror

errno is saved into a local variable to avoid it getting trampled
by perror before it is checked to determine the return value.

This issue seems quite rare, but I have seen it when running sfdisk
via gksudo and using the --quiet command-line option.  From what I
can tell, this combination triggers loading of translations in perror,
which (at least on my machine) ends up changing the value of errno.

Signed-off-by: Forest Bond <forest@alittletooquiet.net>
This commit is contained in:
Forest Bond 2010-10-04 21:01:30 -04:00 committed by Karel Zak
parent 6cebde5c96
commit 628e30197e
1 changed files with 4 additions and 1 deletions

View File

@ -784,10 +784,13 @@ reread_ioctl(int fd) {
errno = ENOSYS;
#endif
{
/* perror might change errno */
int err = errno;
perror("BLKRRPART");
/* 2.6.8 returns EIO for a zero table */
if (errno == EBUSY)
if (err == EBUSY)
return -1;
}
return 0;