[Libguestfs] [PATCH 26/46] daemon: If /proc/modules doesn't exist, linuxmodules optgroup is disabled.

Richard W.M. Jones rjones at redhat.com
Sat Aug 24 12:37:02 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

It likely means the kernel was compiled without modules support.

(cherry picked from commit 8ad634877cf315288497a8580fb4afc7658deae9)
(cherry picked from commit 6503aa1681bb44d2beffa7cfd4f0c4c74ed6d820)
---
 daemon/modprobe.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/daemon/modprobe.c b/daemon/modprobe.c
index 24d2a5b..0b7896a 100644
--- a/daemon/modprobe.c
+++ b/daemon/modprobe.c
@@ -20,6 +20,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
 
 #include "daemon.h"
 #include "actions.h"
@@ -30,6 +32,13 @@ GUESTFSD_EXT_CMD(str_modprobe, modprobe);
 int
 optgroup_linuxmodules_available (void)
 {
+  /* If /proc/modules doesn't exist, then the appliance kernel
+   * probably has modules support compiled out.  This means modprobe
+   * is not supported.
+   */
+  if (access ("/proc/modules", R_OK) == -1 && errno == ENOENT)
+    return 0;
+
   return prog_exists (str_modprobe);
 }
 
@@ -37,7 +46,9 @@ int
 do_modprobe (const char *module)
 {
   CLEANUP_FREE char *err = NULL;
-  int r = command (NULL, &err, str_modprobe, module, NULL);
+  int r;
+
+  r = command (NULL, &err, str_modprobe, module, NULL);
 
   if (r == -1) {
     reply_with_error ("%s", err);
-- 
1.8.3.1




More information about the Libguestfs mailing list