From 3bb0f0fbdde37789ee51e718225cbd278e9167f9 Mon Sep 17 00:00:00 2001 From: sin Date: Sat, 15 Feb 2014 18:26:01 +0000 Subject: [PATCH] Check setmntent() for failures --- swapoff.c | 2 ++ swapon.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/swapoff.c b/swapoff.c index 806d1f0..2d2b7ac 100644 --- a/swapoff.c +++ b/swapoff.c @@ -36,6 +36,8 @@ main(int argc, char *argv[]) FILE *fp; fp = setmntent("/etc/fstab", "r"); + if (!fp) + eprintf("setmntent %s:", "/etc/fstab"); while ((me = getmntent(fp)) != NULL) { if (strcmp(me->mnt_type, MNTTYPE_SWAP) == 0) { if (swapoff(me->mnt_fsname) < 0) { diff --git a/swapon.c b/swapon.c index 40e6c9f..6b3d32f 100644 --- a/swapon.c +++ b/swapon.c @@ -43,6 +43,8 @@ main(int argc, char *argv[]) FILE *fp; fp = setmntent("/etc/fstab", "r"); + if (!fp) + eprintf("setmntent %s:", "/etc/fstab"); while ((me = getmntent(fp)) != NULL) { if (strcmp(me->mnt_type, MNTTYPE_SWAP) == 0 && (hasmntopt(me, MNTOPT_NOAUTO) == NULL)) {