Print this page
3347 zonecfg(1M) is confused about selection
4956 zonecfg won't use a valid pager

@@ -20,10 +20,11 @@
  */
 
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2014 Gary Mills
  */
 
 /*
  * zonecfg is a lex/yacc based command interpreter used to manage zone
  * configurations.  The lexer (see zonecfg_lex.l) builds up tokens, which

@@ -929,20 +930,23 @@
                         pager = PAGER;
 
                 space = strchr(pager, ' ');
                 if (space)
                         *space = '\0';
-                if (stat(pager, &statbuf) == 0) {
+                if (*pager == '/' && stat(pager, &statbuf) != 0) {
+                        zerr(gettext("PAGER %s does not exist (%s)."),
+                            pager, strerror(errno));
+                } else {
                         if (space)
                                 *space = ' ';
-                        if ((newfp = popen(pager, "w")) != NULL) {
+                        if ((newfp = popen(pager, "w")) == NULL) {
+                                zerr(gettext("PAGER %s open failed (%s)."),
+                                    pager, strerror(errno));
+                        } else {
                                 need_to_close = B_TRUE;
                                 fp = newfp;
                         }
-                } else {
-                        zerr(gettext("PAGER %s does not exist (%s)."),
-                            pager, strerror(errno));
                 }
         }
 
         if (flags & HELP_META) {
                 (void) fprintf(fp, gettext("More help is available for the "

@@ -1271,12 +1275,21 @@
                     pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP),
                     pt_to_str(PT_LOCKED));
                 (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_ADMIN),
                     pt_to_str(PT_USER), pt_to_str(PT_AUTHS));
         }
-        if (need_to_close)
-                (void) pclose(fp);
+        if (need_to_close) {
+                int status;
+
+                status = pclose(fp);
+                if (status == -1)
+                        zerr(gettext("PAGER %s close failed (%s)."),
+                            pager, strerror(errno));
+                else if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+                        zerr(gettext("PAGER %s exit code: %d."),
+                            pager, WEXITSTATUS(status));
+        }
 }
 
 static void
 zone_perror(char *prefix, int err, boolean_t set_saw)
 {

@@ -5360,21 +5373,24 @@
                 if ((pager = getenv("PAGER")) == NULL)
                         pager = PAGER;
                 space = strchr(pager, ' ');
                 if (space)
                         *space = '\0';
-                if (stat(pager, &statbuf) == 0) {
+                if (*pager == '/' && stat(pager, &statbuf) != 0) {
+                        zerr(gettext("PAGER %s does not exist (%s)."),
+                            pager, strerror(errno));
+                } else {
                         if (space)
                                 *space = ' ';
-                        if ((fp = popen(pager, "w")) != NULL)
-                                need_to_close = B_TRUE;
-                        else
+                        if ((fp = popen(pager, "w")) == NULL) {
                                 fp = stdout;
-                } else {
-                        zerr(gettext("PAGER %s does not exist (%s)."),
+                                zerr(gettext("PAGER %s open failed (%s)."),
                             pager, strerror(errno));
+                        } else {
+                                need_to_close = B_TRUE;
                 }
+                }
 
                 setbuf(fp, NULL);
         }
 
         if (!global_scope) {

@@ -5559,12 +5575,21 @@
                 zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE,
                     B_TRUE);
         }
 
 cleanup:
-        if (need_to_close)
-                (void) pclose(fp);
+        if (need_to_close) {
+                int status;
+
+                status = pclose(fp);
+                if (status == -1)
+                        zerr(gettext("PAGER %s close failed (%s)."),
+                            pager, strerror(errno));
+                else if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+                        zerr(gettext("PAGER %s exit code: %d."),
+                            pager, WEXITSTATUS(status));
+        }
 }
 
 /*
  * Helper function for verify-- checks that a required string property
  * exists.