Re: exit status
| From: | Sascha Schumann | Date: | Thu, 13 May 1999 17:05:35 +0000 |
| Subject: | Re: exit status | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-5602@lists.php.net to get a copy of this message | ||
On Thu, May 13, 1999 at 07:51:04PM +0300, Zeev Suraski wrote:
> On Thu, 13 May 1999, Sascha Schumann wrote:
>
> > Hello all,
> >
> > once upon the time:
> >
> > -----------
> > At 12:56 07/10/98 -0700, Sumbry][ <sumbry@ahnet.net> wrote:
> > >
> > >Greetings;
> > ...
> > >Now I figured by using the exit(1) command, that the PHP CGI would return
> > >an exit status of 1, but instead, all it does is prints the number 1 to
> > >the screen and dies.
> >
> > Zeev's answer:
> >
> > You can't. Since there's no meaning to the exit status of PHP right now,
> > though, we may add that in the future.
> > -----------
> >
> > I'm now in the need of the option to exit with a specific status (if you
> > wonder, it is for a mail handler).
> >
> > Is there any option to implement this now? If someone could point me at the
> > right place, I'll try it myself. Zeev's response looks like it is not
> > completely impossible to do.
>
> You mean for PHP 3? I guess we could make it so that the exit status of
> the CGI is 0, or what exit() was passed, converted to an integer. But it
> would still display that exit status.
I've attached a short diff which seems to do what I need. Does it look
reasonable?
--
Regards,
Sascha Schumann
Consultant
Index: language-parser.y =================================================================== RCS file: /repository/php3/language-parser.y,v retrieving revision 1.178 diff -u -r1.178 language-parser.y --- language-parser.y 1999/01/01 17:58:50 1.178 +++ language-parser.y 1999/05/13 16:04:43 @@ -51,6 +51,7 @@ #else extern char *phptext; extern int phpleng; +extern int wanted_exit_status; #define YY_TLS_VARS #endif #include "php.h" @@ -549,7 +550,7 @@ | OBJECT_CAST expr { if (GLOBAL(Execute)) { convert_to_object(&$2); $$ = $2; } } | EXIT { if (GLOBAL(Execute)) { php3_header(); GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } | EXIT '(' ')' { if (GLOBAL(Execute)) { php3_header(); GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } - | EXIT '(' expr ')' { if (GLOBAL(Execute)) { if (php3_header()) { convert_to_string(&$3); PUTS($3.value.str.val); pval_destructor(&$3 _INLINE_TLS); } GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } + | EXIT '(' expr ')' { if (GLOBAL(Execute)) { if (php3_header()) { convert_to_string(&$3); PUTS($3.value.str.val); pval_destructor(&$3 _INLINE_TLS); } GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; convert_to_long(&$3); wanted_exit_status = $3.value.lval; $$.type=IS_LONG; $$.value.lval=1; } } | '@' { $1.cs_data.error_reporting=GLOBAL(error_reporting); GLOBAL(error_reporting)=0; } expr { GLOBAL(error_reporting)=$1.cs_data.error_reporting; $$ = $3; } | '@' error { php3_error(E_ERROR,"@ operator may only be used on expressions"); } | scalar { if (GLOBAL(Execute)) $$ = $1; } Index: main.c =================================================================== RCS file: /repository/php3/main.c,v retrieving revision 1.496 diff -u -r1.496 main.c --- main.c 1999/03/07 15:49:15 1.496 +++ main.c 1999/05/13 16:04:45 @@ -105,6 +105,7 @@ int initialized; /* keep track of which resources were successfully initialized */ static int module_initialized = 0; char *php3_ini_path = NULL; +int wanted_exit_status = 0; int shutdown_requested; unsigned char header_is_being_sent; unsigned int max_execution_time = 0; @@ -2264,7 +2265,7 @@ tls_destroy(); } #endif - return 0; + exit(wanted_exit_status); } #endif /* FHTTPD */
Index: language-parser.y =================================================================== RCS file: /repository/php3/language-parser.y,v retrieving revision 1.178 diff -u -r1.178 language-parser.y --- language-parser.y 1999/01/01 17:58:50 1.178 +++ language-parser.y 1999/05/13 16:04:43 @@ -51,6 +51,7 @@ #else extern char *phptext; extern int phpleng; +extern int wanted_exit_status; #define YY_TLS_VARS #endif #include "php.h" @@ -549,7 +550,7 @@ | OBJECT_CAST expr { if (GLOBAL(Execute)) { convert_to_object(&$2); $$ = $2; } } | EXIT { if (GLOBAL(Execute)) { php3_header(); GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } | EXIT '(' ')' { if (GLOBAL(Execute)) { php3_header(); GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } - | EXIT '(' expr ')' { if (GLOBAL(Execute)) { if (php3_header()) { convert_to_string(&$3); PUTS($3.value.str.val); pval_destructor(&$3 _INLINE_TLS); } GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; $$.type=IS_LONG; $$.value.lval=1; } } + | EXIT '(' expr ')' { if (GLOBAL(Execute)) { if (php3_header()) { convert_to_string(&$3); PUTS($3.value.str.val); pval_destructor(&$3 _INLINE_TLS); } GLOBAL(shutdown_requested)=ABNORMAL_SHUTDOWN; convert_to_long(&$3); wanted_exit_status = $3.value.lval; $$.type=IS_LONG; $$.value.lval=1; } } | '@' { $1.cs_data.error_reporting=GLOBAL(error_reporting); GLOBAL(error_reporting)=0; } expr { GLOBAL(error_reporting)=$1.cs_data.error_reporting; $$ = $3; } | '@' error { php3_error(E_ERROR,"@ operator may only be used on expressions"); } | scalar { if (GLOBAL(Execute)) $$ = $1; } Index: main.c =================================================================== RCS file: /repository/php3/main.c,v retrieving revision 1.496 diff -u -r1.496 main.c --- main.c 1999/03/07 15:49:15 1.496 +++ main.c 1999/05/13 16:04:45 @@ -105,6 +105,7 @@ int initialized; /* keep track of which resources were successfully initialized */ static int module_initialized = 0; char *php3_ini_path = NULL; +int wanted_exit_status = 0; int shutdown_requested; unsigned char header_is_being_sent; unsigned int max_execution_time = 0; @@ -2264,7 +2265,7 @@ tls_destroy(); } #endif - return 0; + exit(wanted_exit_status); } #endif /* FHTTPD */