+static char *
+get_modpath (const char *kernel_name)
+{
+ /* Ignore "vmlinuz-" at the beginning of the kernel name. */
+ const char *version = &kernel_name[8];
+
+ /* /lib/modules/<version> */
+ char *modpath = xasprintf (MODULESDIR "/%s", version);
+ if (!modpath) {
+ perror ("xasprintf");
+ exit (EXIT_FAILURE);
+ }
+
+ return modpath;
+}
+
+/* kernel_name is "vmlinuz-*". Check if there is a corresponding
+ * module path in /lib/modules.
+ */
+static int
+has_modpath (const char *kernel_name)
+{
+ char *modpath = get_modpath (kernel_name);
+
+ if (verbose)
+ fprintf (stderr, "checking modpath %s is a directory\n", modpath);
+
+ int r = isdir (modpath);
+
+ if (r) {
+ if (verbose)
+ fprintf (stderr, "picked %s because modpath %s exists\n",
+ kernel_name, modpath);
+ free (modpath);
+ return 1;
+ }
+ else {
+ free (modpath);
+ return 0;
+ }
+}
+