Commit Graph

123 Commits

Author SHA1 Message Date
Tobias Nießen
88aab45c92
os,vm: fix segfaults and CHECK failure
Fixes multiple possible segmentation faults in node_contextify.cc and
an assertion failure in node_os.cc

Fixes: https://github.com/nodejs/node/issues/12369
Fixes: https://github.com/nodejs/node/issues/12370
PR-URL: https://github.com/nodejs/node/pull/12371
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-04-14 23:02:45 +02:00
James M Snell
98e54b0bd4 meta: restore original copyright header
A prior io.js era commit inappropriately removed the
original copyright statements from the source. This
restores those in any files still remaining from that
edit.

Ref: https://github.com/nodejs/TSC/issues/174
Ref: https://github.com/nodejs/node/pull/10599
PR-URL: https://github.com/nodejs/node/pull/10155

Note: This PR was required, reviewed-by and approved
by the Node.js Foundation Legal Committee and the TSC.
There is no `Approved-By:` meta data.
2017-03-10 11:23:48 -08:00
Brian White
4e05952a8a
os: improve cpus() performance
PR-URL: https://github.com/nodejs/node/pull/11564
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
2017-03-02 15:31:21 -05:00
Brian White
efdc571a58
os: improve loadavg() performance
PR-URL: https://github.com/nodejs/node/pull/11516
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-02-25 20:53:56 -05:00
Alexey Orlenko
c8c79b937f src: add a missing space in node_os.cc
This commit makes a small stylistic fix adding a missing space in
GetOSType function in node_os.cc

PR-URL: https://github.com/nodejs/node/pull/10931
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-23 09:33:31 -08:00
jBarz
1c3c75dac2 os: fix os.release() for aix and add test
PR-URL: https://github.com/nodejs/node/pull/10245
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-27 14:01:49 -08:00
Juan Andres Andrango
13a204e5c3 src: fix typo in #endif comment
PR-URL: https://github.com/nodejs/node/pull/8989
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-10-10 08:31:44 -07:00
cjihrig
d6e56fd843 os: add userInfo() method
os.userInfo() calls libuv's uv_os_get_passwd() function. It returns
an object containing the current effective user's username, uid,
gid, shell, and home directory. On Windows, the uid and gid are
-1, and the shell is null.

Refs: https://github.com/nodejs/node/issues/5582
PR-URL: https://github.com/nodejs/node/pull/6104
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-12 17:21:29 -04:00
Michaël Zasso
a729208808 src: replace usage of deprecated Has
PR-URL: https://github.com/nodejs/node/pull/5159
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-03-03 20:35:20 -08:00
Martin Bark
028194b576 os: fix crash in GetInterfaceAddresses
If uv_interface_addresses() returns UV_ENOSYS then interfaces and count
are uninitialised. This can cause a segmentation fault inside
GetInterfaceAddresses when it tries to use the invalid interfaces[].
Fix the issue by returning from GetInterfaceAddresses on the UV_ENOSYS
error.

This issue was observed when using uCLibc-ng version 1.0.9 because
uv_interface_addresses() in deps/uv/src/unix/linux-core.c incorrectly
undefines HAVE_IFADDRS_H.

Signed-off-by: Martin Bark <martin@barkynet.com>
PR-URL: https://github.com/nodejs/node/pull/4272
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-01-04 15:04:16 +11:00
Michaël Zasso
4abc896a82 src: replace usage of v8::Handle with v8::Local
v8::Handle is deprecated: https://codereview.chromium.org/1224623004

PR-URL: https://github.com/nodejs/io.js/pull/2202
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-09-06 21:38:05 +10:00
cjihrig
6e78e5feaa os: add homedir()
os.homedir() calls libuv's uv_os_homedir() to retrieve the current
user's home directory.

PR-URL: https://github.com/nodejs/io.js/pull/1791
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2015-06-05 22:58:14 -04:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Bert Belder
09fe6fe153 win: suppress GetVersionEx deprecation warning
There is no other way to retrieve the Windows version. The stated reason
this API is deprecated is that applications are not supposed to check
whether the Windows it's running on is recent enough. But that's not
what we use it for.

PR-URL: https://github.com/iojs/io.js/pull/261
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-08 14:17:23 +01:00
Bert Belder
0ce7b912c4 win: use GetVersionExW instead of GetVersionExA
For consistency with the rest of the source code, use the wide-char
version of this API.

PR-URL: https://github.com/iojs/io.js/pull/261
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-08 14:17:23 +01:00
Ben Noordhuis
355b96b605 lib,src: make os.endianness() inlinable
Turn os.endianness() from a run-time function into a pure JS function.
Upsides: makes it a good candidate for inlining at the call site.
Downsides: none that I can think of.

PR-URL: https://github.com/node-forward/node/pull/55
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-11 12:02:27 +01:00
Ben Noordhuis
e13663d647 src: network interface names are UTF-8 encoded
Fixes a bug that was introduced in commit f674b09 when v8::String::New()
calls were replaced with calls to one-byte, two-byte and UTF-8 versions.
It turns out that for network interface names, using a one-byte encoding
can produce the wrong results on Windows.  Use UTF-8 instead.

Libuv on Windows correctly encodes non-ASCII characters in the interface
name as UTF-8.  On Unices however, the interface name is just a binary
string with no particular encoding; that's why on UNIX platforms, we
keep interpreting it as a one-byte string.

Fixes joyent/node#8633.

PR-URL: https://github.com/node-forward/node/pull/44
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2014-11-05 20:39:24 +01:00
Ben Noordhuis
d3c317e08a src: attach env directly to api functions
Attach the per-context execution environment directly to API functions.
Rationale:

 * Gets node one step closer to multi-isolate readiness.

 * Avoids multi-context confusion, e.g. when the caller and callee live
   in different contexts.

 * Avoids expensive calls to pthread_getspecific() on platforms where
   V8 does not know how to use the thread-local storage directly.
   (Linux, the BSDs.)

PR-URL: https://github.com/node-forward/node/pull/18
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-13 23:46:46 +04:00
Ben Noordhuis
97585b0d7a src: remove unnecessary HandleScopes
API callback functions don't need to create a v8::HandleScope instance
because V8 already creates one in the JS->C++ adapter frame.

PR-URL: https://github.com/node-forward/node/pull/16
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12 02:09:16 +04:00
Fedor Indutny
ce04c726a3 src: update to v8 3.24 APIs 2014-03-13 20:56:55 +04:00
Fedor Indutny
75adde07f9 src: remove node_isolate from source
fix #6899
2014-02-22 03:20:56 +04:00
Xidorn Quan
ae02992872 os: networkInterfaces include scopeid for ipv6 2014-02-18 10:10:30 -08:00
Keith M Wesolowski
76b98462e5 node: register modules from DSO constructors
Built-in modules should be automatically registered, replacing the
static module list.  Add-on modules should also be automatically
registered via DSO constructors.  This improves flexibility in adding
built-in modules and is also a prerequisite to pure-C addon modules.
2014-01-27 15:52:50 -08:00
Timothy J Fontaine
429b58701a Merge remote-tracking branch 'upstream/v0.10'
Conflicts:
	deps/uv/ChangeLog
	deps/uv/build.mk
	deps/uv/src/version.c
	deps/uv/test/test-ipc.c
	deps/v8/src/objects.cc
	src/node.cc
	src/node_os.cc
2014-01-13 14:56:12 -08:00
Timothy J Fontaine
8753bb3859 src: return empty set on ENOSYS for interfaces
If node was compiled with --no-ifaddrs to support older operating
systems, don't throw instead simply return an empty object

Fixes #6846
2014-01-12 10:04:21 -08:00
Fedor Indutny
2bc30f239b cpplint: disallow if one-liners 2013-10-17 00:34:19 +04:00
Ben Noordhuis
756b622295 src: add multi-context support
This commit makes it possible to use multiple V8 execution contexts
within a single event loop.  Put another way, handle and request wrap
objects now "remember" the context they belong to and switch back to
that context when the time comes to call into JS land.

This could have been done in a quick and hacky way by calling
v8::Object::GetCreationContext() on the wrap object right before
making a callback but that leaves a fairly wide margin for bugs.

Instead, we make the context explicit through a new Environment class
that encapsulates everything (or almost everything) that belongs to
the context.  Variables that used to be a static or a global are now
members of the aforementioned class.  An additional benefit is that
this approach should make it relatively straightforward to add full
isolate support in due course.

There is no JavaScript API yet but that will be added in the near
future.

This work was graciously sponsored by GitHub, Inc.
2013-09-06 05:51:42 +02:00
Ben Noordhuis
9ac75d1f06 src: remove pointless node_os.h header file
src/node_os.cc doesn't export anything that's used elsewhere. Remove it.
2013-08-26 15:15:43 +02:00
Ben Noordhuis
f674b09f40 src: use v8::String::NewFrom*() functions
* Change calls to String::New() and String::NewSymbol() to their
  respective one-byte, two-byte and UTF-8 counterparts.

* Add a FIXED_ONE_BYTE_STRING macro that takes a string literal and
  turns it into a v8::Local<v8::String>.

* Add helper functions that make v8::String::NewFromOneByte() easier to
  work with. Said function expects a `const uint8_t*` but almost every
  call site deals with `const char*` or `const unsigned char*`. Helps
  us avoid doing reinterpret_casts all over the place.

* Code that handles file system paths keeps using UTF-8 for backwards
  compatibility reasons. At least now the use of UTF-8 is explicit.

* Remove v8::String::NewSymbol() entirely. Almost all call sites were
  effectively minor de-optimizations. If you create a string only once,
  there is no point in making it a symbol. If you are create the same
  string repeatedly, it should probably be cached in a persistent
  handle.
2013-08-09 11:44:50 +02:00
Brian White
30701d6e74 os: add mac address to networkInterfaces() output 2013-08-01 12:47:05 +02:00
Fedor Indutny
8e29ce9f13 src: lint c++ code 2013-07-31 22:12:06 +04:00
Ben Noordhuis
71b3138925 src: remove unused import in src/node_os.cc 2013-07-30 21:32:45 +02:00
Ben Noordhuis
b8c04b921b Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/ChangeLog
	deps/uv/src/version.c
	deps/uv/src/win/fs.c
	src/node.cc
	src/node_crypto.cc
	src/node_os.cc
	src/node_version.h
2013-07-30 15:19:48 +02:00
Ben Noordhuis
e20811a628 src: os: use Number::New() for CPU info
The return values from uv_cpu_info() don't necessarily fit in a 32 bits
signed integer.

Fixes #5732.
2013-07-23 17:12:17 +02:00
Ben Noordhuis
ca9eb718fb src, lib: update after internal api change
Libuv now returns errors directly.  Make everything in src/ and lib/
follow suit.

The changes to lib/ are not strictly necessary but they remove the need
for the abominations that are process._errno and node::SetErrno().
2013-07-20 12:09:29 +02:00
Ben Noordhuis
110a9cd8db lib, src: upgrade after v8 api change
This is a big commit that touches just about every file in the src/
directory. The V8 API has changed in significant ways. The most
important changes are:

* Binding functions take a const v8::FunctionCallbackInfo<T>& argument
  rather than a const v8::Arguments& argument.

* Binding functions return void rather than v8::Handle<v8::Value>. The
  return value is returned with the args.GetReturnValue().Set() family
  of functions.

* v8::Persistent<T> no longer derives from v8::Handle<T> and no longer
  allows you to directly dereference the object that the persistent
  handle points to. This means that the common pattern of caching
  oft-used JS values in a persistent handle no longer quite works,
  you first need to reconstruct a v8::Local<T> from the persistent
  handle with the Local<T>::New(isolate, persistent) factory method.

A handful of (internal) convenience classes and functions have been
added to make dealing with the new API a little easier.

The most visible one is node::Cached<T>, which wraps a v8::Persistent<T>
with some template sugar. It can hold arbitrary types but so far it's
exclusively used for v8::Strings (which was by far the most commonly
cached handle type.)
2013-07-06 17:44:44 +02:00
Ben Noordhuis
ef0926ce42 os: use IsBigEndian() in GetEndianness() function 2013-05-30 00:13:04 +02:00
Ben Kelly
8a407f58b9 os: Include netmask in os.networkInterfaces()
re #3765 and #5432
fixes #4743
2013-05-08 17:04:29 -07:00
Ben Noordhuis
af1ed99ce2 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/ChangeLog
	deps/uv/src/version.c
	lib/http.js
	src/node_crypto.cc
	src/node_os.cc
	src/node_version.h
	test/simple/helper-debugger-repl.js
2013-04-29 14:08:51 +02:00
isaacs
c77747354c os: Fix uname() error handling on sunos
The uname function can return any non-negative int to indicate success.

Strange, but that's how it is documented.  This also fixes a similar
buffer overflow in the even more unlikely event that info.release is
> 255 characters, similar to how 78c5de5 did for info.sysname.
2013-04-22 11:00:52 -07:00
Ben Noordhuis
8e190bf6a1 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	src/node_os.cc
2013-04-18 12:14:30 +02:00
Ben Noordhuis
d58ee7e5c7 os: unbreak windows build
Windows doesn't have MAXHOSTNAMELEN. Introduced in afbadde.
2013-04-15 22:39:03 +02:00
Ben Noordhuis
afbaddecd3 os: handle 256 character hostnames
Fix a (rather academic) buffer overflow. MAXHOSTNAMELEN is 256 on most
platforms, which means the buffer wasn't big enough to hold the
trailing nul byte on a system with a maximum length hostname.
2013-04-15 21:13:29 +02:00
Ben Noordhuis
78c5de598b os: fix unlikely buffer overflow in os.type()
* Fix a buffer overflow that happens iff strlen(info.sysname) > 255.
* Check the return value of uname().
2013-04-15 20:57:14 +02:00
Trevor Norris
f65e14ed1d src: pass Isolate to all applicable api
Update the api to pass node_isolate to all supported methods.

Much thanks to Ben Noordhuis and his work in 51f6e6a.
2013-03-20 01:11:02 +01:00
Ben Noordhuis
51f6e6a9b3 src, test: downgrade to v8 3.14 api 2013-02-25 23:45:02 +01:00
Ben Noordhuis
7788a6bf85 src: pass node_isolate to Undefined() 2013-01-07 17:39:58 +01:00
Ben Noordhuis
109f73b2c0 src: pass node_isolate to True() and False() 2013-01-07 17:39:57 +01:00
Ben Noordhuis
6573fc3502 src: pass node_isolate to Integer::New 2013-01-07 17:39:57 +01:00
Bert Belder
03b00dcca9 os: throw when os.networkInterfaces() fails 2012-12-03 22:35:01 +01:00
Nathan Rajlich
5e4e87ade5 os: add os.endianness() function 2012-11-08 12:31:45 -08:00
Ben Noordhuis
ff4a9d381d core: use proper #include directives 2012-03-10 00:14:14 +01:00
Igor Zinkovsky
500c8f45f5 Remove platform files, and use uv platform api 2011-12-15 18:01:22 -08:00
Ben Noordhuis
cdcb1118c8 Remove stray NODE_MODULE() semi-colons. 2011-11-09 16:34:09 +01:00
Ryan Dahl
88af0c8635 Remove os.openOSHandle
Unused.
2011-10-19 16:28:58 -07:00
Fedor Indutny
4561d9e07b Don't check sign of loadavg
Fixes #1838
2011-10-07 01:32:54 -07:00
Fedor Indutny
698455384f use uv for memory and loadavg functions 2011-10-07 01:31:35 -07:00
Bert Belder
91ecfbcae8 Remove platform_win32_winsock 2011-08-02 18:38:34 +02:00
Ben Noordhuis
a7bdaabf60 Include "platform.h", not <platform.h> - conflicts with system headers
Fixes #1003.
2011-07-26 22:05:08 +02:00
Ryan Dahl
19e53512b8 os.getNetworkInterfaces() 2011-03-16 16:34:12 -07:00
Ryan Dahl
55048cdf79 Update copyright headers 2011-03-14 17:37:05 -07:00
Bert Belder
61af4207da Fix dns on windows 2011-02-07 15:30:17 -08:00
Bert Belder
0eb4c2157d Define winsock error numbers 2011-01-18 04:58:30 +01:00
Bert Belder
c99962e4cd Misc. cleanups
casts, unused vars, function ordering, /* within comment, etc.
2011-01-18 04:58:29 +01:00
Bert Belder
e0f47be9d0 Clean up the way windows headers are included
Plus make inclusion order a little more consistent in general
2011-01-18 04:58:11 +01:00
Ryan Dahl
9bcfc0745c Revert "Implement os.isWindows"
This reverts commit 9e31e0837e.

Use process.platform == 'win32'
2011-01-13 20:32:36 -08:00
Bert Belder
9e31e0837e Implement os.isWindows 2011-01-04 18:38:58 -08:00
Bert Belder
c3ffbf219c Fix the OS module for win32 2011-01-02 23:44:43 +01:00
Bert Belder
33118df8f9 Merge remote branch 'origin/master'
Conflicts:
	src/node_net.cc
	src/node_os.cc
2011-01-02 22:57:32 +01:00
Brian White
8275d7cd34 Fix Cygwin compatibility in the os module 2010-12-23 09:52:04 -08:00
Brian White
d75c338dd6 Add more functionality to the os module 2010-12-22 11:01:25 -08:00
Bert Belder
86518c3b11 Port GetHostName 2010-12-21 00:17:12 +01:00
Brian White
f1762ff815 Add os module and getHostname 2010-12-11 00:51:20 -08:00