Re: pg_ctl using START with paths needing quotes

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: pg_ctl using START with paths needing quotes
Дата
Msg-id 40CA0FC3.5050207@dunslane.net
обсуждение исходный текст
Ответ на Re: pg_ctl using START with paths needing quotes  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-patches
Bruce Momjian wrote:

>Tom Lane wrote:
>
>
>>Andrew Dunstan <andrew@dunslane.net> 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

В списке pgsql-patches по дате отправления:

Предыдущее
От: Andreas Pflug
Дата:
Сообщение: Re: [HACKERS] serverlog function (log_destination file)
Следующее
От: Manfred Spraul
Дата:
Сообщение: Re: Compiling libpq with VisualC