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:
Ben Noordhuis 2013-02-28 17:50:14 +01:00
parent 1762ba37ca
commit 12d0f0bd3a
11 changed files with 54 additions and 54 deletions

View File

@ -398,7 +398,9 @@ function setupChannel(target, channel) {
var writeReq = channel.writeUtf8String(string, handle); var writeReq = channel.writeUtf8String(string, handle);
if (!writeReq) { 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); this.emit('error', er);
} }
@ -710,7 +712,7 @@ function ChildProcess() {
// //
// - spawn failures are reported with exitCode == -1 // - 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) { if (signalCode) {
self.signalCode = signalCode; self.signalCode = signalCode;
@ -866,7 +868,7 @@ ChildProcess.prototype.spawn = function(options) {
this._handle.close(); this._handle.close();
this._handle = null; this._handle = null;
throw errnoException(errno, 'spawn'); throw errnoException(process._errno, 'spawn');
} }
this.pid = this._handle.pid; this.pid = this._handle.pid;
@ -951,14 +953,14 @@ ChildProcess.prototype.kill = function(sig) {
/* Success. */ /* Success. */
this.killed = true; this.killed = true;
return true; return true;
} else if (errno == 'ESRCH') { } else if (process._errno == 'ESRCH') {
/* Already dead. */ /* Already dead. */
} else if (errno == 'EINVAL' || errno == 'ENOSYS') { } else if (process._errno == 'EINVAL' || process._errno == 'ENOSYS') {
/* The underlying platform doesn't support this signal. */ /* The underlying platform doesn't support this signal. */
throw errnoException(errno, 'kill'); throw errnoException(process._errno, 'kill');
} else { } else {
/* Other error, almost certainly EPERM. */ /* Other error, almost certainly EPERM. */
this.emit('error', errnoException(errno, 'kill')); this.emit('error', errnoException(process._errno, 'kill'));
} }
} }

View File

@ -190,7 +190,7 @@ Socket.prototype.bind = function(port, address, callback) {
return; // handle has been closed in the mean time return; // handle has been closed in the mean time
if (self._handle.bind(ip, port || 0, /*flags=*/ 0)) { 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; self._bindState = BIND_STATE_UNBOUND;
// Todo: close? // Todo: close?
return; return;
@ -274,7 +274,7 @@ Socket.prototype.send = function(buffer,
} }
else { else {
// don't emit as error, dgram_legacy.js compatibility // don't emit as error, dgram_legacy.js compatibility
var err = errnoException(errno, 'send'); var err = errnoException(process._errno, 'send');
process.nextTick(function() { process.nextTick(function() {
callback(err); callback(err);
}); });
@ -306,7 +306,7 @@ Socket.prototype.address = function() {
var address = this._handle.getsockname(); var address = this._handle.getsockname();
if (!address) if (!address)
throw errnoException(errno, 'getsockname'); throw errnoException(process._errno, 'getsockname');
return address; return address;
}; };
@ -314,7 +314,7 @@ Socket.prototype.address = function() {
Socket.prototype.setBroadcast = function(arg) { Socket.prototype.setBroadcast = function(arg) {
if (this._handle.setBroadcast((arg) ? 1 : 0)) { 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)) { if (this._handle.setTTL(arg)) {
throw errnoException(errno, 'setTTL'); throw errnoException(process._errno, 'setTTL');
} }
return arg; return arg;
@ -338,7 +338,7 @@ Socket.prototype.setMulticastTTL = function(arg) {
} }
if (this._handle.setMulticastTTL(arg)) { if (this._handle.setMulticastTTL(arg)) {
throw errnoException(errno, 'setMulticastTTL'); throw errnoException(process._errno, 'setMulticastTTL');
} }
return arg; return arg;
@ -349,7 +349,7 @@ Socket.prototype.setMulticastLoopback = function(arg) {
arg = arg ? 1 : 0; arg = arg ? 1 : 0;
if (this._handle.setMulticastLoopback(arg)) { if (this._handle.setMulticastLoopback(arg)) {
throw errnoException(errno, 'setMulticastLoopback'); throw errnoException(process._errno, 'setMulticastLoopback');
} }
return arg; // 0.4 compatibility return arg; // 0.4 compatibility
@ -365,7 +365,7 @@ Socket.prototype.addMembership = function(multicastAddress,
} }
if (this._handle.addMembership(multicastAddress, interfaceAddress)) { 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)) { 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) { function onMessage(handle, slab, start, len, rinfo) {
var self = handle.owner; 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 rinfo.size = len; // compatibility
self.emit('message', slab.slice(start, start + len), rinfo); self.emit('message', slab.slice(start, start + len), rinfo);
} }

View File

@ -121,14 +121,14 @@ exports.lookup = function(domain, family, callback) {
callback(null, addresses[0], addresses[0].indexOf(':') >= 0 ? 6 : 4); callback(null, addresses[0], addresses[0].indexOf(':') >= 0 ? 6 : 4);
} }
} else { } else {
callback(errnoException(errno, 'getaddrinfo')); callback(errnoException(process._errno, 'getaddrinfo'));
} }
} }
var wrap = cares.getaddrinfo(domain, family); var wrap = cares.getaddrinfo(domain, family);
if (!wrap) { if (!wrap) {
throw errnoException(errno, 'getaddrinfo'); throw errnoException(process._errno, 'getaddrinfo');
} }
wrap.oncomplete = onanswer; wrap.oncomplete = onanswer;
@ -146,14 +146,14 @@ function resolver(bindingName) {
if (!status) { if (!status) {
callback(null, result); callback(null, result);
} else { } else {
callback(errnoException(errno, bindingName)); callback(errnoException(process._errno, bindingName));
} }
} }
callback = makeAsync(callback); callback = makeAsync(callback);
var wrap = binding(name, onanswer); var wrap = binding(name, onanswer);
if (!wrap) { if (!wrap) {
throw errnoException(errno, bindingName); throw errnoException(process._errno, bindingName);
} }
callback.immediately = true; callback.immediately = true;

View File

@ -978,7 +978,7 @@ function FSWatcher() {
this._handle.onchange = function(status, event, filename) { this._handle.onchange = function(status, event, filename) {
if (status) { if (status) {
self._handle.close(); self._handle.close();
self.emit('error', errnoException(errno, 'watch')); self.emit('error', errnoException(process._errno, 'watch'));
} else { } else {
self.emit('change', event, filename); self.emit('change', event, filename);
} }
@ -992,7 +992,7 @@ FSWatcher.prototype.start = function(filename, persistent) {
if (r) { if (r) {
this._handle.close(); this._handle.close();
throw errnoException(errno, 'watch'); throw errnoException(process._errno, 'watch');
} }
}; };

View File

@ -198,7 +198,7 @@ function onSocketFinish() {
var shutdownReq = this._handle.shutdown(); var shutdownReq = this._handle.shutdown();
if (!shutdownReq) if (!shutdownReq)
return this._destroy(errnoException(errno, 'shutdown')); return this._destroy(errnoException(process._errno, 'shutdown'));
shutdownReq.oncomplete = afterShutdown; shutdownReq.oncomplete = afterShutdown;
} }
@ -351,7 +351,7 @@ Socket.prototype._read = function(n, callback) {
this._handle.reading = true; this._handle.reading = true;
var r = this._handle.readStart(); var r = this._handle.readStart();
if (r) if (r)
this._destroy(errnoException(errno, 'read')); this._destroy(errnoException(process._errno, 'read'));
} else { } else {
debug('readStart already has been called.'); debug('readStart already has been called.');
} }
@ -453,7 +453,7 @@ function onread(buffer, offset, length) {
timers.active(self); timers.active(self);
var end = offset + length; var end = offset + length;
debug('onread', global.errno, offset, length, end); debug('onread', process._errno, offset, length, end);
if (buffer) { if (buffer) {
debug('got data'); debug('got data');
@ -484,10 +484,10 @@ function onread(buffer, offset, length) {
debug('readStop'); debug('readStop');
var r = handle.readStop(); var r = handle.readStop();
if (r) if (r)
self._destroy(errnoException(errno, 'read')); self._destroy(errnoException(process._errno, 'read'));
} }
} else if (errno == 'EOF') { } else if (process._errno == 'EOF') {
debug('EOF'); debug('EOF');
if (self._readableState.length === 0) 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. // procedure. No need to wait for all the data to be consumed.
self.emit('_socketEnd'); self.emit('_socketEnd');
} else { } else {
debug('error', errno); debug('error', process._errno);
// Error // 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); var writeReq = createWriteReq(this._handle, data, enc);
if (!writeReq || typeof writeReq !== 'object') if (!writeReq || typeof writeReq !== 'object')
return this._destroy(errnoException(errno, 'write'), cb); return this._destroy(errnoException(process._errno, 'write'), cb);
writeReq.oncomplete = afterWrite; writeReq.oncomplete = afterWrite;
this._bytesDispatched += writeReq.bytes; this._bytesDispatched += writeReq.bytes;
@ -661,8 +661,8 @@ function afterWrite(status, handle, req) {
} }
if (status) { if (status) {
debug('write failure', errnoException(errno, 'write')); debug('write failure', errnoException(process._errno, 'write'));
self._destroy(errnoException(errno, 'write'), req.cb); self._destroy(errnoException(process._errno, 'write'), req.cb);
return; return;
} }
@ -691,7 +691,7 @@ function connect(self, address, port, addressType, localAddress) {
} }
if (r) { if (r) {
self._destroy(errnoException(errno, 'bind')); self._destroy(errnoException(process._errno, 'bind'));
return; return;
} }
} }
@ -708,7 +708,7 @@ function connect(self, address, port, addressType, localAddress) {
if (connectReq !== null) { if (connectReq !== null) {
connectReq.oncomplete = afterConnect; connectReq.oncomplete = afterConnect;
} else { } else {
self._destroy(errnoException(errno, 'connect')); self._destroy(errnoException(process._errno, 'connect'));
} }
} }
@ -834,7 +834,7 @@ function afterConnect(status, handle, req, readable, writable) {
} else { } else {
self._connecting = false; self._connecting = false;
self._destroy(errnoException(errno, 'connect')); self._destroy(errnoException(process._errno, 'connect'));
} }
} }
@ -922,7 +922,7 @@ var createServerHandle = exports._createServerHandle =
default: default:
// Not a fd we can listen on. This will trigger an error. // Not a fd we can listen on. This will trigger an error.
debug('listen invalid fd=' + fd + ' type=' + type); 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; handle = null;
break; break;
} }
@ -969,7 +969,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
debug('_listen2: create a handle'); debug('_listen2: create a handle');
self._handle = createServerHandle(address, port, addressType, fd); self._handle = createServerHandle(address, port, addressType, fd);
if (!self._handle) { if (!self._handle) {
var error = errnoException(errno, 'listen'); var error = errnoException(process._errno, 'listen');
process.nextTick(function() { process.nextTick(function() {
self.emit('error', error); self.emit('error', error);
}); });
@ -988,7 +988,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
r = self._handle.listen(backlog || 511); r = self._handle.listen(backlog || 511);
if (r) { if (r) {
var ex = errnoException(errno, 'listen'); var ex = errnoException(process._errno, 'listen');
self._handle.close(); self._handle.close();
self._handle = null; self._handle = null;
process.nextTick(function() { process.nextTick(function() {
@ -1096,7 +1096,7 @@ function onconnection(clientHandle) {
debug('onconnection'); debug('onconnection');
if (!clientHandle) { if (!clientHandle) {
self.emit('error', errnoException(errno, 'accept')); self.emit('error', errnoException(process._errno, 'accept'));
return; return;
} }

View File

@ -94,7 +94,7 @@ WriteStream.prototype._refreshSize = function() {
var oldRows = this.rows; var oldRows = this.rows;
var winSize = this._handle.getWindowSize(); var winSize = this._handle.getWindowSize();
if (!winSize) { if (!winSize) {
this.emit('error', errnoException(errno, 'getWindowSize')); this.emit('error', errnoException(process._errno, 'getWindowSize'));
return; return;
} }
var newCols = winSize[0]; var newCols = winSize[0];

View File

@ -1046,17 +1046,17 @@ MakeCallback(const Handle<Object> object,
void SetErrno(uv_err_t err) { void SetErrno(uv_err_t err) {
HandleScope scope; HandleScope scope;
static Persistent<String> errno_symbol;
if (errno_symbol.IsEmpty()) { if (errno_symbol.IsEmpty()) {
errno_symbol = NODE_PSYMBOL("errno"); errno_symbol = NODE_PSYMBOL("_errno");
} }
if (err.code == UV_UNKNOWN) { if (err.code == UV_UNKNOWN) {
char errno_buf[100]; char errno_buf[100];
snprintf(errno_buf, 100, "Unknown system errno %d", err.sys_errno_); 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 { } else {
Context::GetCurrent()->Global()->Set(errno_symbol, process->Set(errno_symbol, String::NewSymbol(uv_err_name(err)));
String::NewSymbol(uv_err_name(err)));
} }
} }

View File

@ -708,7 +708,7 @@
} }
if (r) { if (r) {
throw errnoException(errno, 'kill'); throw errnoException(process._errno, 'kill');
} }
return true; return true;
@ -746,7 +746,7 @@
var r = wrap.start(signum); var r = wrap.start(signum);
if (r) { if (r) {
wrap.close(); wrap.close();
throw errnoException(errno, 'uv_signal_start'); throw errnoException(process._errno, 'uv_signal_start');
} }
signalWraps[type] = wrap; signalWraps[type] = wrap;

View File

@ -101,10 +101,6 @@ process.on('exit', function() {
process, process,
global]; global];
if (global.errno) {
knownGlobals.push(errno);
}
if (global.gc) { if (global.gc) {
knownGlobals.push(gc); knownGlobals.push(gc);
} }

View File

@ -32,7 +32,7 @@ if (process.argv[2] === 'child') {
child.on('exit', function() { child.on('exit', function() {
child._handle = { child._handle = {
kill: function() { kill: function() {
global.errno = 42; process._errno = 42;
return -1; return -1;
} }
}; };

View File

@ -33,7 +33,7 @@ assert.equal(0, r);
// Should not be able to bind to the same port again // Should not be able to bind to the same port again
var r = handle.bind('0.0.0.0', common.PORT); var r = handle.bind('0.0.0.0', common.PORT);
assert.equal(-1, r); assert.equal(-1, r);
console.log(errno); console.log(process._errno);
assert.equal(errno, 'EINVAL'); assert.equal(process._errno, 'EINVAL');
handle.close(); handle.close();