Cezar Andrei has proposed merging 
lp:~zorba-coders/zorba/bug1086323-processExitCode into lp:zorba/process-module.

Commit message:
Fix for bug 1086323.

Requested reviews:
  Sorin Marian Nasoi (sorin.marian.nasoi)
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1086323 in Zorba: "Process module: exit code reporting is broken"
  https://bugs.launchpad.net/zorba/+bug/1086323

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug1086323-processExitCode/+merge/137966

Fix for bug 1086323.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug1086323-processExitCode/+merge/137966
Your team Zorba Coders is subscribed to branch lp:zorba/process-module.
=== modified file 'src/com/zorba-xquery/www/modules/process.xq'
--- src/com/zorba-xquery/www/modules/process.xq	2012-09-27 16:53:40 +0000
+++ src/com/zorba-xquery/www/modules/process.xq	2012-12-04 19:46:25 +0000
@@ -56,6 +56,11 @@
  : @return the result of the execution as an element as
  :         shown in the documentation of this module. The exit-code
  :         element returns the exit code of the child process.
+ : For POSIX compliant platforms: returns the process exit code. If process is 
+ : terminated: (-1000) - termination signal code. If process is stoped:
+ : (-2000) - stop signal code or -1999 othewise.
+ : For Windows platforms: returns the return value of the process or the exit 
+ : or terminate process specified value.
  :
  : @error process:PROC01 if an error occurred while communicating 
  :   with the executed process.
@@ -75,6 +80,11 @@
  : @return the result of the execution as an element as
  :         shown in the documentation of this module. The exit-code
  :         element returns the exit code of the child process.
+ : For POSIX compliant platforms: returns the process exit code. If process is 
+ : terminated: (-1000) - termination signal code. If process is stoped:
+ : (-2000) - stop signal code or -1999 othewise.
+ : For Windows platforms: returns the return value of the process or the exit 
+ : or terminate process specified value.
  :
  : @error process:PROC01 if an error occurred while communicating 
  :   with the executed process.

=== modified file 'src/com/zorba-xquery/www/modules/process.xq.src/process.cpp'
--- src/com/zorba-xquery/www/modules/process.xq.src/process.cpp	2012-07-21 01:09:37 +0000
+++ src/com/zorba-xquery/www/modules/process.xq.src/process.cpp	2012-12-04 19:46:25 +0000
@@ -257,7 +257,7 @@
   };
   
   //start child process
-  BOOL ok=create_child_process(lStdOut,lStdErr,aCommand,lChildProcessInfo);
+  BOOL ok = create_child_process(lStdOut,lStdErr,aCommand,lChildProcessInfo);
   if(ok==TRUE)
   {
 
@@ -424,6 +424,7 @@
       "http://www.zorba-xquery.com/modules/process";, "PROC01");
     throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());
   }
+  exit_code = code;
 
 #else //not WIN32
 
@@ -470,36 +471,33 @@
 
     int  stat = 0;
     
-    waitpid(pid, &stat, 0);
-    /*pid_t w;
-    do 
-    {
-      w = waitpid(pid, &stat, WUNTRACED | WCONTINUED);
-      if (w == -1) 
-      { 
-          perror("waitpid"); 
-          exit(EXIT_FAILURE); 
-      }
+    pid_t w = waitpid(pid, &stat, 0);
+    
+    if (w == -1) 
+    { 
+        std::stringstream lErrorMsg;
+        lErrorMsg << "Failed to wait for child process ";
+        Item lQName = ProcessModule::getItemFactory()->createQName(
+          "http://www.zorba-xquery.com/modules/process";, "PROC01");
+        throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());          
+    }
 
-      if (WIFEXITED(stat)) 
-      {
-          printf("exited, status=%d\n", WEXITSTATUS(stat));
-      } 
-      else if (WIFSIGNALED(stat)) 
-      {
-          printf("killed by signal %d\n", WTERMSIG(stat));
-      }
-      else if (WIFSTOPPED(stat)) 
-      {
-          printf("stopped by signal %d\n", WSTOPSIG(stat));
-      } 
-      else if (WIFCONTINUED(stat)) 
-      {
-          printf("continued\n");
-      }
-    } while (!WIFEXITED(stat) && !WIFSIGNALED(stat));
-    */
-    exit_code = WEXITSTATUS(stat);
+    if (WIFEXITED(stat)) 
+    {
+        exit_code = WEXITSTATUS(stat);
+    } 
+    else if (WIFSIGNALED(stat)) 
+    {
+        exit_code = -1000 - WTERMSIG(stat);
+    }
+    else if (WIFSTOPPED(stat)) 
+    {
+        exit_code = -2000 - WSTOPSIG(stat);
+    }
+    else
+    {
+        exit_code = -1999;
+    } 
 
   }
 #endif // WIN32

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to