hdt: Adding postexec= option
authorErwan Velu <erwanaliasr1@gmail.com>
Sat, 17 Dec 2011 21:27:07 +0000 (22:27 +0100)
committerErwan Velu <erwanaliasr1@gmail.com>
Sat, 17 Dec 2011 21:27:07 +0000 (22:27 +0100)
When HDT is exiting, you might need executing something else.
This could be used in the following scenario :

You start HDT, do an automatic command like 'dump; exit', but then after
you might need to launch something else from syslinux.

The postexec option will allow you to define what label you'd love
running one HDT got terminated.

Syntaxt is like the following:

postexec='menu_label_to_run_once_hdt_got_exited'

Note the quotes (') after the equal sign (=)

This could looks like :
APPEND auto='dump; exit' postexec='memtest'

com32/hdt/hdt-common.c
com32/hdt/hdt-common.h
com32/hdt/hdt.c

index 1857cc0..8e9a9e6 100644 (file)
@@ -115,6 +115,27 @@ void detect_parameters(const int argc, const char *argv[],
        } else if (!strncmp(argv[i], "tftp_ip=", 8)) {
            strlcpy(hardware->tftp_ip, argv[i] + 8,
                    sizeof(hardware->tftp_ip));
+       } else if (!strncmp(argv[i], "postexec=", 9)) {
+           /* The postexec= parameter is separated in several argv[]
+            * as it can contains spaces.
+            * We use the AUTO_DELIMITER char to define the limits
+            * of this parameter.
+            * i.e postexec='linux memtest.bin'
+            */
+
+           char *argument = (char*)argv[i]+10;
+           /* Extracting the first parameter */
+           strcpy(hardware->postexec, argument);
+
+           /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
+           while ((strchr(argument, AUTO_DELIMITER) == NULL) && (i+1<argc)) {
+               i++;
+               argument = (char *)argv[i];
+               strcat(hardware->postexec, " ");
+               strcat(hardware->postexec, argument);
+           } 
+       
+            hardware->postexec[strlen(hardware->postexec) - 1] = 0;
        } else if (!strncmp(argv[i], "auto=", 5)) {
            /* The auto= parameter is separated in several argv[]
             * as it can contains spaces.
@@ -210,6 +231,7 @@ void init_hardware(struct s_hardware *hardware)
     memset(hardware->dump_filename, 0, sizeof hardware->dump_filename);
     memset(hardware->vesa_background, 0, sizeof hardware->vesa_background);
     memset(hardware->tftp_ip, 0, sizeof hardware->tftp_ip);
+    memset(hardware->postexec, 0, sizeof hardware->postexec);
     strcat(hardware->dump_path, "hdt");
     strcat(hardware->dump_filename, "%{m}+%{p}+%{v}");
     strcat(hardware->pciids_path, "pci.ids");
index f007e72..8c85260 100644 (file)
@@ -219,6 +219,7 @@ struct s_hardware {
     char memtest_label[255];
     char auto_label[AUTO_COMMAND_SIZE];
     char vesa_background[255];
+    char postexec[255];
 };
 
 void reset_more_printf(void);
index a1e3923..851b046 100644 (file)
@@ -74,14 +74,21 @@ int main(const int argc, const char *argv[])
 
     printf("%s\n", version_string);
 
+    int return_code = 0;
+
     if (!menumode || automode)
        start_cli_mode(&hardware);
     else {
-       int return_code = start_menu_mode(&hardware, version_string);
+       return_code = start_menu_mode(&hardware, version_string);
        if (return_code == HDT_RETURN_TO_CLI)
            start_cli_mode(&hardware);
-       else
-           return return_code;
     }
-    return 0;
+
+    /* Do we got request to do something at exit time ? */
+    if (strlen(hardware.postexec)>0) {
+           printf("Executing postexec instructions : %s\n",hardware.postexec);
+           runsyslinuxcmd(hardware.postexec);
+    }
+
+    return return_code;
 }