]> granicus.if.org Git - postgresql/blobdiff - src/bin/psql/command.c
Misc message style and doc fixes.
[postgresql] / src / bin / psql / command.c
index 0b7b8d45b8bd21033636af59a3c2fb41d63da707..cede72a5d6cc18d9eb282dbc5784c1b6db641eec 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * psql - the PostgreSQL interactive terminal
  *
- * Copyright (c) 2000-2013, PostgreSQL Global Development Group
+ * Copyright (c) 2000-2014, PostgreSQL Global Development Group
  *
  * src/bin/psql/command.c
  */
@@ -264,11 +264,15 @@ exec_command(const char *cmd,
                {
 #ifndef WIN32
                        struct passwd *pw;
+                       uid_t           user_id = geteuid();
 
-                       pw = getpwuid(geteuid());
+                       errno = 0;                      /* clear errno before call */
+                       pw = getpwuid(user_id);
                        if (!pw)
                        {
-                               psql_error("could not get home directory: %s\n", strerror(errno));
+                               psql_error("could not get home directory for user id %ld: %s\n",
+                                                  (long) user_id,
+                                                errno ? strerror(errno) : _("user does not exist"));
                                exit(EXIT_FAILURE);
                        }
                        dir = pw->pw_dir;
@@ -297,7 +301,7 @@ exec_command(const char *cmd,
        else if (strcmp(cmd, "conninfo") == 0)
        {
                char       *db = PQdb(pset.db);
-               char       *host = PQhost(pset.db);
+               char       *host = (PQhostaddr(pset.db) != NULL) ? PQhostaddr(pset.db) : PQhost(pset.db);
 
                if (db == NULL)
                        printf(_("You are currently not connected to a database.\n"));
@@ -407,7 +411,7 @@ exec_command(const char *cmd,
                                success = listSchemas(pattern, show_verbose, show_system);
                                break;
                        case 'o':
-                               success = describeOperators(pattern, show_system);
+                               success = describeOperators(pattern, show_verbose, show_system);
                                break;
                        case 'O':
                                success = listCollations(pattern, show_verbose, show_system);
@@ -760,6 +764,7 @@ exec_command(const char *cmd,
                        /* we must set a non-NULL prefix to trigger storing */
                        pset.gset_prefix = pg_strdup("");
                }
+               /* gset_prefix is freed later */
                status = PSQL_CMD_SEND;
        }
 
@@ -1041,20 +1046,21 @@ exec_command(const char *cmd,
 
                if (!opt0)
                {
-                      size_t i;
-                      /* list all variables */
-                      static const char *const my_list[] = {
+                       /* list all variables */
+
+                       int                     i;
+                       static const char *const my_list[] = {
                                "border", "columns", "expanded", "fieldsep",
                                "footer", "format", "linestyle", "null",
                                "numericlocale", "pager", "recordsep",
                                "tableattr", "title", "tuples_only",
-                               NULL };
-                      for (i = 0; my_list[i] != NULL; i++) {
-                              printPsetInfo(my_list[i], &pset.popt);
-                      }
+                               NULL
+                       };
 
-                      success = true;
+                       for (i = 0; my_list[i] != NULL; i++)
+                               printPsetInfo(my_list[i], &pset.popt);
 
+                       success = true;
                }
                else
                        success = do_pset(opt0, opt1, &pset.popt, pset.quiet);
@@ -1794,8 +1800,8 @@ printSSLInfo(void)
                return;                                 /* no SSL */
 
        SSL_get_cipher_bits(ssl, &sslbits);
-       printf(_("SSL connection (cipher: %s, bits: %d)\n"),
-                  SSL_get_cipher(ssl), sslbits);
+       printf(_("SSL connection (protocol: %s, cipher: %s, bits: %d)\n"),
+                  SSL_get_version(ssl), SSL_get_cipher(ssl), sslbits);
 #else
 
        /*
@@ -1924,17 +1930,17 @@ editFile(const char *fname, int lineno)
 #ifndef WIN32
        if (lineno > 0)
                sys = psprintf("exec %s %s%d '%s'",
-                                       editorName, editor_lineno_arg, lineno, fname);
+                                          editorName, editor_lineno_arg, lineno, fname);
        else
                sys = psprintf("exec %s '%s'",
-                                       editorName, fname);
+                                          editorName, fname);
 #else
        if (lineno > 0)
-               sys = psprintf(SYSTEMQUOTE "\"%s\" %s%d \"%s\"" SYSTEMQUOTE,
-                               editorName, editor_lineno_arg, lineno, fname);
+               sys = psprintf("\"%s\" %s%d \"%s\"",
+                                          editorName, editor_lineno_arg, lineno, fname);
        else
-               sys = psprintf(SYSTEMQUOTE "\"%s\" \"%s\"" SYSTEMQUOTE,
-                                       editorName, fname);
+               sys = psprintf("\"%s\" \"%s\"",
+                                          editorName, fname);
 #endif
        result = system(sys);
        if (result == -1)
@@ -2021,14 +2027,20 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf,
                        if (fwrite(query_buf->data, 1, ql, stream) != ql)
                        {
                                psql_error("%s: %s\n", fname, strerror(errno));
-                               fclose(stream);
-                               remove(fname);
+
+                               if (fclose(stream) != 0)
+                                       psql_error("%s: %s\n", fname, strerror(errno));
+
+                               if (remove(fname) != 0)
+                                       psql_error("%s: %s\n", fname, strerror(errno));
+
                                error = true;
                        }
                        else if (fclose(stream) != 0)
                        {
                                psql_error("%s: %s\n", fname, strerror(errno));
-                               remove(fname);
+                               if (remove(fname) != 0)
+                                       psql_error("%s: %s\n", fname, strerror(errno));
                                error = true;
                        }
                }
@@ -2432,8 +2444,8 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
                return false;
        }
 
-       if (!quiet)
-              printPsetInfo(param, &pset.popt);
+       if (!quiet)
+               printPsetInfo(param, &pset.popt);
 
        return true;
 }
@@ -2451,7 +2463,7 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                        printf(_("Border style (%s) unset.\n"), param);
                else
                        printf(_("Border style (%s) is %d.\n"), param,
-                               popt->topt.border);
+                                  popt->topt.border);
        }
 
        /* show the target width for the wrapped format */
@@ -2461,7 +2473,7 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                        printf(_("Target width (%s) unset.\n"), param);
                else
                        printf(_("Target width (%s) is %d.\n"), param,
-                               popt->topt.columns);
+                                  popt->topt.columns);
        }
 
        /* show expanded/vertical mode */
@@ -2482,7 +2494,7 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                        printf(_("Field separator (%s) is zero byte.\n"), param);
                else
                        printf(_("Field separator (%s) is \"%s\".\n"), param,
-                               popt->topt.fieldSep.separator);
+                                  popt->topt.fieldSep.separator);
        }
 
        else if (strcmp(param, "fieldsep_zero") == 0)
@@ -2506,21 +2518,21 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                        printf(_("Output format (%s) is aligned.\n"), param);
                else
                        printf(_("Output format (%s) is %s.\n"), param,
-                               _align2string(popt->topt.format));
+                                  _align2string(popt->topt.format));
        }
 
        /* show table line style */
        else if (strcmp(param, "linestyle") == 0)
        {
                printf(_("Line style (%s) is %s.\n"), param,
-                       get_line_style(&popt->topt)->name);
+                          get_line_style(&popt->topt)->name);
        }
 
        /* show null display */
        else if (strcmp(param, "null") == 0)
        {
                printf(_("Null display (%s) is \"%s\".\n"), param,
-                       popt->nullPrint ? popt->nullPrint : "");
+                          popt->nullPrint ? popt->nullPrint : "");
        }
 
        /* show locale-aware numeric output */
@@ -2540,7 +2552,7 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                else if (popt->topt.pager == 2)
                        printf(_("Pager (%s) is always used.\n"), param);
                else
-                       printf(_("Pager (%s) usage is off.\n"), param);
+                       printf(_("Pager usage (%s) is off.\n"), param);
        }
 
        /* show record separator for unaligned text */
@@ -2552,7 +2564,7 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
                        printf(_("Record separator (%s) is <newline>.\n"), param);
                else
                        printf(_("Record separator (%s) is \"%s\".\n"), param,
-                               popt->topt.recordSep.separator);
+                                  popt->topt.recordSep.separator);
        }
 
        else if (strcmp(param, "recordsep_zero") == 0)
@@ -2564,8 +2576,8 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
        else if (strcmp(param, "T") == 0 || strcmp(param, "tableattr") == 0)
        {
                if (popt->topt.tableAttr)
-                       printf(_("Table attribute (%s) is \"%s\".\n"), param,
-                               popt->topt.tableAttr);
+                       printf(_("Table attributes (%s) are \"%s\".\n"), param,
+                                  popt->topt.tableAttr);
                else
                        printf(_("Table attributes (%s) unset.\n"), param);
        }
@@ -2631,7 +2643,7 @@ do_shell(const char *command)
 #ifndef WIN32
                sys = psprintf("exec %s", shellName);
 #else
-               sys = psprintf(SYSTEMQUOTE "\"%s\"" SYSTEMQUOTE, shellName);
+               sys = psprintf("\"%s\"", shellName);
 #endif
                result = system(sys);
                free(sys);
@@ -2785,7 +2797,7 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
        PGresult   *res;
 
        query = createPQExpBuffer();
-       printfPQExpBuffer(query, "SELECT ");
+       appendPQExpBufferStr(query, "SELECT ");
        appendStringLiteralConn(query, desc, conn);
        appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
                                          strchr(desc, '(') ? "regprocedure" : "regproc");