Introducing a new wrapper function in iprconfig that invokes an editor chosen by
the user for log viewing. The default editor is now set to a secure invocation
of the "less" pager.

Signed-off-by: Heitor Ricardo Alves de Siqueira <hal...@linux.vnet.ibm.com>
---
 iprconfig.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/iprconfig.c b/iprconfig.c
index c71a946f03d0..f26e662146f0 100644
--- a/iprconfig.c
+++ b/iprconfig.c
@@ -94,8 +94,7 @@ static int use_curses;
 #define for_each_raid_cmd(cmd) for (cmd = raid_cmd_head; cmd; cmd = cmd->next)
 
 #define DEFAULT_LOG_DIR "/var/log"
-#define DEFAULT_EDITOR "vi -R"
-#define FAILSAFE_EDITOR "vi -R -"
+#define DEFAULT_EDITOR "/usr/bin/less"
 
 #define IS_CANCEL_KEY(c) ((c == KEY_F(12)) || (c == 'q') || (c == 'Q'))
 #define CANCEL_KEY_LABEL "q=Cancel   "
@@ -11910,6 +11909,50 @@ int log_menu(i_container *i_con)
        return rc;
 }
 
+#define EDITOR_MAX_ARGS 32
+static int invoke_editor(char* filename)
+{
+       int i;
+       int rc, pid, status;
+
+       /* if editor not set, use secure pager */
+       if (strcmp(editor, DEFAULT_EDITOR) == 0) {
+               rc = invoke_pager(filename);
+               return rc;
+       }
+
+       pid = fork();
+       if (pid == 0) {
+               char *tok;
+               char *argv[EDITOR_MAX_ARGS];
+               char cmnd[MAX_CMD_LENGTH];
+
+               /* copy editor name to argv[0] */
+               strncpy(cmnd, editor, sizeof(cmnd) - 1);
+               tok = strtok(cmnd, " ");
+               argv[0] = malloc(strlen(tok));
+               strcpy(argv[0], tok);
+
+               /* handle editor arguments, if any */
+               for (i = 1; i < EDITOR_MAX_ARGS - 2; ++i) {
+                       tok = strtok(NULL, " ");
+                       if (tok == NULL)
+                               break;
+                       argv[i] = malloc(strlen(tok));
+                       strcpy(argv[i], tok);
+               }
+               argv[i] = filename;
+               argv[i+1] = NULL;
+
+               execvp(argv[0], argv);
+               _exit(errno);
+       } else {
+               waitpid(pid, &status, 0);
+       }
+
+       return WEXITSTATUS(status);
+}
+
 /**
  * ibm_storage_log_tail -
  * @i_con:             i_container struct
@@ -11971,7 +12014,7 @@ int ibm_storage_log_tail(i_container *i_con)
        }
 
        close(log_fd);
-       rc = invoke_pager(logfile);
+       rc = invoke_editor(logfile);
 
        if ((rc != 0) && (rc != 127)) {
                /* "Editor returned %d. Try setting the default editor" */
@@ -12149,7 +12192,7 @@ int ibm_storage_log(i_container *i_con)
                waitpid(pid, &status, 0);
        }
 
-       rc = invoke_pager(logfile);
+       rc = invoke_editor(logfile);
 
        if ((rc != 0) && (rc != 127)) {
                /* "Editor returned %d. Try setting the default editor" */
@@ -12206,7 +12249,7 @@ int kernel_log(i_container *i_con)
                waitpid(pid, &status, 0);
        }
 
-       rc = invoke_pager(logfile);
+       rc = invoke_editor(logfile);
 
        if ((rc != 0) && (rc != 127))   {
                /* "Editor returned %d. Try setting the default editor" */
@@ -12276,7 +12319,7 @@ int iprconfig_log(i_container *i_con)
                waitpid(pid, &status, 0);
        }
 
-       rc = invoke_pager(logfile);
+       rc = invoke_editor(logfile);
 
        if ((rc != 0) && (rc != 127))   {
                /* "Editor returned %d. Try setting the default editor" */
@@ -12523,7 +12566,7 @@ int ibm_boot_log(i_container *i_con)
        }
 
        close(log_fd);
-       rc = invoke_pager(logfile);
+       rc = invoke_editor(logfile);
 
        if ((rc != 0) && (rc != 127)) {
                s_status.num = rc;
-- 
2.4.3


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Iprdd-devel mailing list
Iprdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iprdd-devel

Reply via email to