Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=frugalwareutils.git;a=commitdiff;h=17ebe73052e29a776505e2ed483eddaed1cdc5cc
commit 17ebe73052e29a776505e2ed483eddaed1cdc5cc Author: James Buren <r...@frugalware.org> Date: Fri Feb 24 01:41:18 2012 -0600 convert shared code to execute_command diff --git a/libfwgrubconfig/new.c b/libfwgrubconfig/new.c index 793a4fd..928b3eb 100644 --- a/libfwgrubconfig/new.c +++ b/libfwgrubconfig/new.c @@ -89,6 +89,32 @@ char *guess_mbr_device(void) return root; } +static +int execute_command(const char *cmd) +{ + pid_t pid; + int status; + + /* Let's do the splits! :D */ + pid = fork(); + + if(!pid) + { + /* Execute the command in the child process. */ + execl("/bin/sh","/bin/sh","-c",cmd,(void *) 0); + + _exit(EXIT_FAILURE); + } + else if(pid == -1) + return 1; + + /* Did the process exit normally and return a zero exit code? */ + if(waitpid(pid,&status,0) == -1 || !WIFEXITED(status) || WEXITSTATUS(status)) + return 1; + + return 0; +} + /** Installs grub to a given target * @param mode FWGRUB_INSTALL_MBR, FWGRUB_INSTALL_EFI * @return 0 on succcess, 1 on error @@ -96,9 +122,7 @@ char *guess_mbr_device(void) int fwgrub_install(enum fwgrub_install_mode mode) { - char cmd[4096], *mbr; - pid_t pid; - int status; + char cmd[_POSIX_ARG_MAX], *mbr; /* First, define the common parts of the install command. */ strcpy(cmd,"grub-install --recheck --no-floppy --boot-directory=/boot "); @@ -123,24 +147,7 @@ int fwgrub_install(enum fwgrub_install_mode mode) /* Setup logging. */ strcat(cmd," > " FWGRUB_LOGDEV " 2>&1"); - /* Let's do the splits! :D */ - pid = fork(); - - if(!pid) - { - /* Execute the command in the child process. */ - execl("/bin/sh","/bin/sh","-c",cmd,(void *) 0); - - _exit(EXIT_FAILURE); - } - else if(pid == -1) - return 1; - - /* Did the process exit normally and return a zero exit code? */ - if(waitpid(pid,&status,0) == -1 || !WIFEXITED(status) || WEXITSTATUS(status)) - return 1; - - return 0; + return execute_command(cmd); } /** Creates a grub.cfg @@ -148,25 +155,5 @@ int fwgrub_install(enum fwgrub_install_mode mode) */ int fwgrub_create_menu(void) { - pid_t pid; - int status; - - /* Let's do the splits! :D */ - pid = fork(); - - if(!pid) - { - /* Execute the command in the child process. */ - execl("/bin/sh","/bin/sh","-c","grub-mkconfig -o /boot/grub/grub.cfg > " FWGRUB_LOGDEV " 2>&1", (void *) 0); - - _exit(EXIT_FAILURE); - } - else if(pid == -1) - return 1; - - /* Did the process exit normally and return a zero exit code? */ - if(waitpid(pid,&status,0) == -1 || !WIFEXITED(status) || WEXITSTATUS(status)) - return 1; - - return 0; + return execute_command("grub-mkconfig -o /boot/grub/grub.cfg > " FWGRUB_LOGDEV " 2>&1"); } _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git