diff --git a/deps/libeio/Changes b/deps/libeio/Changes index 78a34594be9..7cba947ea55 100644 --- a/deps/libeio/Changes +++ b/deps/libeio/Changes @@ -18,7 +18,9 @@ TODO: maybe add mincore support? available on at least darwin, solaris, linux, f - "outbundled" from IO::AIO. - eio_set_max_polltime did not properly convert time to ticks. - tentatively support darwin in sendfile. + - fix freebsd/darwin sendfile. - also use sendfile emulation for ENOTSUP and EOPNOTSUPP error codes. - add OS-independent EIO_MT_* and EIO_MS_* flag enums. + - add eio_statvfs/eio_fstatvfs. diff --git a/deps/libeio/eio.c b/deps/libeio/eio.c index 7d54ca97c9e..937c066a845 100644 --- a/deps/libeio/eio.c +++ b/deps/libeio/eio.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -82,7 +83,7 @@ # include /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ -# if __freebsd || defined __NetBSD__ || defined __OpenBSD__ +# if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ # define _DIRENT_HAVE_D_TYPE /* sigh */ # define D_INO(de) (de)->d_fileno # define D_NAMLEN(de) (de)->d_namlen @@ -108,7 +109,7 @@ #if HAVE_SENDFILE # if __linux # include -# elif __freebsd || defined __APPLE__ +# elif __FreeBSD__ || defined __APPLE__ # include # include # elif __hpux @@ -138,6 +139,11 @@ # define NAME_MAX 4096 #endif +/* used for readlink etc. */ +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + /* buffer size for various temporary buffers */ #define EIO_BUFSIZE 65536 @@ -911,7 +917,7 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) # if __linux res = sendfile (ofd, ifd, &offset, count); -# elif __freebsd +# elif __FreeBSD__ /* * Of course, the freebsd sendfile is a dire hack with no thoughts * wasted on making it similar to other I/O functions. @@ -920,8 +926,16 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) off_t sbytes; res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); - if (res < 0 && sbytes) - /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ + #if 0 /* according to the manpage, this is correct, but broken behaviour */ + /* freebsd' sendfile will return 0 on success */ + /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ + /* not on e.g. EIO or EPIPE - sounds broken */ + if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) + res = sbytes; + #endif + + /* according to source inspection, this is correct, and useful behaviour */ + if (sbytes) res = sbytes; } @@ -931,7 +945,8 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) off_t sbytes = count; res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); - if (res < 0 && errno == EAGAIN && sbytes) + /* according to the manpage, sbytes is always valid */ + if (sbytes) res = sbytes; } @@ -1577,6 +1592,11 @@ static void eio_execute (etp_worker *self, eio_req *req) case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; + case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = statvfs (req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; case EIO_CHMOD: req->result = chmod (req->ptr1, (mode_t)req->int2); break; @@ -1595,8 +1615,8 @@ static void eio_execute (etp_worker *self, eio_req *req) case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->int3); break; - case EIO_READLINK: ALLOC (NAME_MAX); - req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; + case EIO_READLINK: ALLOC (PATH_MAX); + req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; case EIO_SYNC: req->result = 0; sync (); break; case EIO_FSYNC: req->result = fsync (req->int1); break; @@ -1733,6 +1753,11 @@ eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) REQ (EIO_FSTAT); req->int1 = fd; SEND; } +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FSTATVFS); req->int1 = fd; SEND; +} + eio_req *eio_futime (int fd, double atime, double mtime, int pri, eio_cb cb, void *data) { REQ (EIO_FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; @@ -1814,6 +1839,11 @@ eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data) return eio__1path (EIO_LSTAT, path, pri, cb, data); } +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_STATVFS, path, pri, cb, data); +} + eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data) { return eio__1path (EIO_UNLINK, path, pri, cb, data); diff --git a/deps/libeio/eio.h b/deps/libeio/eio.h index 2008d8579b2..1a5dc3d3f9e 100644 --- a/deps/libeio/eio.h +++ b/deps/libeio/eio.h @@ -60,6 +60,10 @@ typedef int (*eio_cb)(eio_req *req); # define EIO_STRUCT_STAT struct stat #endif +#ifndef EIO_STRUCT_STATVFS +# define EIO_STRUCT_STATVFS struct statvfs +#endif + /* for readdir */ /* eio_readdir flags */ @@ -133,6 +137,7 @@ enum { EIO_READ, EIO_WRITE, EIO_READAHEAD, EIO_SENDFILE, EIO_STAT, EIO_LSTAT, EIO_FSTAT, + EIO_STATVFS, EIO_FSTATVFS, EIO_TRUNCATE, EIO_FTRUNCATE, EIO_UTIME, EIO_FUTIME, EIO_CHMOD, EIO_FCHMOD, @@ -239,6 +244,7 @@ eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data); @@ -257,6 +263,7 @@ eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); @@ -277,13 +284,14 @@ void eio_grp_cancel (eio_req *grp); /* cancels all sub requests but not the g /* request api */ /* true if the request was cancelled, useful in the invoke callback */ -#define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) +#define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) -#define EIO_RESULT(req) ((req)->result) +#define EIO_RESULT(req) ((req)->result) /* returns a pointer to the result buffer allocated by eio */ -#define EIO_BUF(req) ((req)->ptr2) -#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) -#define EIO_PATH(req) ((char *)(req)->ptr1) +#define EIO_BUF(req) ((req)->ptr2) +#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) +#define EIO_STATVFS_BUF(req) ((EIO_STRUCT_STATVFS *)EIO_BUF(req)) +#define EIO_PATH(req) ((char *)(req)->ptr1) /* submit a request for execution */ void eio_submit (eio_req *req); diff --git a/deps/libeio/libeio.m4 b/deps/libeio/libeio.m4 index e80e008174d..0a737d36d7e 100644 --- a/deps/libeio/libeio.m4 +++ b/deps/libeio/libeio.m4 @@ -64,7 +64,7 @@ AC_CACHE_CHECK(for sendfile, ac_cv_sendfile, [AC_LINK_IFELSE([ # include #if __linux # include -#elif __freebsd || defined __APPLE__ +#elif __FreeBSD__ || defined __APPLE__ # include # include #elif __hpux @@ -80,7 +80,7 @@ int main(void) ssize_t res; #if __linux res = sendfile (fd, fd, offset, count); -#elif __freebsd +#elif __FreeBSD__ res = sendfile (fd, fd, offset, count, 0, &offset, 0); #elif __hpux res = sendfile (fd, fd, offset, count, 0, 0); diff --git a/deps/libeio/wscript b/deps/libeio/wscript index 2c49f71f28b..e6146ec7f1b 100644 --- a/deps/libeio/wscript +++ b/deps/libeio/wscript @@ -67,7 +67,7 @@ def configure(conf): # include #if __linux # include - #elif __freebsd + #elif __FreeBSD__ || defined(__APPLE__) # include # include #elif __hpux @@ -83,8 +83,10 @@ def configure(conf): ssize_t res; #if __linux res = sendfile (fd, fd, offset, count); - #elif __freebsd + #elif __FreeBSD__ res = sendfile (fd, fd, offset, count, 0, &offset, 0); + #elif __APPLE__ + res = sendfile (fd, fd, offset, &offset, 0, 0); #elif __hpux res = sendfile (fd, fd, offset, count, 0, 0); #endif diff --git a/doc/api.txt b/doc/api.txt index c745bc8716d..516396888b4 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -154,22 +154,10 @@ Send a signal to a process. +pid+ is the process id and +signal+ is the signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more information. -+process.compile(source, scriptOrigin)+:: -Just like +eval()+ except that you can specify a +scriptOrigin+ for better -error reporting. ++process.compile(code, scriptOrigin)+:: +Similar to +eval()+ except that you can specify a +scriptOrigin+ for better +error reporting and the +code+ cannot see the local scope. -+process.mixin([deep], target, object1, [objectN])+ :: -Extend one object with one or more others, returning the modified object. -If no target is specified, the +GLOBAL+ namespace itself is extended. -Keep in mind that the target object will be modified, and will be returned -from +process.mixin()+. -+ -If a boolean true is specified as the first argument, Node performs a deep -copy, recursively copying any objects it finds. Otherwise, the copy will -share structure with the original object(s). -+ -Undefined properties are not copied. However, properties inherited from the -object's prototype will be copied over. == System module diff --git a/lib/fs.js b/lib/fs.js index 28e52bd293d..f9eae9bd39a 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1,6 +1,8 @@ var sys = require('./sys'), events = require('events'); +var fs = exports; + exports.Stats = process.Stats; process.Stats.prototype._checkModeProperty = function (property) { diff --git a/lib/ini.js b/lib/ini.js index 6a1b18daa86..bc1938733b4 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -1,22 +1,25 @@ exports.parse = function(d) { - var trim = function(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } var ini = {'-':{}}; var section = '-'; var lines = d.split('\n'); for (var i=0; i Loop(const Arguments& args) { } static Handle Unloop(const Arguments& args) { - fprintf(stderr, "Node.js Depreciation: Don't use process.unloop(). It will be removed soon.\n"); + fprintf(stderr, "Deprecation: Don't use process.unloop(). It will be removed soon.\n"); HandleScope scope; int how = EVUNLOOP_ONE; if (args[0]->IsString()) { @@ -610,6 +610,7 @@ int getmem(size_t *rss, size_t *vsize) { struct kinfo_proc *kinfo = NULL; pid_t pid; int nprocs; + size_t page_size = getpagesize(); pid = getpid(); @@ -619,7 +620,7 @@ int getmem(size_t *rss, size_t *vsize) { kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs); if (kinfo == NULL) goto error; - *rss = kinfo->ki_rssize * PAGE_SIZE; + *rss = kinfo->ki_rssize * page_size; *vsize = kinfo->ki_size; kvm_close(kd); @@ -858,6 +859,53 @@ Handle DLOpen(const v8::Arguments& args) { return Undefined(); } +// evalcx(code, sandbox={}) +// Executes code in a new context +Handle EvalCX(const Arguments& args) { + HandleScope scope; + + Local code = args[0]->ToString(); + Local sandbox = args.Length() > 1 ? args[1]->ToObject() + : Object::New(); + // Create the new context + Persistent context = Context::New(); + + // Copy objects from global context, to our brand new context + Handle keys = sandbox->GetPropertyNames(); + + int i; + for (i = 0; i < keys->Length(); i++) { + Handle key = keys->Get(Integer::New(i))->ToString(); + Handle value = sandbox->Get(key); + context->Global()->Set(key, value->ToObject()->Clone()); + } + + // Enter and compile script + context->Enter(); + + // Catch errors + TryCatch try_catch; + + Local