This commit rewrites some functions in iprconfig that are used to
display log information to the user. We now use standard C code instead
of system() calls and other OS utilities like grep. To view the
requested log info, the less pager is invoked with the environment
variable LESSSECURE set to 1 to prevent arbitrary command execution.

This commit also introduces a zlib depency to iprutils. This is needed
so that we can seamlessly work with compressed and uncompressed log files.

Changes since v1:
- moved invoke-pager() to iprconfig.c
- DEFAULT_EDITOR doesn't use an absolute path
- renamed some variables to make code more intelligible
- added a new entry to screen_status[] in iprconfig.h
- substituted return values with semantic literals from iprconfig.h
- added missing free() because of tmp_log
- fixed static build

Signed-off-by: Heitor Ricardo Alves de Siqueira <hal...@linux.vnet.ibm.com>
---
 configure.ac       |   3 +-
 iprconfig.c        | 469 +++++++++++++++++++++++++++++++----------------------
 iprconfig.h        |   2 +
 iprlib.h           |   1 +
 spec/iprutils.spec |   6 +-
 5 files changed, 279 insertions(+), 202 deletions(-)

diff --git a/configure.ac b/configure.ac
index ee69bee73267..6fdbf558cae2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,6 +132,7 @@ AC_CHECK_LIB([form], [free_form], [], [AC_ERROR("libform 
not found.")])
 AC_CHECK_LIB([m], [matherr], [], [AC_ERROR("libm not found.")])
 AC_CHECK_LIB([menu], [new_menu], [], [AC_ERROR("libmenu not found.")])
 AC_CHECK_LIB([panel], [show_panel], [], [AC_ERROR("libpanel not found.")])
+AC_CHECK_LIB([z], [zlibVersion], [], [AC_ERROR("zlib not found.")])
 IPRCONFIG_LIBS="$LIBS"
 AC_SUBST([IPRCONFIG_LIBS])
 LIBS="$save_LIBS"
@@ -140,7 +141,7 @@ LIBS="$save_LIBS"
 AC_CHECK_HEADERS([fcntl.h libintl.h locale.h netinet/in.h nl_types.h \
                 paths.h stddef.h stdint.h stdlib.h string.h sys/file.h \
                 sys/ioctl.h sys/mount.h sys/socket.h syslog.h \
-                unistd.h ncurses.h form.h menu.h], [],
+                unistd.h ncurses.h form.h menu.h zlib.h], [],
                 [AC_ERROR(["Missing headers."])])
 
 # Checks for typedefs, structures, and compiler characteristics.
diff --git a/iprconfig.c b/iprconfig.c
index 3189af01a125..02e94cad4a31 100644
--- a/iprconfig.c
+++ b/iprconfig.c
@@ -96,8 +96,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 "less"
 
 #define IS_CANCEL_KEY(c) ((c == KEY_F(12)) || (c == 'q') || (c == 'Q'))
 #define CANCEL_KEY_LABEL "q=Cancel   "
@@ -12046,66 +12045,114 @@ int log_menu(i_container *i_con)
        return rc;
 }
 
+static int invoke_pager(char *filename)
+{
+       int pid, status;
+       char *argv[] = {
+               DEFAULT_EDITOR, "-c",
+               filename, NULL
+       };
+
+       pid = fork();
+       if (pid) {
+               waitpid(pid, &status, 0);
+       } else {
+               /* disable insecure pager features */
+               putenv("LESSSECURE=1");
+               execvp(argv[0], argv);
+               _exit(errno);
+       }
+       return WEXITSTATUS(status);
+}
+
 /**
  * ibm_storage_log_tail -
  * @i_con:             i_container struct
  *
  * Returns:
- *   1 if no status / 65 on failure
+ *   0 on success / non-zero on failure
  **/
-
 int ibm_storage_log_tail(i_container *i_con)
 {
-       char cmnd[MAX_CMD_LENGTH];
        int rc, len;
        int log_fd;
-       char *logfile;
-
-       logfile = strdup(_PATH_TMP"iprerror-XXXXXX");
-       log_fd = mkstemp(logfile);
+       char line[MAX_CMD_LENGTH];
+       char logfile[MAX_CMD_LENGTH];
+       char *tmp_log;
+       FILE *logsource_fp;
+
+       /* aux variables for erasing unnecessary log info */
+       const char *local_s = "localhost kernel: ipr";
+       const char *kernel_s = "kernel: ipr";
+       char prefix[256];
+       char host[256];
+       char *dot;
+
+       tmp_log = strdup(_PATH_TMP"iprerror-XXXXXX");
+       log_fd = mkstemp(tmp_log);
+       if (log_fd < 0) {
+               s_status.str = strerror(errno);
+               syslog(LOG_ERR, "Could not create tmp log file: %m\n");
+               free(tmp_log);
+               return RC_94_Tmp_Log_Fail;
+       }
 
        def_prog_mode();
+       endwin();
 
-       if (log_fd == -1) {
-               len = sprintf(cmnd, "cd %s; zcat -f messages", log_root_dir);
-
-               len += sprintf(cmnd + len," | grep ipr | ");
-               len += sprintf(cmnd + len, "sed \"s/ `hostname -s` kernel: 
ipr//g\" | ");
-               len += sprintf(cmnd + len, "sed \"s/ localhost kernel: ipr//g\" 
| ");
-               len += sprintf(cmnd + len, "sed \"s/ kernel: ipr//g\" | ");
-               len += sprintf(cmnd + len, "sed \"s/\\^M//g\" | ");
-               len += sprintf(cmnd + len, FAILSAFE_EDITOR);
-               closelog();
-               openlog("iprconfig", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
-               syslog(LOG_ERR, "Error encountered concatenating log 
files...\n");
-               syslog(LOG_ERR, "Using failsafe editor...\n");
-               closelog();
-               openlog("iprconfig", LOG_PID | LOG_CONS, LOG_USER);
-               sleep(3);
-       } else {
-               len = sprintf(cmnd,"cd %s; zcat -f messages | grep ipr |", 
log_root_dir);
-               len += sprintf(cmnd + len, "sed \"s/ `hostname -s` kernel: 
ipr//g\"");
-               len += sprintf(cmnd + len, " | sed \"s/ localhost kernel: 
ipr//g\"");
-               len += sprintf(cmnd + len, " | sed \"s/ kernel: ipr//g\"");
-               len += sprintf(cmnd + len, " | sed \"s/\\^M//g\" ");
-               len += sprintf(cmnd + len, ">> %s", logfile);
-               system(cmnd);
-
-               sprintf(cmnd, "%s %s", editor, logfile);
+       snprintf(logfile, sizeof(logfile), "%s/messages", log_root_dir);
+       logsource_fp = fopen(logfile, "r");
+       if (logsource_fp < 0) {
+               syslog(LOG_ERR, "Could not open %s: %m\n", logfile);
+               free(tmp_log);
+               close(log_fd);
+               return RC_75_Failed_Read_Err_Log;
        }
 
-       rc = system(cmnd);
+       while (fgets(line, sizeof(line), logsource_fp)) {
+               /* ignore lines that dont contain 'ipr' */
+               if (strstr(line, "ipr") == NULL)
+                       continue;
 
-       if (log_fd != -1)
-               close(log_fd);
+               /* build prefix using current hostname */
+               gethostname(host, sizeof(host));
+               dot = strchr(host, '.');
+               if (dot)
+                       *dot = '\0';
+               snprintf(prefix, sizeof(prefix), "%s kernel: ipr", host);
+
+               /* erase prefix, local_s and kernel_s from line:
+                * dot+strlen points to beginning of prefix
+                * strlen(dot) - strlen(prefix) + 1 == size of the rest of line
+                *
+                * code below moves 'rest of line' on top of prefix et al. */
+               if (dot = strstr(line, prefix)) {
+                       memmove(dot, dot + strlen(prefix),
+                               strlen(dot) - strlen(prefix) + 1);
+               } else if (dot = strstr(line, local_s)) {
+                       memmove(dot, dot+strlen(local_s),
+                               strlen(dot) - strlen(local_s) + 1);
+               } else if (dot = strstr(line, kernel_s)) {
+                       memmove(dot, dot+strlen(kernel_s),
+                               strlen(dot) - strlen(kernel_s) + 1);
+               }
+
+               write(log_fd, line, strlen(line));
+       }
+
+       fclose(logsource_fp);
+       close(log_fd);
+       rc = invoke_pager(tmp_log);
+       free(tmp_log);
 
        if ((rc != 0) && (rc != 127)) {
                /* "Editor returned %d. Try setting the default editor" */
                s_status.num = rc;
-               return 65; 
-       } else
-               /* return with no status */
-               return 1; 
+               return RC_65_Set_Default_Editor;
+       } else {
+               /* return with success */
+               return RC_0_Success;
+       }
 }
 
 /**
@@ -12162,74 +12209,97 @@ static int compare_log_file(const struct dirent 
**first_dir, const struct dirent
  * @i_con:             i_container struct
  *
  * Returns:
- *   0 if success / non-zero on failure FIXME
+ *   0 on success / non-zero on failure FIXME
  **/
 int ibm_storage_log(i_container *i_con)
 {
-       char cmnd[MAX_CMD_LENGTH];
+       char line[MAX_CMD_LENGTH];
+       char logfile[MAX_CMD_LENGTH];
        int i;
        struct dirent **log_files;
        struct dirent **dirent;
        int num_dir_entries;
        int rc, len;
        int log_fd;
-       char *logfile;
+       char *tmp_log;
+       gzFile logsource_fp;
 
-       logfile = strdup(_PATH_TMP"iprerror-XXXXXX");
-       log_fd = mkstemp(logfile);
+       /* aux variables for erasing unnecessary log info */
+       const char *local_s = "localhost kernel: ipr";
+       const char *kernel_s = "kernel: ipr";
+       char prefix[256];
+       char host[256];
+       char *dot;
+
+       tmp_log = strdup(_PATH_TMP"iprerror-XXXXXX");
+       log_fd = mkstemp(tmp_log);
+       if (log_fd < 0) {
+               s_status.str = strerror(errno);
+               syslog(LOG_ERR, "Could not create tmp log file: %m\n");
+               free(tmp_log);
+               return RC_94_Tmp_Log_Fail;
+       }
 
        def_prog_mode();
+       endwin();
 
        num_dir_entries = scandir(log_root_dir, &log_files, select_log_file, 
compare_log_file);
        if (num_dir_entries < 0) {
                s_status.num = 75;
-               return 75;
+               return RC_75_Failed_Read_Err_Log;
        }
 
        if (num_dir_entries)
                dirent = log_files;
 
-       if (log_fd == -1) {
-               len = sprintf(cmnd, "cd %s; zcat -f ", log_root_dir);
-
-               /* Probably have a read-only root file system */
-               for (i = 0; i < num_dir_entries; i++) {
-                       len += sprintf(cmnd + len, "%s ", (*dirent)->d_name);
-                       dirent++;
-               }
-
-               len += sprintf(cmnd + len," | grep ipr-err | ");
-               len += sprintf(cmnd + len, "sed \"s/ `hostname -s` kernel: 
ipr//g\" | ");
-               len += sprintf(cmnd + len, "sed \"s/ localhost kernel: ipr//g\" 
| ");
-               len += sprintf(cmnd + len, "sed \"s/ kernel: ipr//g\" | ");
-               len += sprintf(cmnd + len, "sed \"s/\\^M//g\" | ");
-               len += sprintf(cmnd + len, FAILSAFE_EDITOR);
-               closelog();
-               openlog("iprconfig", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
-               syslog(LOG_ERR, "Error encountered concatenating log 
files...\n");
-               syslog(LOG_ERR, "Using failsafe editor...\n");
-               closelog();
-               openlog("iprconfig", LOG_PID | LOG_CONS, LOG_USER);
-               sleep(3);
-       } else {
-               for (i = 0; i < num_dir_entries; i++) {
-                       len = sprintf(cmnd,"cd %s; zcat -f %s | grep ipr |", 
log_root_dir, (*dirent)->d_name);
-                       len += sprintf(cmnd + len, "sed \"s/ `hostname -s` 
kernel: ipr//g\"");
-                       len += sprintf(cmnd + len, " | sed \"s/ localhost 
kernel: ipr//g\"");
-                       len += sprintf(cmnd + len, " | sed \"s/ kernel: 
ipr//g\"");
-                       len += sprintf(cmnd + len, " | sed \"s/\\^M//g\" ");
-                       len += sprintf(cmnd + len, ">> %s", logfile);
-                       system(cmnd);
-                       dirent++;
+       for (i = 0; i < num_dir_entries; ++i) {
+               snprintf(logfile, sizeof(logfile), "%s/%s", log_root_dir,
+                        (*dirent)->d_name);
+               logsource_fp = gzopen(logfile, "r");
+               if (logsource_fp == NULL) {
+                       syslog(LOG_ERR, "Could not open %s: %m\n", line);
+                       close(log_fd);
+                       continue; /* proceed to next log file */
                }
 
-               sprintf(cmnd, "%s %s", editor, logfile);
-       }
+               while (gzgets(logsource_fp, line, sizeof(line))) {
+                       /* ignore lines that dont contain 'ipr' */
+                       if (strstr(line, "ipr") == NULL)
+                               continue;
 
-       rc = system(cmnd);
+                       gethostname(host, sizeof(host));
+                       dot = strchr(host, '.');
+                       if (dot)
+                               *dot = '\0';
+                       snprintf(prefix, sizeof(prefix), "%s kernel: ipr",
+                                host);
+
+                       /* erase prefix, local_s and kernel_s from line:
+                        * dot+strlen points to beginning of prefix
+                        * strlen(dot) - strlen(prefix) + 1 ==
+                        *             size of the rest of line
+                        *
+                        * code below moves 'rest of line' on top of prefix */
+                       if (dot = strstr(line, prefix)) {
+                               memmove(dot, dot + strlen(prefix),
+                                       strlen(dot) - strlen(prefix) + 1);
+                       } else if (dot = strstr(line, local_s)) {
+                               memmove(dot, dot + strlen(local_s),
+                                       strlen(dot) - strlen(local_s) + 1);
+                       } else if (dot = strstr(line, kernel_s)) {
+                               memmove(dot, dot + strlen(kernel_s),
+                                       strlen(dot) - strlen(kernel_s) + 1);
+                       }
 
-       if (log_fd != -1)
-               close(log_fd);
+                       write(log_fd, line, strlen(line));
+               }
+               gzclose_r(logsource_fp);
+               dirent++;
+       }
+
+       close(log_fd);
+       rc = invoke_pager(tmp_log);
+       free(tmp_log);
 
        if (num_dir_entries) {
                while (num_dir_entries--)
@@ -12240,10 +12310,11 @@ int ibm_storage_log(i_container *i_con)
        if ((rc != 0) && (rc != 127)) {
                /* "Editor returned %d. Try setting the default editor" */
                s_status.num = rc;
-               return 65; 
-       } else
-               /* return with no status */
-               return 1; 
+               return RC_65_Set_Default_Editor;
+       } else {
+               /* return with success */
+               return RC_0_Success;
+       }
 }
 
 /**
@@ -12255,63 +12326,57 @@ int ibm_storage_log(i_container *i_con)
  **/
 int kernel_log(i_container *i_con)
 {
-       char cmnd[MAX_CMD_LENGTH];
+       char line[MAX_CMD_LENGTH];
+       char logfile[MAX_CMD_LENGTH];
        int rc, i;
        struct dirent **log_files;
        struct dirent **dirent;
        int num_dir_entries;
        int len;
        int log_fd;
-       char *logfile;
+       char *tmp_log;
+       gzFile logsource_fp;
 
-       logfile = strdup(_PATH_TMP"iprerror-XXXXXX");
-       log_fd = mkstemp(logfile);
+       tmp_log = strdup(_PATH_TMP"iprerror-XXXXXX");
+       log_fd = mkstemp(tmp_log);
+       if (log_fd < 0) {
+               s_status.str = strerror(errno);
+               syslog(LOG_ERR, "Could not create tmp log file: %m\n");
+               free(tmp_log);
+               return RC_94_Tmp_Log_Fail;
+       }
 
        def_prog_mode();
+       endwin();
 
        num_dir_entries = scandir(log_root_dir, &log_files, select_log_file, 
compare_log_file);
        if (num_dir_entries < 0) {
                s_status.num = 75;
-               return 75;
+               return RC_75_Failed_Read_Err_Log;
        }
 
        if (num_dir_entries)
                dirent = log_files;
 
-       if (log_fd == -1) {
-               /* Probably have a read-only root file system */
-               len = sprintf(cmnd, "cd %s; zcat -f ", log_root_dir);
-
-               /* Probably have a read-only root file system */
-               for (i = 0; i < num_dir_entries; i++) {
-                       len += sprintf(cmnd + len, "%s ", (*dirent)->d_name);
-                       dirent++;
-               }
-
-               len += sprintf(cmnd + len, " | sed \"s/\\^M//g\" ");
-               len += sprintf(cmnd + len, "| %s", FAILSAFE_EDITOR);
-               closelog();
-               openlog("iprconfig", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
-               syslog(LOG_ERR, "Error encountered concatenating log 
files...\n");
-               syslog(LOG_ERR, "Using failsafe editor...\n");
-               openlog("iprconfig", LOG_PID | LOG_CONS, LOG_USER);
-               sleep(3);
-       } else {
-               for (i = 0; i < num_dir_entries; i++) {
-                       sprintf(cmnd,
-                               "cd %s; zcat -f %s | sed \"s/\\^M//g\" >> %s",
-                               log_root_dir, (*dirent)->d_name, logfile);
-                       system(cmnd);
-                       dirent++;
+       for (i = 0; i < num_dir_entries; ++i) {
+               snprintf(logfile, sizeof(logfile), "%s/%s", log_root_dir,
+                        (*dirent)->d_name);
+               logsource_fp = gzopen(logfile, "r");
+               if (logsource_fp == NULL) {
+                       syslog(LOG_ERR, "Could not open %s: %m\n", line);
+                       close(log_fd);
+                       continue; /* proceed to next log file */
                }
 
-               sprintf(cmnd, "%s %s", editor, logfile);
+               while (gzgets(logsource_fp, line, sizeof(line)))
+                       write(log_fd, line, strlen(line));
+               gzclose_r(logsource_fp);
+               dirent++;
        }
 
-       rc = system(cmnd);
-
-       if (log_fd != -1)
-               close(log_fd);
+       close(log_fd);
+       rc = invoke_pager(tmp_log);
+       free(tmp_log);
 
        if (num_dir_entries > 0) {
                while (num_dir_entries--)
@@ -12322,11 +12387,12 @@ int kernel_log(i_container *i_con)
        if ((rc != 0) && (rc != 127))   {
                /* "Editor returned %d. Try setting the default editor" */
                s_status.num = rc;
-               return 65; 
+               return RC_65_Set_Default_Editor;
+       }
+       else {
+               /* return with success */
+               return RC_0_Success;
        }
-       else
-               /* return with no status */
-               return 1; 
 }
 
 /**
@@ -12338,61 +12404,61 @@ int kernel_log(i_container *i_con)
  **/
 int iprconfig_log(i_container *i_con)
 {
-       char cmnd[MAX_CMD_LENGTH];
+       char line[MAX_CMD_LENGTH];
+       char logfile[MAX_CMD_LENGTH];
        int rc, i;
        struct dirent **log_files;
        struct dirent **dirent;
        int num_dir_entries;
        int len;
        int log_fd;
-       char *logfile;
+       char *tmp_log;
+       gzFile logsource_fp;
 
-       logfile = strdup(_PATH_TMP"iprerror-XXXXXX");
-       log_fd = mkstemp(logfile);
+       tmp_log = strdup(_PATH_TMP"iprerror-XXXXXX");
+       log_fd = mkstemp(tmp_log);
+       if (log_fd < 0) {
+               s_status.str = strerror(errno);
+               syslog(LOG_ERR, "Could not create tmp log file: %m\n");
+               free(tmp_log);
+               return RC_94_Tmp_Log_Fail;
+       }
 
        def_prog_mode();
+       endwin();
 
        num_dir_entries = scandir(log_root_dir, &log_files, select_log_file, 
compare_log_file);
        if (num_dir_entries < 0) {
                s_status.num = 75;
-               return 75;
+               return RC_75_Failed_Read_Err_Log;
        }
 
        if (num_dir_entries)
                dirent = log_files;
 
-       if (log_fd == -1) {
-               len = sprintf(cmnd, "cd %s; zcat -f ", log_root_dir);
-
-               /* Probably have a read-only root file system */
-               for (i = 0; i < num_dir_entries; i++) {
-                       len += sprintf(cmnd + len, "%s ", (*dirent)->d_name);
-                       dirent++;
+       for (i = 0; i < num_dir_entries; ++i) {
+               snprintf(logfile, sizeof(logfile), "%s/%s", log_root_dir,
+                        (*dirent)->d_name);
+               logsource_fp = gzopen(logfile, "r");
+               if (logsource_fp == NULL) {
+                       syslog(LOG_ERR, "Could not open %s: %m\n", line);
+                       close(log_fd);
+                       continue; /* proceed to next log file */
                }
 
-               len += sprintf(cmnd + len," | grep iprconfig | ");
-               len += sprintf(cmnd + len, FAILSAFE_EDITOR);
-               closelog();
-               openlog("iprconfig", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
-               syslog(LOG_ERR, "Error encountered concatenating log 
files...\n");
-               syslog(LOG_ERR, "Using failsafe editor...\n");
-               openlog("iprconfig", LOG_PID | LOG_CONS, LOG_USER);
-               sleep(3);
-       } else {
-               for (i = 0; i < num_dir_entries; i++) {
-                       len = sprintf(cmnd,"cd %s; zcat -f %s | grep iprconfig 
", log_root_dir, (*dirent)->d_name);
-                       len += sprintf(cmnd + len, ">> %s", logfile);
-                       system(cmnd);
-                       dirent++;
+               while (gzgets(logsource_fp, line, sizeof(line))) {
+                       /* ignore lines that dont contain 'iprconfig' */
+                       if (strstr(line, "iprconfig") == NULL)
+                               continue;
+                       write(log_fd, line, strlen(line));
                }
-
-               sprintf(cmnd, "%s %s", editor, logfile);
+               gzclose_r(logsource_fp);
+               dirent++;
        }
 
-       rc = system(cmnd);
-
-       if (log_fd != -1)
-               close(log_fd);
+       close(log_fd);
+       rc = invoke_pager(tmp_log);
+       free(tmp_log);
 
        if (num_dir_entries) {
                while (num_dir_entries--)
@@ -12403,10 +12469,11 @@ int iprconfig_log(i_container *i_con)
        if ((rc != 0) && (rc != 127))   {
                /* "Editor returned %d. Try setting the default editor" */
                s_status.num = rc;
-               return 65; 
-       } else
-               /* return with no status */
-               return 1; 
+               return RC_65_Set_Default_Editor;
+       } else {
+               /* return with success */
+               return RC_0_Success;
+       }
 }
 
 /**
@@ -12598,56 +12665,62 @@ int restore_log_defaults(i_container *i_con)
  **/
 int ibm_boot_log(i_container *i_con)
 {
-       char cmnd[MAX_CMD_LENGTH];
+       char line[MAX_CMD_LENGTH];
+       char logfile[MAX_CMD_LENGTH];
        int rc;
        int len;
        struct stat file_stat;
        int log_fd;
-       char *logfile;
+       char *tmp_log;
+       FILE *logsource_fp;
 
-
-       sprintf(cmnd,"%s/boot.msg",log_root_dir);
-       rc = stat(cmnd, &file_stat);
+       sprintf(line,"%s/boot.msg",log_root_dir);
+       rc = stat(line, &file_stat);
        if (rc)
                return 2; /* "Invalid option specified" */
 
-       logfile = strdup(_PATH_TMP"iprerror-XXXXXX");
-       log_fd = mkstemp(logfile);
+       tmp_log = strdup(_PATH_TMP"iprerror-XXXXXX");
+       log_fd = mkstemp(tmp_log);
+       if (log_fd < 0) {
+               s_status.str = strerror(errno);
+               syslog(LOG_ERR, "Could not create temp log file: %m\n");
+               free(tmp_log);
+               return RC_94_Tmp_Log_Fail;
+       }
 
        def_prog_mode();
+       endwin();
 
-       if (log_fd == -1) {
-               len = sprintf(cmnd, "cd %s; zcat -f ", log_root_dir);
-
-               /* Probably have a read-only root file system */
-               len += sprintf(cmnd + len, "boot.msg");
-               len += sprintf(cmnd + len," | grep ipr |");
-               len += sprintf(cmnd + len, FAILSAFE_EDITOR);
-               closelog();
-               openlog("iprconfig", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
-               syslog(LOG_ERR, "Error encountered concatenating log 
files...\n");
-               syslog(LOG_ERR, "Using failsafe editor...\n");
-               closelog();
-               openlog("iprconfig", LOG_PID | LOG_CONS, LOG_USER);
-               sleep(3);
-       } else {
-               len = sprintf(cmnd,"cd %s; zcat -f boot.msg | grep ipr  | "
-                             "sed 's/<[0-9]>ipr-err: //g' | sed 's/<[0-9]>ipr: 
//g'",
-                             log_root_dir);
-               len += sprintf(cmnd + len, ">> %s", logfile);
-               system(cmnd);
-               sprintf(cmnd, "%s %s", editor, logfile);
+       snprintf(logfile, sizeof(logfile), "%s/boot.msg", log_root_dir);
+       logsource_fp = fopen(logfile, "r");
+       if (logsource_fp < 0) {
+               syslog(LOG_ERR, "Could not open %s: %m\n", line);
+               free(tmp_log);
+               close(log_fd);
+               return RC_75_Failed_Read_Err_Log;
        }
-       rc = system(cmnd);
 
-       if (log_fd != -1)
-               close(log_fd);
+       while (fgets(line, sizeof(line), logsource_fp)) {
+               /* ignore lines that dont contain 'ipr' */
+               if (strstr(line, "ipr") == NULL)
+                       continue;
+
+               write(log_fd, line, strlen(line));
+       }
+
+       fclose(logsource_fp);
+       close(log_fd);
+       rc = invoke_pager(tmp_log);
+       free(tmp_log);
 
        if ((rc != 0) && (rc != 127)) {
+               /* "Editor returned %d. Try setting the default editor" */
                s_status.num = rc;
-               return 65; /* "Editor returned %d. Try setting the default 
editor" */
-       } else
-               return 1; /* return with no status */
+               return RC_65_Set_Default_Editor;
+       } else {
+               /* return with no status */
+               return RC_0_Success;
+       }
 }
 
 int get_ses_ioport_status(struct ipr_dev *ses)
diff --git a/iprconfig.h b/iprconfig.h
index 9bce950e1c0f..8e3ca901f142 100644
--- a/iprconfig.h
+++ b/iprconfig.h
@@ -1718,6 +1718,7 @@ const char *screen_status[] = {
        /* 91 */ __("Create disk array failed - can not mix 5XX and 4K disks."),
        /* 92 */ __("Create disk array failed - can not build with read 
intensive disks only."),
        /* 93 */ __("All devices up to date"),
+       /* 94 */ __("Temporary log file creation failed: %s"),
 
       /* NOTE:  127 maximum limit */
 };
@@ -1818,6 +1819,7 @@ enum {
        RC_91_Mixed_Logical_Blk_Size,
        RC_92_UNSUPT_REQ_BLK_DEV_CLASS,
        RC_93_All_Up_To_Date,
+       RC_94_Tmp_Log_Fail,
 
        /* NOTE:  127 maximum limit */
 };
diff --git a/iprlib.h b/iprlib.h
index 16fe1e162650..82a3139171a8 100644
--- a/iprlib.h
+++ b/iprlib.h
@@ -49,6 +49,7 @@
 #include <bits/sockaddr.h>
 #include <linux/netlink.h>
 #include <time.h>
+#include <zlib.h>
 
 typedef uint8_t u8;
 typedef uint16_t u16;
diff --git a/spec/iprutils.spec b/spec/iprutils.spec
index 0d6f22bdf241..da9c204915e8 100644
--- a/spec/iprutils.spec
+++ b/spec/iprutils.spec
@@ -11,7 +11,7 @@ Vendor: IBM
 URL: http://sourceforge.net/projects/iprdd/
 Source0: iprutils-%{version}.%{release_prefix}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-root
-BuildRequires: ncurses-devel
+BuildRequires: ncurses-devel zlib-devel
 
 # Predicate whether we want to build -static package.
 %bcond_with static
@@ -77,9 +77,9 @@ supported by the ipr SCSI storage device driver.
 Summary: Static version of iprutils.
 Group: System Environment/Base
 %if 0%{?suse_version:1}
-BuildRequires: glibc-static
+BuildRequires: glibc-static zlib-static
 %else
-BuildRequires: glibc-static ncurses-static
+BuildRequires: glibc-static ncurses-static zlib-static
 %endif
 
 %description static
-- 
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