~zorba-coders/zorba/process-module

« back to all changes in this revision

Viewing changes to src/com/zorba-xquery/www/modules/process.xq.src/process.cpp

  • Committer: Zorba Build Bot
  • Author(s): cezar.lp at cezarandrei
  • Date: 2012-12-06 02:13:28 UTC
  • mfrom: (31.1.4 process)
  • Revision ID: chillery+buildbot@lambda.nu-20121206021328-d8zvg8hgvibioj27
Tags: zorba-2.8, zorba-2.9
Fix for bug 1086323, align Fedora and Ubuntu when process module executes a command that crashes. Approved: Paul J. Lucas, Chris Hillery, Sorin Marian Nasoi

Show diffs side-by-side

added added

removed removed

Lines of Context:
257
257
  };
258
258
  
259
259
  //start child process
260
 
  BOOL ok=create_child_process(lStdOut,lStdErr,aCommand,lChildProcessInfo);
 
260
  BOOL ok = create_child_process(lStdOut,lStdErr,aCommand,lChildProcessInfo);
261
261
  if(ok==TRUE)
262
262
  {
263
263
 
413
413
  std::ostringstream lStderr;
414
414
 
415
415
#ifdef WIN32
416
 
  std::string lCommandLineString=lTmp.str();
417
 
  int code = run_process(lCommandLineString,lStdout,lStderr);
 
416
  std::string lCommandLineString = lTmp.str();
 
417
  int code = run_process(lCommandLineString, lStdout, lStderr);
418
418
  
419
419
  if (code != 0)
420
420
  {
424
424
      "http://www.zorba-xquery.com/modules/process", "PROC01");
425
425
    throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());
426
426
  }
 
427
  exit_code = code;
427
428
 
428
429
#else //not WIN32
429
430
 
470
471
 
471
472
    int  stat = 0;
472
473
    
473
 
    waitpid(pid, &stat, 0);
474
 
    /*pid_t w;
475
 
    do 
476
 
    {
477
 
      w = waitpid(pid, &stat, WUNTRACED | WCONTINUED);
478
 
      if (w == -1) 
479
 
      { 
480
 
          perror("waitpid"); 
481
 
          exit(EXIT_FAILURE); 
482
 
      }
 
474
    pid_t w = waitpid(pid, &stat, 0);
 
475
    
 
476
    if (w == -1) 
 
477
    { 
 
478
        std::stringstream lErrorMsg;
 
479
        lErrorMsg << "Failed to wait for child process ";
 
480
        Item lQName = ProcessModule::getItemFactory()->createQName(
 
481
          "http://www.zorba-xquery.com/modules/process", "PROC01");
 
482
        throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());          
 
483
    }
483
484
 
484
 
      if (WIFEXITED(stat)) 
485
 
      {
486
 
          printf("exited, status=%d\n", WEXITSTATUS(stat));
487
 
      } 
488
 
      else if (WIFSIGNALED(stat)) 
489
 
      {
490
 
          printf("killed by signal %d\n", WTERMSIG(stat));
491
 
      }
492
 
      else if (WIFSTOPPED(stat)) 
493
 
      {
494
 
          printf("stopped by signal %d\n", WSTOPSIG(stat));
495
 
      } 
496
 
      else if (WIFCONTINUED(stat)) 
497
 
      {
498
 
          printf("continued\n");
499
 
      }
500
 
    } while (!WIFEXITED(stat) && !WIFSIGNALED(stat));
501
 
    */
502
 
    exit_code = WEXITSTATUS(stat);
 
485
    if (WIFEXITED(stat)) 
 
486
    {
 
487
        //std::cout << " WEXITSTATUS : " << WEXITSTATUS(stat) << std::endl; std::cout.flush();
 
488
        exit_code = WEXITSTATUS(stat);
 
489
    } 
 
490
    else if (WIFSIGNALED(stat)) 
 
491
    {
 
492
        //std::cout << " WTERMSIG : " << WTERMSIG(stat) << std::endl; std::cout.flush();
 
493
        exit_code = 128 + WTERMSIG(stat);
 
494
    }
 
495
    else if (WIFSTOPPED(stat)) 
 
496
    {
 
497
        //std::cout << " STOPSIG : " << WSTOPSIG(stat) << std::endl; std::cout.flush();
 
498
        exit_code = 128 + WSTOPSIG(stat);
 
499
    }
 
500
    else
 
501
    {
 
502
        //std::cout << " else : " << std::endl; std::cout.flush();
 
503
        exit_code = 255;
 
504
    }
 
505
    
 
506
    //std::cout << " exit_code : " << exit_code << std::endl; std::cout.flush();
503
507
 
504
508
  }
505
509
#endif // WIN32