Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir
the function of these files exceeds what can be sanely handled in shell in posix-comaptible way. Also writing it in C extends the functionality to non-UNIX-like OS and minimal environments.
This commit is contained in:
parent
9ef81064a3
commit
cd46aa6cef
52 changed files with 5811 additions and 2101 deletions
|
@ -38,6 +38,23 @@ grub_util_exec (const char *const *argv)
|
|||
{
|
||||
pid_t pid;
|
||||
int status = -1;
|
||||
char *str, *pstr;
|
||||
const char *const *ptr;
|
||||
grub_size_t strl = 0;
|
||||
for (ptr = argv; *ptr; ptr++)
|
||||
strl += grub_strlen (*ptr) + 1;
|
||||
pstr = str = xmalloc (strl);
|
||||
for (ptr = argv; *ptr; ptr++)
|
||||
{
|
||||
pstr = grub_stpcpy (pstr, *ptr);
|
||||
*pstr++ = ' ';
|
||||
}
|
||||
if (pstr > str)
|
||||
pstr--;
|
||||
*pstr = '\0';
|
||||
|
||||
grub_util_info ("executing %s", str);
|
||||
grub_free (str);
|
||||
|
||||
pid = fork ();
|
||||
if (pid < 0)
|
||||
|
@ -71,6 +88,29 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
|
|||
{
|
||||
pid_t mdadm_pid;
|
||||
int status = -1;
|
||||
char *str, *pstr;
|
||||
const char *const *ptr;
|
||||
grub_size_t strl = 0;
|
||||
for (ptr = argv; *ptr; ptr++)
|
||||
strl += grub_strlen (*ptr) + 1;
|
||||
strl += grub_strlen (stdin_file) + 2;
|
||||
strl += grub_strlen (stdout_file) + 2;
|
||||
|
||||
pstr = str = xmalloc (strl);
|
||||
for (ptr = argv; *ptr; ptr++)
|
||||
{
|
||||
pstr = grub_stpcpy (pstr, *ptr);
|
||||
*pstr++ = ' ';
|
||||
}
|
||||
*pstr++ = '<';
|
||||
pstr = grub_stpcpy (pstr, stdin_file);
|
||||
*pstr++ = ' ';
|
||||
*pstr++ = '>';
|
||||
pstr = grub_stpcpy (pstr, stdout_file);
|
||||
*pstr = '\0';
|
||||
|
||||
grub_util_info ("executing %s", str);
|
||||
grub_free (str);
|
||||
|
||||
mdadm_pid = fork ();
|
||||
if (mdadm_pid < 0)
|
||||
|
@ -87,6 +127,8 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
|
|||
#endif
|
||||
|
||||
in = open (stdin_file, O_RDONLY);
|
||||
if (in < 0)
|
||||
exit (127);
|
||||
dup2 (in, STDIN_FILENO);
|
||||
close (in);
|
||||
|
||||
|
@ -94,6 +136,9 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
|
|||
dup2 (out, STDOUT_FILENO);
|
||||
close (out);
|
||||
|
||||
if (out < 0)
|
||||
exit (127);
|
||||
|
||||
/* Ensure child is not localised. */
|
||||
setenv ("LC_ALL", "C", 1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue