Page MenuHomeFreeBSD

D33846.diff
No OneTemporary

D33846.diff

Index: sbin/swapon/swapon.c
===================================================================
--- sbin/swapon/swapon.c
+++ sbin/swapon/swapon.c
@@ -756,6 +756,24 @@
fd = open(name, O_WRONLY);
if (fd < 0)
errx(1, "Cannot open %s", name);
+
+ /*
+ * Hack: see if the file is already in use as a swap device. If so,
+ * don't attempt to erase its blocks since we may end up clearing
+ * swapped-out data. Currently there is no surefire way to determine
+ * whether a file is a swap device other than by attempting to enable it
+ * as such, and observing EBUSY.
+ */
+ error = swapon(name);
+ if (error != 0) {
+ error = errno;
+ (void)close(fd);
+ errno = error;
+ return (-1);
+ }
+ if (swapoff(name, SWAPOFF_FORCE) != 0)
+ err(1, "swapoff(%s)", name);
+
/* Find the device size. */
if (fstat(fd, &sb) < 0)
errx(1, "Cannot stat %s", name);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 6:38 AM (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14880456
Default Alt Text
D33846.diff (867 B)

Event Timeline