[PATCH] lscpu: require procfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Davidlohr Bueso <dave@xxxxxxx>

This is a relatively dumb patch, but I actually did see a user trigger it. It simply warns the user about mounting the proc filesystem.
If not found, it aborts the program immediately.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 sys-utils/lscpu.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 66f6126..b063fa7 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -32,6 +32,8 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <bitops.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "cpuset.h"
 #include "nls.h"
@@ -925,6 +927,13 @@ void usage(int rc)
 	exit(rc);
 }
 
+void has_procfs(void)
+{
+	struct stat sb;
+	if (stat(_PATH_PROC_CPUINFO, &sb) < 0)
+		errx(EXIT_FAILURE, _("error: mount procfs and rerun"));       
+}
+
 int main(int argc, char *argv[])
 {
 	struct lscpu_desc _desc, *desc = &_desc;
@@ -938,6 +947,8 @@ int main(int argc, char *argv[])
 		{ NULL,		0, 0, 0 }
 	};
 
+	has_procfs();
+
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux