Permalink
Browse files

process, bugfix: process.wait not return while process is already exit.

  • Loading branch information...
xicilion committed Nov 14, 2017
1 parent 1973754 commit 89454b908a392a70a41d27a88fa5109849d41f2d
@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <exlib/include/thread.h>
#include "options.h"
#include <sys/wait.h>
namespace fibjs {
@@ -669,6 +670,11 @@ result_t AsyncIO::waitpid(intptr_t pid, int32_t& retVal, AsyncEvent* ac)
{
ev_child_init(&cw, child_cb, m_pid, 0);
ev_child_start(s_loop, &cw);
cw.rstatus = 0;
pid_t pid1 = ::waitpid(m_pid, &cw.rstatus, WNOHANG);
if (pid1 == -1 || pid1 == m_pid)
child_cb(s_loop, &cw, 0);
}
private:
@@ -153,11 +153,11 @@ result_t SubProcess::create(exlib::string command, v8::Local<v8::Array> args, v8
#ifdef Linux
if (err == 0) {
int32_t status = 0;
waitpid(pid, &status, WNOHANG);
pid_t pid1 = waitpid(pid, &status, WNOHANG);
if (WIFEXITED(status))
status = WEXITSTATUS(status);
if (status == 127)
if (pid1 == -1 || status == 127)
err = 2;
}
#endif
View
@@ -1 +1,2 @@
process.exitCode = 1;
console.log(console.readLine());
View
@@ -1,4 +1,5 @@
setInterval(function() {
process.exitCode = 10;
setInterval(function () {
console.log(400);
this.clear();
}, 100);
}, 100);
View
@@ -1,3 +1,4 @@
process.exitCode = 11;
setImmediate(() => {
console.log(500);
});
});
View
@@ -1,7 +1,8 @@
var coroutine = require('coroutine')
process.exitCode = 12;
setTimeout(() => {
coroutine.start(() => {
console.log(600);
});
}, 10);
}, 10);
View
@@ -1,4 +1,5 @@
var process = require('process');
var json = require('json');
console.log(json.encode(process.argv));
console.log(json.encode(process.argv));
process.exitCode = 2;
View
@@ -1,4 +1,5 @@
var process = require('process');
var json = require('json');
console.log(json.encode(process.execArgv));
console.log(json.encode(process.execArgv));
process.exitCode = 3;
View
@@ -1,4 +1,5 @@
var process = require('process');
var json = require('json');
console.log(json.encode(process.env));
console.log(json.encode(process.env));
process.exitCode = 4;
View
@@ -1,2 +1,3 @@
var coroutine = require("coroutine");
coroutine.sleep(10000);
coroutine.sleep(10000);
process.exitCode = 5;
View
@@ -1,6 +1,8 @@
var coroutine = require('coroutine');
process.exitCode = 7;
coroutine.start(() => {
coroutine.sleep(100);
console.log(100);
});
});
View
@@ -1,5 +1,6 @@
var coroutine = require('coroutine');
process.exitCode = 8;
coroutine.sleep(100, () => {
console.log(200);
});
});
View
@@ -1,3 +1,4 @@
process.exitCode = 9;
setTimeout(() => {
console.log(300);
}, 100);
}, 100);
View
@@ -74,37 +74,37 @@ describe('process', () => {
it("multi fiber", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec7.js')]);
assert.equal(p.readLine(), "100");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 7);
});
it("pendding async", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec8.js')]);
assert.equal(p.readLine(), "200");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 8);
});
it("setTimeout", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec9.js')]);
assert.equal(p.readLine(), "300");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 9);
});
it("setInterval", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec10.js')]);
assert.equal(p.readLine(), "400");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 10);
});
it("setImmediate", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec11.js')]);
assert.equal(p.readLine(), "500");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 11);
});
it("bugfix: multi fiber async", () => {
var p = process.open(cmd, [path.join(__dirname, 'process', 'exec12.js')]);
assert.equal(p.readLine(), "600");
assert.equal(p.wait(), 0);
assert.equal(p.wait(), 12);
});
it("start", () => {

0 comments on commit 89454b9

Please sign in to comment.