*
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.44 2004/10/27 19:44:14 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.45 2004/11/04 22:25:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* http://dev.remotenetworktechnology.com/cmd/cmdfaq.htm
*/
if (log_file != NULL)
-#if !defined(WIN32) /* Cygwin doesn't have START */
+#ifndef WIN32 /* Cygwin doesn't have START */
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
DEVNULL, log_file, SYSTEMQUOTE);
else
-#if !defined(WIN32) /* Cygwin doesn't have START */
+#ifndef WIN32 /* Cygwin doesn't have START */
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",
*
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.129 2004/10/16 03:10:16 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.130 2004/11/04 22:25:14 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
#include <io.h>
#include <fcntl.h>
#include <direct.h>
+#ifndef WIN32_CLIENT_ONLY
+#include <sys/types.h> /* for umask() */
+#include <sys/stat.h> /* for stat() */
+#endif
#endif
#include "libpq-fe.h"
#ifndef WIN32
"exec "
#endif
- "%s '%s'", editorName, fname);
+ "%s\"%s\" \"%s\"%s", SYSTEMQUOTE, editorName, fname, SYSTEMQUOTE);
result = system(sys);
if (result == -1)
psql_error("could not start editor \"%s\"\n", editorName);
bool error = false;
int fd;
-#ifndef WIN32
+#ifndef WIN32_CLIENT_ONLY
struct stat before,
after;
#endif
{
/* make a temp file to edit */
#ifndef WIN32
- const char *tmpdirenv = getenv("TMPDIR");
+ const char *tmpdir = getenv("TMPDIR");
- snprintf(fnametmp, sizeof(fnametmp), "%s/psql.edit.%d.%d",
- tmpdirenv ? tmpdirenv : "/tmp", geteuid(), (int)getpid());
+ if (!tmpdir)
+ tmpdir = "/tmp";
+#else
+ char tmpdir[MAXPGPATH];
+ int ret;
+
+ ret = GetTempPath(MAXPGPATH, tmpdir);
+ if (ret == 0 || ret > MAXPGPATH)
+ {
+ psql_error("Can not locate temporary directory: %s",
+ !ret ? strerror(errno) : "");
+ return false;
+ }
+ /*
+ * No canonicalize_path() here.
+ * EDIT.EXE run from CMD.EXE prepends the current directory to the
+ * supplied path unless we use only backslashes, so we do that.
+ */
+#endif
+ snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
+#ifndef WIN32
+ "/",
#else
- GetTempFileName(".", "psql", 0, fnametmp);
+ "", /* trailing separator already present */
#endif
+ (int)getpid());
+
fname = (const char *) fnametmp;
fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
}
}
-#ifndef WIN32
+#ifndef WIN32_CLIENT_ONLY
if (!error && stat(fname, &before) != 0)
{
psql_error("%s: %s\n", fname, strerror(errno));
if (!error)
error = !editFile(fname);
-#ifndef WIN32
+#ifndef WIN32_CLIENT_ONLY
if (!error && stat(fname, &after) != 0)
{
psql_error("%s: %s\n", fname, strerror(errno));
if (!command)
{
char *sys;
- const char *shellName;
+ const char *shellName = NULL;
- shellName = getenv("SHELL");
+#ifdef WIN32
+ shellName = getenv("COMSPEC");
+#endif
+ if (shellName == NULL)
+ shellName = getenv("SHELL");
if (shellName == NULL)
shellName = DEFAULT_SHELL;
#ifndef WIN32
"exec "
#endif
- "%s", shellName);
+ "%s\"%s\"%s", SYSTEMQUOTE, shellName, SYSTEMQUOTE);
result = system(sys);
free(sys);
}