Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

lib, src: remove errno global #4874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}

Expand Down
22 changes: 12 additions & 10 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -306,15 +306,15 @@ Socket.prototype.address = function() {

var address = this._handle.getsockname();
if (!address)
throw errnoException(errno, 'getsockname');
throw errnoException(process._errno, 'getsockname');

return address;
};


Socket.prototype.setBroadcast = function(arg) {
if (this._handle.setBroadcast((arg) ? 1 : 0)) {
throw errnoException(errno, 'setBroadcast');
throw errnoException(process._errno, 'setBroadcast');
}
};

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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');
}
};

Expand All @@ -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');
}
};

Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -992,7 +992,7 @@ FSWatcher.prototype.start = function(filename, persistent) {

if (r) {
this._handle.close();
throw errnoException(errno, 'watch');
throw errnoException(process._errno, 'watch');
}
};

Expand Down
34 changes: 17 additions & 17 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
Expand All @@ -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'));
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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'));
}
}

Expand Down Expand Up @@ -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'));
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
});
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@
}

if (r) {
throw errnoException(errno, 'kill');
throw errnoException(process._errno, 'kill');
}

return true;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ process.on('exit', function() {
process,
global];

if (global.errno) {
knownGlobals.push(errno);
}

if (global.gc) {
knownGlobals.push(gc);
}
Expand Down
2 changes: 1 addition & 1 deletion test/simple/test-child-process-kill-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
Loading