diff options
author | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2009-10-04 15:32:52 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-01-03 00:55:42 +0100 |
commit | f93702e540596baee7acbf5d78dd1e74233f5e75 (patch) | |
tree | bbdc6501b5c9d7afe65c9f811603a9cff96e2c67 | |
parent | 48412d75bc1dfc203b235761a48f4f563a73c2b9 (diff) | |
download | suspend-utils-f93702e540596baee7acbf5d78dd1e74233f5e75.tar.gz |
Fix "program swap-offset is using a deprecated SCSI ioctl"
"program swap-offset is using a deprecated SCSI ioctl"
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=425219>
The debian uswsusp package tries to run swap-offset even if the
swap is a partition and not a file. Calling FIGETBSZ on a scsi disk
device provokes the alarming kernel warning above. (Alarming
because it suggests that FIGETBSZ might somehow be interpreted as a
random SCSI ioctl).
Let's check explicitly whether we've been given a regular file.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
-rw-r--r-- | swap-offset.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/swap-offset.c b/swap-offset.c index b0cccca..79aeef7 100644 --- a/swap-offset.c +++ b/swap-offset.c @@ -47,6 +47,16 @@ int main(int argc, char **argv) perror("open()"); return err; } + if (fstat(fd, &stat)) { + err = errno; + perror("fstat()"); + goto out; + } + if (!S_ISREG(stat.st_mode)) { + fprintf(stderr, "Not a regular file\n"); + err = EINVAL; + goto out; + } /* Check swap signature */ if (lseek(fd, page_size - SWAP_SIG_SIZE, SEEK_SET) < 0) { @@ -71,11 +81,6 @@ int main(int argc, char **argv) goto out; } - if (fstat(fd, &stat)) { - err = errno; - perror("fstat()"); - goto out; - } if (ioctl(fd, FIGETBSZ, &blk_size)) { err = errno; perror("ioctl(FIGETBSZ) failed"); |