Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80855ba

Browse files
committed
In pipe_read_line Windows code, loop to ensure we get a whole line
from the child process; fixes observed problems when the returnedversion number is '8.0.0' rather than '8.0.0rc1'. Magnus Hagander
1 parentda59a70 commit80855ba

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

‎src/port/exec.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/port/exec.c,v 1.33 2004/11/27 22:44:15 petere Exp $
12+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.34 2004/12/20 17:40:59 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -486,30 +486,45 @@ pipe_read_line(char *cmd, char *line, int maxsize)
486486
&si,
487487
&pi))
488488
{
489-
DWORDbytesread=0;
490-
491489
/* Successfully started the process */
490+
char*lineptr;
492491

493492
ZeroMemory(line,maxsize);
494493

495-
/* Let's see if we can read */
496-
if (WaitForSingleObject(childstdoutrddup,10000)!=WAIT_OBJECT_0)
494+
/* Try to read at least one line from the pipe */
495+
/* This may require more than one wait/read attempt */
496+
for (lineptr=line;lineptr<line+maxsize-1; )
497497
{
498-
/* Got timeout */
499-
CloseHandle(pi.hProcess);
500-
CloseHandle(pi.hThread);
501-
CloseHandle(childstdoutwr);
502-
CloseHandle(childstdoutrddup);
503-
returnNULL;
498+
DWORDbytesread=0;
499+
500+
/* Let's see if we can read */
501+
if (WaitForSingleObject(childstdoutrddup,10000)!=WAIT_OBJECT_0)
502+
break;/* Timeout, but perhaps we got a line already */
503+
504+
if (!ReadFile(childstdoutrddup,lineptr,maxsize-(lineptr-line),
505+
&bytesread,NULL))
506+
break;/* Error, but perhaps we got a line already */
507+
508+
lineptr+=strlen(lineptr);
509+
510+
if (!bytesread)
511+
break;/* EOF */
512+
513+
if (strchr(line,'\n'))
514+
break;/* One or more lines read */
504515
}
505516

506-
/* We try just once */
507-
if (ReadFile(childstdoutrddup,line,maxsize,&bytesread,NULL)&&
508-
bytesread>0)
517+
if (lineptr!=line)
509518
{
510-
/* So we read some data */
511-
intlen=strlen(line);
512-
retval=line;
519+
/* OK, we read some data */
520+
intlen;
521+
522+
/* If we got more than one line, cut off after the first \n */
523+
lineptr=strchr(line,'\n');
524+
if (lineptr)
525+
*(lineptr+1)='\0';
526+
527+
len=strlen(line);
513528

514529
/*
515530
* If EOL is \r\n, convert to just \n. Because stdout is a
@@ -531,6 +546,8 @@ pipe_read_line(char *cmd, char *line, int maxsize)
531546
*/
532547
if (len==0||line[len-1]!='\n')
533548
strcat(line,"\n");
549+
550+
retval=line;
534551
}
535552

536553
CloseHandle(pi.hProcess);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp