lib, src: remove errno global
Remove the errno global. It's a property on the process object now. Fixes #3095.
This commit is contained in:
parent
1762ba37ca
commit
12d0f0bd3a
@ -398,7 +398,9 @@ function setupChannel(target, channel) {
|
||||
var writeReq = channel.writeUtf8String(string, handle);
|
||||
|
||||
if (!writeReq) {
|
||||
var er = errnoException(errno, 'write', 'cannot write to IPC channel.');
|
||||
var er = errnoException(process._errno,
|
||||
'write',
|
||||
'cannot write to IPC channel.');
|
||||
this.emit('error', er);
|
||||
}
|
||||
|
||||
@ -710,7 +712,7 @@ function ChildProcess() {
|
||||
//
|
||||
// - spawn failures are reported with exitCode == -1
|
||||
//
|
||||
var err = (exitCode == -1) ? errnoException(errno, 'spawn') : null;
|
||||
var err = (exitCode == -1) ? errnoException(process._errno, 'spawn') : null;
|
||||
|
||||
if (signalCode) {
|
||||
self.signalCode = signalCode;
|
||||
@ -866,7 +868,7 @@ ChildProcess.prototype.spawn = function(options) {
|
||||
|
||||
this._handle.close();
|
||||
this._handle = null;
|
||||
throw errnoException(errno, 'spawn');
|
||||
throw errnoException(process._errno, 'spawn');
|
||||
}
|
||||
|
||||
this.pid = this._handle.pid;
|
||||
@ -951,14 +953,14 @@ ChildProcess.prototype.kill = function(sig) {
|
||||
/* Success. */
|
||||
this.killed = true;
|
||||
return true;
|
||||
} else if (errno == 'ESRCH') {
|
||||
} else if (process._errno == 'ESRCH') {
|
||||
/* Already dead. */
|
||||
} else if (errno == 'EINVAL' || errno == 'ENOSYS') {
|
||||
} else if (process._errno == 'EINVAL' || process._errno == 'ENOSYS') {
|
||||
/* The underlying platform doesn't support this signal. */
|
||||
throw errnoException(errno, 'kill');
|
||||
throw errnoException(process._errno, 'kill');
|
||||
} else {
|
||||
/* Other error, almost certainly EPERM. */
|
||||
this.emit('error', errnoException(errno, 'kill'));
|
||||
this.emit('error', errnoException(process._errno, 'kill'));
|
||||
}
|
||||
}
|
||||
|
||||
|
22
lib/dgram.js
22
lib/dgram.js
@ -190,7 +190,7 @@ Socket.prototype.bind = function(port, address, callback) {
|
||||
return; // handle has been closed in the mean time
|
||||
|
||||
if (self._handle.bind(ip, port || 0, /*flags=*/ 0)) {
|
||||
self.emit('error', errnoException(errno, 'bind'));
|
||||
self.emit('error', errnoException(process._errno, 'bind'));
|
||||
self._bindState = BIND_STATE_UNBOUND;
|
||||
// Todo: close?
|
||||
return;
|
||||
@ -274,7 +274,7 @@ Socket.prototype.send = function(buffer,
|
||||
}
|
||||
else {
|
||||
// don't emit as error, dgram_legacy.js compatibility
|
||||
var err = errnoException(errno, 'send');
|
||||
var err = errnoException(process._errno, 'send');
|
||||
process.nextTick(function() {
|
||||
callback(err);
|
||||
});
|
||||
@ -306,7 +306,7 @@ Socket.prototype.address = function() {
|
||||
|
||||
var address = this._handle.getsockname();
|
||||
if (!address)
|
||||
throw errnoException(errno, 'getsockname');
|
||||
throw errnoException(process._errno, 'getsockname');
|
||||
|
||||
return address;
|
||||
};
|
||||
@ -314,7 +314,7 @@ Socket.prototype.address = function() {
|
||||
|
||||
Socket.prototype.setBroadcast = function(arg) {
|
||||
if (this._handle.setBroadcast((arg) ? 1 : 0)) {
|
||||
throw errnoException(errno, 'setBroadcast');
|
||||
throw errnoException(process._errno, 'setBroadcast');
|
||||
}
|
||||
};
|
||||
|
||||
@ -325,7 +325,7 @@ Socket.prototype.setTTL = function(arg) {
|
||||
}
|
||||
|
||||
if (this._handle.setTTL(arg)) {
|
||||
throw errnoException(errno, 'setTTL');
|
||||
throw errnoException(process._errno, 'setTTL');
|
||||
}
|
||||
|
||||
return arg;
|
||||
@ -338,7 +338,7 @@ Socket.prototype.setMulticastTTL = function(arg) {
|
||||
}
|
||||
|
||||
if (this._handle.setMulticastTTL(arg)) {
|
||||
throw errnoException(errno, 'setMulticastTTL');
|
||||
throw errnoException(process._errno, 'setMulticastTTL');
|
||||
}
|
||||
|
||||
return arg;
|
||||
@ -349,7 +349,7 @@ Socket.prototype.setMulticastLoopback = function(arg) {
|
||||
arg = arg ? 1 : 0;
|
||||
|
||||
if (this._handle.setMulticastLoopback(arg)) {
|
||||
throw errnoException(errno, 'setMulticastLoopback');
|
||||
throw errnoException(process._errno, 'setMulticastLoopback');
|
||||
}
|
||||
|
||||
return arg; // 0.4 compatibility
|
||||
@ -365,7 +365,7 @@ Socket.prototype.addMembership = function(multicastAddress,
|
||||
}
|
||||
|
||||
if (this._handle.addMembership(multicastAddress, interfaceAddress)) {
|
||||
throw new errnoException(errno, 'addMembership');
|
||||
throw new errnoException(process._errno, 'addMembership');
|
||||
}
|
||||
};
|
||||
|
||||
@ -379,7 +379,7 @@ Socket.prototype.dropMembership = function(multicastAddress,
|
||||
}
|
||||
|
||||
if (this._handle.dropMembership(multicastAddress, interfaceAddress)) {
|
||||
throw new errnoException(errno, 'dropMembership');
|
||||
throw new errnoException(process._errno, 'dropMembership');
|
||||
}
|
||||
};
|
||||
|
||||
@ -402,7 +402,9 @@ Socket.prototype._stopReceiving = function() {
|
||||
|
||||
function onMessage(handle, slab, start, len, rinfo) {
|
||||
var self = handle.owner;
|
||||
if (!slab) return self.emit('error', errnoException(errno, 'recvmsg'));
|
||||
if (!slab) {
|
||||
return self.emit('error', errnoException(process._errno, 'recvmsg'));
|
||||
}
|
||||
rinfo.size = len; // compatibility
|
||||
self.emit('message', slab.slice(start, start + len), rinfo);
|
||||
}
|
||||
|
@ -121,14 +121,14 @@ exports.lookup = function(domain, family, callback) {
|
||||
callback(null, addresses[0], addresses[0].indexOf(':') >= 0 ? 6 : 4);
|
||||
}
|
||||
} else {
|
||||
callback(errnoException(errno, 'getaddrinfo'));
|
||||
callback(errnoException(process._errno, 'getaddrinfo'));
|
||||
}
|
||||
}
|
||||
|
||||
var wrap = cares.getaddrinfo(domain, family);
|
||||
|
||||
if (!wrap) {
|
||||
throw errnoException(errno, 'getaddrinfo');
|
||||
throw errnoException(process._errno, 'getaddrinfo');
|
||||
}
|
||||
|
||||
wrap.oncomplete = onanswer;
|
||||
@ -146,14 +146,14 @@ function resolver(bindingName) {
|
||||
if (!status) {
|
||||
callback(null, result);
|
||||
} else {
|
||||
callback(errnoException(errno, bindingName));
|
||||
callback(errnoException(process._errno, bindingName));
|
||||
}
|
||||
}
|
||||
|
||||
callback = makeAsync(callback);
|
||||
var wrap = binding(name, onanswer);
|
||||
if (!wrap) {
|
||||
throw errnoException(errno, bindingName);
|
||||
throw errnoException(process._errno, bindingName);
|
||||
}
|
||||
|
||||
callback.immediately = true;
|
||||
|
@ -978,7 +978,7 @@ function FSWatcher() {
|
||||
this._handle.onchange = function(status, event, filename) {
|
||||
if (status) {
|
||||
self._handle.close();
|
||||
self.emit('error', errnoException(errno, 'watch'));
|
||||
self.emit('error', errnoException(process._errno, 'watch'));
|
||||
} else {
|
||||
self.emit('change', event, filename);
|
||||
}
|
||||
@ -992,7 +992,7 @@ FSWatcher.prototype.start = function(filename, persistent) {
|
||||
|
||||
if (r) {
|
||||
this._handle.close();
|
||||
throw errnoException(errno, 'watch');
|
||||
throw errnoException(process._errno, 'watch');
|
||||
}
|
||||
};
|
||||
|
||||
|
34
lib/net.js
34
lib/net.js
@ -198,7 +198,7 @@ function onSocketFinish() {
|
||||
var shutdownReq = this._handle.shutdown();
|
||||
|
||||
if (!shutdownReq)
|
||||
return this._destroy(errnoException(errno, 'shutdown'));
|
||||
return this._destroy(errnoException(process._errno, 'shutdown'));
|
||||
|
||||
shutdownReq.oncomplete = afterShutdown;
|
||||
}
|
||||
@ -351,7 +351,7 @@ Socket.prototype._read = function(n, callback) {
|
||||
this._handle.reading = true;
|
||||
var r = this._handle.readStart();
|
||||
if (r)
|
||||
this._destroy(errnoException(errno, 'read'));
|
||||
this._destroy(errnoException(process._errno, 'read'));
|
||||
} else {
|
||||
debug('readStart already has been called.');
|
||||
}
|
||||
@ -453,7 +453,7 @@ function onread(buffer, offset, length) {
|
||||
timers.active(self);
|
||||
|
||||
var end = offset + length;
|
||||
debug('onread', global.errno, offset, length, end);
|
||||
debug('onread', process._errno, offset, length, end);
|
||||
|
||||
if (buffer) {
|
||||
debug('got data');
|
||||
@ -484,10 +484,10 @@ function onread(buffer, offset, length) {
|
||||
debug('readStop');
|
||||
var r = handle.readStop();
|
||||
if (r)
|
||||
self._destroy(errnoException(errno, 'read'));
|
||||
self._destroy(errnoException(process._errno, 'read'));
|
||||
}
|
||||
|
||||
} else if (errno == 'EOF') {
|
||||
} else if (process._errno == 'EOF') {
|
||||
debug('EOF');
|
||||
|
||||
if (self._readableState.length === 0)
|
||||
@ -503,9 +503,9 @@ function onread(buffer, offset, length) {
|
||||
// procedure. No need to wait for all the data to be consumed.
|
||||
self.emit('_socketEnd');
|
||||
} else {
|
||||
debug('error', errno);
|
||||
debug('error', process._errno);
|
||||
// Error
|
||||
self._destroy(errnoException(errno, 'read'));
|
||||
self._destroy(errnoException(process._errno, 'read'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -594,7 +594,7 @@ Socket.prototype._write = function(dataEncoding, cb) {
|
||||
var writeReq = createWriteReq(this._handle, data, enc);
|
||||
|
||||
if (!writeReq || typeof writeReq !== 'object')
|
||||
return this._destroy(errnoException(errno, 'write'), cb);
|
||||
return this._destroy(errnoException(process._errno, 'write'), cb);
|
||||
|
||||
writeReq.oncomplete = afterWrite;
|
||||
this._bytesDispatched += writeReq.bytes;
|
||||
@ -661,8 +661,8 @@ function afterWrite(status, handle, req) {
|
||||
}
|
||||
|
||||
if (status) {
|
||||
debug('write failure', errnoException(errno, 'write'));
|
||||
self._destroy(errnoException(errno, 'write'), req.cb);
|
||||
debug('write failure', errnoException(process._errno, 'write'));
|
||||
self._destroy(errnoException(process._errno, 'write'), req.cb);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -691,7 +691,7 @@ function connect(self, address, port, addressType, localAddress) {
|
||||
}
|
||||
|
||||
if (r) {
|
||||
self._destroy(errnoException(errno, 'bind'));
|
||||
self._destroy(errnoException(process._errno, 'bind'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -708,7 +708,7 @@ function connect(self, address, port, addressType, localAddress) {
|
||||
if (connectReq !== null) {
|
||||
connectReq.oncomplete = afterConnect;
|
||||
} else {
|
||||
self._destroy(errnoException(errno, 'connect'));
|
||||
self._destroy(errnoException(process._errno, 'connect'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -834,7 +834,7 @@ function afterConnect(status, handle, req, readable, writable) {
|
||||
|
||||
} else {
|
||||
self._connecting = false;
|
||||
self._destroy(errnoException(errno, 'connect'));
|
||||
self._destroy(errnoException(process._errno, 'connect'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -922,7 +922,7 @@ var createServerHandle = exports._createServerHandle =
|
||||
default:
|
||||
// Not a fd we can listen on. This will trigger an error.
|
||||
debug('listen invalid fd=' + fd + ' type=' + type);
|
||||
global.errno = 'EINVAL'; // hack, callers expect that errno is set
|
||||
process._errno = 'EINVAL'; // hack, callers expect that errno is set
|
||||
handle = null;
|
||||
break;
|
||||
}
|
||||
@ -969,7 +969,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
||||
debug('_listen2: create a handle');
|
||||
self._handle = createServerHandle(address, port, addressType, fd);
|
||||
if (!self._handle) {
|
||||
var error = errnoException(errno, 'listen');
|
||||
var error = errnoException(process._errno, 'listen');
|
||||
process.nextTick(function() {
|
||||
self.emit('error', error);
|
||||
});
|
||||
@ -988,7 +988,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
||||
r = self._handle.listen(backlog || 511);
|
||||
|
||||
if (r) {
|
||||
var ex = errnoException(errno, 'listen');
|
||||
var ex = errnoException(process._errno, 'listen');
|
||||
self._handle.close();
|
||||
self._handle = null;
|
||||
process.nextTick(function() {
|
||||
@ -1096,7 +1096,7 @@ function onconnection(clientHandle) {
|
||||
debug('onconnection');
|
||||
|
||||
if (!clientHandle) {
|
||||
self.emit('error', errnoException(errno, 'accept'));
|
||||
self.emit('error', errnoException(process._errno, 'accept'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ WriteStream.prototype._refreshSize = function() {
|
||||
var oldRows = this.rows;
|
||||
var winSize = this._handle.getWindowSize();
|
||||
if (!winSize) {
|
||||
this.emit('error', errnoException(errno, 'getWindowSize'));
|
||||
this.emit('error', errnoException(process._errno, 'getWindowSize'));
|
||||
return;
|
||||
}
|
||||
var newCols = winSize[0];
|
||||
|
@ -1046,17 +1046,17 @@ MakeCallback(const Handle<Object> object,
|
||||
void SetErrno(uv_err_t err) {
|
||||
HandleScope scope;
|
||||
|
||||
static Persistent<String> errno_symbol;
|
||||
if (errno_symbol.IsEmpty()) {
|
||||
errno_symbol = NODE_PSYMBOL("errno");
|
||||
errno_symbol = NODE_PSYMBOL("_errno");
|
||||
}
|
||||
|
||||
if (err.code == UV_UNKNOWN) {
|
||||
char errno_buf[100];
|
||||
snprintf(errno_buf, 100, "Unknown system errno %d", err.sys_errno_);
|
||||
Context::GetCurrent()->Global()->Set(errno_symbol, String::New(errno_buf));
|
||||
process->Set(errno_symbol, String::New(errno_buf));
|
||||
} else {
|
||||
Context::GetCurrent()->Global()->Set(errno_symbol,
|
||||
String::NewSymbol(uv_err_name(err)));
|
||||
process->Set(errno_symbol, String::NewSymbol(uv_err_name(err)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -708,7 +708,7 @@
|
||||
}
|
||||
|
||||
if (r) {
|
||||
throw errnoException(errno, 'kill');
|
||||
throw errnoException(process._errno, 'kill');
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -746,7 +746,7 @@
|
||||
var r = wrap.start(signum);
|
||||
if (r) {
|
||||
wrap.close();
|
||||
throw errnoException(errno, 'uv_signal_start');
|
||||
throw errnoException(process._errno, 'uv_signal_start');
|
||||
}
|
||||
|
||||
signalWraps[type] = wrap;
|
||||
|
@ -101,10 +101,6 @@ process.on('exit', function() {
|
||||
process,
|
||||
global];
|
||||
|
||||
if (global.errno) {
|
||||
knownGlobals.push(errno);
|
||||
}
|
||||
|
||||
if (global.gc) {
|
||||
knownGlobals.push(gc);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ if (process.argv[2] === 'child') {
|
||||
child.on('exit', function() {
|
||||
child._handle = {
|
||||
kill: function() {
|
||||
global.errno = 42;
|
||||
process._errno = 42;
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ assert.equal(0, r);
|
||||
// Should not be able to bind to the same port again
|
||||
var r = handle.bind('0.0.0.0', common.PORT);
|
||||
assert.equal(-1, r);
|
||||
console.log(errno);
|
||||
assert.equal(errno, 'EINVAL');
|
||||
console.log(process._errno);
|
||||
assert.equal(process._errno, 'EINVAL');
|
||||
|
||||
handle.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user