Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 208ae0c

Browse files
committed
When system() fails in Win32, report it as an exception, print the
exception value in hex, and give a URL where the value can be looked-up.
1 parent eeae929 commit 208ae0c

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.508 2007/01/16 13:28:56 alvherre Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.509 2007/01/22 18:31:51 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -2421,13 +2421,23 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
24212421
(errmsg("%s (PID %d) exited with exit code %d",
24222422
procname, pid, WEXITSTATUS(exitstatus))));
24232423
else if (WIFSIGNALED(exitstatus))
2424+
#ifndef WIN32
24242425
ereport(lev,
24252426

24262427
/*------
24272428
translator: %s is a noun phrase describing a child process, such as
24282429
"server process" */
24292430
(errmsg("%s (PID %d) was terminated by signal %d",
24302431
procname, pid, WTERMSIG(exitstatus))));
2432+
#else
2433+
ereport(lev,
2434+
2435+
/*------
2436+
translator: %s is a noun phrase describing a child process, such as
2437+
"server process" */
2438+
(errmsg("%s (PID %d) was terminated by exception %X\nSee http://source.winehq.org/source/include/ntstatus.h for a description\nof the hex value.",
2439+
procname, pid, WTERMSIG(exitstatus))));
2440+
#endif
24312441
else
24322442
ereport(lev,
24332443

src/include/port/win32.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.65 2007/01/11 02:42:31 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.66 2007/01/22 18:31:51 momjian Exp $ */
22

33
#if defined(_MSC_VER) || defined(__BORLANDC__)
44
#define WIN32_ONLY_COMPILER
@@ -115,16 +115,38 @@ int semop(int semId, struct sembuf * sops, int flag);
115115

116116
/*
117117
* Signal stuff
118-
* WIN32 doesn't have wait(), so the return value for children
119-
* is simply the return value specified by the child, without
120-
* any additional information on whether the child terminated
121-
* on its own or via a signal. These macros are also used
122-
* to interpret the return value of system().
118+
*
119+
* For WIN32, there is no wait() call so there are no wait() macros
120+
* to interpret the return value of system(). Instead, system()
121+
* return values < 0x100 are used for exit() termination, and higher
122+
* values are used to indicated non-exit() termination, which is
123+
* similar to a unix-style signal exit (think SIGSEGV ==
124+
* STATUS_ACCESS_VIOLATION). Return values are broken up into groups:
125+
*
126+
* http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
127+
*
128+
* NT_SUCCESS 0 - 0x3FFFFFFF
129+
* NT_INFORMATION 0x40000000 - 0x7FFFFFFF
130+
* NT_WARNING 0x80000000 - 0xBFFFFFFF
131+
* NT_ERROR 0xC0000000 - 0xFFFFFFFF
132+
*
133+
* Effectively, we don't care on the severity of the return value from
134+
* system(), we just need to know if it was because of exit() or generated
135+
* by the system, and it seems values >= 0x100 are system-generated.
136+
* See this URL for a list of WIN32 STATUS_* values:
137+
*
138+
* Wine (URL used in our error messages) -
139+
* http://source.winehq.org/source/include/ntstatus.h
140+
* Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
141+
* MS SDK - http://www.nologs.com/ntstatus.html
142+
*
143+
* Some day we might want to print descriptions for the most common
144+
* exceptions, rather than printing a URL.
123145
*/
124-
#define WEXITSTATUS(w) (w)
125-
#define WIFEXITED(w) (true)
126-
#define WIFSIGNALED(w) (false)
127-
#define WTERMSIG(w) (0)
146+
#define WIFEXITED(w) (((w) & 0xffffff00) == 0)
147+
#define WIFSIGNALED(w) (!WIFEXITED(w))
148+
#define WEXITSTATUS(w) (w)
149+
#define WTERMSIG(w) (w)
128150

129151
#define sigmask(sig) ( 1 << ((sig)-1) )
130152

src/port/exec.c

Lines changed: 6 additions & 1 deletion
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.44 2007/01/05 22:20:02 momjian Exp $
12+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.45 2007/01/22 18:31:51 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -582,8 +582,13 @@ pclose_check(FILE *stream)
582582
log_error(_("child process exited with exit code %d"),
583583
WEXITSTATUS(exitstatus));
584584
else if (WIFSIGNALED(exitstatus))
585+
#ifndef WIN32
585586
log_error(_("child process was terminated by signal %d"),
586587
WTERMSIG(exitstatus));
588+
#else
589+
log_error(_("child process was terminated by exception %X\nSee http://source.winehq.org/source/include/ntstatus.h for a description\nof the hex value."),
590+
WTERMSIG(exitstatus));
591+
#endif
587592
else
588593
log_error(_("child process exited with unrecognized status %d"),
589594
exitstatus);

0 commit comments

Comments
 (0)