- char *cmd;
- int r;
-
- /* Copy kernel modules into tmpdir. */
- size_t n = strlen (modpath) + strlen (dir) + 64;
- size_t i;
- for (i = 0; kmods[i] != NULL; ++i)
- n += strlen (kmods[i]) + 16;
- cmd = malloc (n);
- /* "cd /" here is for virt-v2v. It's cwd might not be accessible by
- * the current user (because it sometimes sets its own uid) and the
- * "find" command works by changing directory then changing back to
- * the cwd. This results in a warning:
- *
- * find: failed to restore initial working directory: Permission denied
- *
- * Note this only works because "modpath" and temporary "dir" are
- * currently guaranteed to be absolute paths, hence assertion.
- */
- assert (modpath[0] == '/');
- sprintf (cmd, "cd / ; find '%s' ", modpath);
- for (i = 0; kmods[i] != NULL; ++i) {
- if (i > 0) strcat (cmd, "-o ");
- strcat (cmd, "-name '");
- strcat (cmd, kmods[i]);
- strcat (cmd, "' ");
- }
- strcat (cmd, "| xargs cp -t ");
- strcat (cmd, dir);
- if (verbose >= 2) fprintf (stderr, "%s\n", cmd);
- r = system (cmd);
- if (r == -1 || WEXITSTATUS (r) != 0)
- error (EXIT_FAILURE, 0, "ext2_make_initrd: copy kmods failed");
- free (cmd);
-
- /* The above command effectively gives us the final list of modules.
- * Calculate dependencies from modpath/modules.dep and write that
- * into the output.
- */