[syslinux:master] hdt: Adding postexec= option

syslinux-bot for Erwan Velu erwanaliasr1 at gmail.com
Thu Dec 22 13:18:12 PST 2011


Commit-ID:  c0c25b4826950162517896c5039c6d62d07115be
Gitweb:     http://www.syslinux.org/commit/c0c25b4826950162517896c5039c6d62d07115be
Author:     Erwan Velu <erwanaliasr1 at gmail.com>
AuthorDate: Sat, 17 Dec 2011 22:27:07 +0100
Committer:  Erwan Velu <erwanaliasr1 at gmail.com>
CommitDate: Sat, 17 Dec 2011 22:27:07 +0100

hdt: Adding postexec= option

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 |   22 ++++++++++++++++++++++
 com32/hdt/hdt-common.h |    1 +
 com32/hdt/hdt.c        |   15 +++++++++++----
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c
index 1857cc0..8e9a9e6 100644
--- a/com32/hdt/hdt-common.c
+++ b/com32/hdt/hdt-common.c
@@ -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");
diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h
index f007e72..8c85260 100644
--- a/com32/hdt/hdt-common.h
+++ b/com32/hdt/hdt-common.h
@@ -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);
diff --git a/com32/hdt/hdt.c b/com32/hdt/hdt.c
index a1e3923..851b046 100644
--- a/com32/hdt/hdt.c
+++ b/com32/hdt/hdt.c
@@ -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;
 }


More information about the Syslinux-commits mailing list