Re: [PATCHES] pg_ctl using START with paths needing quotes
Bruce Momjian wrote: Tom Lane wrote: Andrew Dunstan <[EMAIL PROTECTED]> writes: Bruce Momjian wrote: This applied patch changes the way pg_ctl starts on Win32. Using START, it is not possible to quote the executable name, who's directory might have spaces: This is a really ugly hack (I take the blame since I gave Bruce the idea). There are a few things to note: . the .bat file should probably be created in the data dir - that's about the only place that we should be guaranteed we can write. In that case, haven't we simply moved the spaces problem from the executable directory to the data directory? Yep. That code is all gone now that we have the right fix, use: START "" "executable" For the record, and in case we need to use it in future, here's what I got working in pg_ctl.c for starting without any shell call required (lacks error checking). cheers andrew #ifdef WIN32 char exepath[MAXPGPATH]; STARTUPINFO si; PROCESS_INFORMATION pi; bool rval; int null_fd, log_fd; int save_stdin, save_stdout, save_stderr; save_stdin = _dup(fileno(stdin)); ZeroMemory(&si,sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); null_fd = open("nul",O_RDONLY,0); dup2(null_fd, fileno(stdin)); if (log_file != NULL) { save_stdout = _dup(fileno(stdout)); save_stderr = _dup(fileno(stderr)); log_fd = open(log_file,O_WRONLY|O_CREAT|O_APPEND,0700); dup2(log_fd, fileno(stdout)); dup2(log_fd ,fileno(stderr)); } snprintf(exepath,MAXPGPATH,"%s",postgres_path); snprintf(cmd,MAXPGPATH,"\"%s\" %s",postgres_path,post_opts); rval = CreateProcess(exepath,cmd,NULL,NULL,true,0,NULL,NULL,&si,&pi); if (rval == 0) { CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } dup2(save_stdin, fileno(stdin)); close(null_fd); if (log_file != NULL) { dup2(save_stdout,fileno(stdout)); dup2(save_stderr,fileno(stderr)); close(log_fd); } return (rval == 0); #else ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] pg_ctl using START with paths needing quotes
Tom Lane wrote: > Andrew Dunstan <[EMAIL PROTECTED]> writes: > > Bruce Momjian wrote: > >> This applied patch changes the way pg_ctl starts on Win32. > >> > >> Using START, it is not possible to quote the executable name, who's > >> directory might have spaces: > > > > This is a really ugly hack (I take the blame since I gave Bruce the > > idea). There are a few things to note: > > > . the .bat file should probably be created in the data dir - that's > > about the only place that we should be guaranteed we can write. > > In that case, haven't we simply moved the spaces problem from the > executable directory to the data directory? Yep. That code is all gone now that we have the right fix, use: START "" "executable" -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] pg_ctl using START with paths needing quotes
Andrew Dunstan <[EMAIL PROTECTED]> writes: > Bruce Momjian wrote: >> This applied patch changes the way pg_ctl starts on Win32. >> >> Using START, it is not possible to quote the executable name, who's >> directory might have spaces: > > This is a really ugly hack (I take the blame since I gave Bruce the > idea). There are a few things to note: > . the .bat file should probably be created in the data dir - that's > about the only place that we should be guaranteed we can write. In that case, haven't we simply moved the spaces problem from the executable directory to the data directory? regards, tom lane ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] pg_ctl using START with paths needing quotes
Tom Lane wrote: Andrew Dunstan <[EMAIL PROTECTED]> writes: Bruce Momjian wrote: This applied patch changes the way pg_ctl starts on Win32. Using START, it is not possible to quote the executable name, who's directory might have spaces: This is a really ugly hack (I take the blame since I gave Bruce the idea). There are a few things to note: . the .bat file should probably be created in the data dir - that's about the only place that we should be guaranteed we can write. In that case, haven't we simply moved the spaces problem from the executable directory to the data directory? Yes. you're right. The hack is gone now so it's moot. cheers andrew ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] pg_ctl using START with paths needing quotes
Andrew Dunstan wrote: > > This is a really ugly hack (I take the blame since I gave Bruce the > idea). There are a few things to note: > > . the .bat file should probably be created in the data dir - that's > about the only place that we should be guaranteed we can write. > . the command should be preceded by '@' to suppress echoing > . the whole command, including redirections should go inside the .bat > file, so that pg_ctl just issues 'start /b foo.bat' > > There are still things to clean up in pg_ctl, e.g. its handling of > relative paths to the data dir. Hack removed. -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] pg_ctl using START with paths needing quotes
This is a really ugly hack (I take the blame since I gave Bruce the idea). There are a few things to note: . the .bat file should probably be created in the data dir - that's about the only place that we should be guaranteed we can write. . the command should be preceded by '@' to suppress echoing . the whole command, including redirections should go inside the .bat file, so that pg_ctl just issues 'start /b foo.bat' There are still things to clean up in pg_ctl, e.g. its handling of relative paths to the data dir. cheers andrew Bruce Momjian wrote: This applied patch changes the way pg_ctl starts on Win32. Using START, it is not possible to quote the executable name, who's directory might have spaces: START /B /program files/x.exe The fix is to create a temporary batch file in C:\ containing: /program files/x.exe and run START with the batch name: START /B C:\PG_CTL_323223.BAT then unlink the batch file. ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
[PATCHES] pg_ctl using START with paths needing quotes
This applied patch changes the way pg_ctl starts on Win32. Using START, it is not possible to quote the executable name, who's directory might have spaces: START /B /program files/x.exe The fix is to create a temporary batch file in C:\ containing: /program files/x.exe and run START with the batch name: START /B C:\PG_CTL_323223.BAT then unlink the batch file. -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 Index: src/bin/pg_ctl/pg_ctl.c === RCS file: /cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.c,v retrieving revision 1.13 diff -c -c -r1.13 pg_ctl.c *** src/bin/pg_ctl/pg_ctl.c 10 Jun 2004 22:20:53 - 1.13 --- src/bin/pg_ctl/pg_ctl.c 11 Jun 2004 00:56:22 - *** *** 221,226 --- 221,261 * to pass everything to a shell to process them. */ charcmd[MAXPGPATH]; + int ret; + char*pgexec = postgres_path; + + #ifdef WIN32 + /* +* Win32 has a problem with the interaction between START and system(). +* There is no way to quote the executable name passed to START. +* Therefore, we put the executable name in a temporary batch file +* and run it via START. +*/ + chartmp[MAXPGPATH] = "C:\\PG_CTL_XX", /* good location? */ + bat[MAXPGPATH]; + int fd = mkstemp(tmp); + + if (fd == -1) + { + fprintf(stderr, _("%s: cannot create batch file %s to start server: %s\n"), + progname, tmp, strerror(errno)); + exit(1); + } + write(fd, postgres_path, strlen(postgres_path)); + write(fd, "\n", 1); + close(fd); + + strcpy(bat, tmp); + strcat(bat, ".BAT"); + pgexec = bat; + if (rename(tmp, bat) == -1) + { + fprintf(stderr, _("%s: cannot rename batch file %s to %s: %s\n"), + progname, tmp, bat, strerror(errno)); + unlink(tmp); + exit(1); + } + #endif if (log_file != NULL) /* Win32 needs START /B rather than "&" */ *** *** 229,235 #else snprintf(cmd, MAXPGPATH, "%sSTART /B \"%s\" %s < \"%s\" >> \"%s\" 2>&1%s", #endif !SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, log_file, SYSTEMQUOTE); else #ifndef WIN32 --- 264,270 #else snprintf(cmd, MAXPGPATH, "%sSTART /B \"%s\" %s < \"%s\" >> \"%s\" 2>&1%s", #endif !SYSTEMQUOTE, pgexec, post_opts, DEVNULL, log_file, SYSTEMQUOTE); else #ifndef WIN32 *** *** 237,244 #else snprintf(cmd, MAXPGPATH, "%sSTART /B \"%s\" %s < \"%s\" 2>&1%s", #endif !SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, SYSTEMQUOTE); ! return system(cmd); } --- 272,291 #else snprintf(cmd, MAXPGPATH, "%sSTART /B \"%s\" %s < \"%s\" 2>&1%s", #endif !SYSTEMQUOTE, pgexec, post_opts, DEVNULL, SYSTEMQUOTE); ! ! ret = system(cmd); ! ! #ifdef WIN32 ! /* We are unlinking it while it is running, but that should be OK */ ! if (unlink(bat)) ! { ! fprintf(stderr, _("%s: cannot remove batch file %s: %s\n"), ! progname, bat, strerror(errno)); ! exit(1); ! } ! #endif ! return ret; } ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org