Introducing a new wrapper function in iprconfig that invokes an editor
chosen by the user for log viewing.

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

diff --git a/iprconfig.c b/iprconfig.c
index 02e94cad4a31..a162d1b2acd3 100644
--- a/iprconfig.c
+++ b/iprconfig.c
@@ -12065,6 +12065,50 @@ static int invoke_pager(char *filename)
        return WEXITSTATUS(status);
 }
 
+#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
@@ -12142,7 +12186,7 @@ int ibm_storage_log_tail(i_container *i_con)
 
        fclose(logsource_fp);
        close(log_fd);
-       rc = invoke_pager(tmp_log);
+       rc = invoke_editor(tmp_log);
        free(tmp_log);
 
        if ((rc != 0) && (rc != 127)) {
@@ -12298,7 +12342,7 @@ int ibm_storage_log(i_container *i_con)
        }
 
        close(log_fd);
-       rc = invoke_pager(tmp_log);
+       rc = invoke_editor(tmp_log);
        free(tmp_log);
 
        if (num_dir_entries) {
@@ -12375,7 +12419,7 @@ int kernel_log(i_container *i_con)
        }
 
        close(log_fd);
-       rc = invoke_pager(tmp_log);
+       rc = invoke_editor(tmp_log);
        free(tmp_log);
 
        if (num_dir_entries > 0) {
@@ -12457,7 +12501,7 @@ int iprconfig_log(i_container *i_con)
        }
 
        close(log_fd);
-       rc = invoke_pager(tmp_log);
+       rc = invoke_editor(tmp_log);
        free(tmp_log);
 
        if (num_dir_entries) {
@@ -12710,7 +12754,7 @@ int ibm_boot_log(i_container *i_con)
 
        fclose(logsource_fp);
        close(log_fd);
-       rc = invoke_pager(tmp_log);
+       rc = invoke_editor(tmp_log);
        free(tmp_log);
 
        if ((rc != 0) && (rc != 127)) {
-- 
2.4.3


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Iprdd-devel mailing list
Iprdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iprdd-devel

Reply via email to