Permalink
Browse files

Node's global process object's pid property is not automatically updated

when the pid of the process changes.  This commit wraps calls to
binding.start() with a function that updates the process.pid to reflect
the pid of the newly forked child process.  With this change
'process.pid' in the child process will be the actual pid of the
child process, not that of the killed parent process.
  • Loading branch information...
1 parent eac4f7b commit b3ceb4c14f908bf1b02b719b72e817ac261b228c @egoldblum committed Apr 20, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 lib/daemon.js
View
@@ -16,17 +16,28 @@ var fs = require('fs'),
Object.keys(binding).forEach(function (k) { daemon[k] = binding[k] });
//
+// function start (fd)
+// Wrapper around C++ start code to update the pid property of the
+// global process js object.
+//
+daemon.start = function (fd) {
+ var pid = binding.start(fd);
+ process.pid = pid;
+ return pid;
+};
+
+//
// function daemonize ([out, lock, callback])
// Run is designed to encapsulate the basic daemon operation in a single async call.
// When the callback returns you are in the the child process.
//
daemon.daemonize = function (out, lock, callback) {
//
// If we only get one argument assume it's an fd and
- // simply return with the pid from binding.daemonize(fd);
+ // simply return with the pid from daemon.start(fd);
//
if (arguments.length === 1) {
- return binding.daemonize(out);
+ return daemon.start(out);
}
fs.open(out, 'a+', 0666, function (err, fd) {
@@ -67,4 +78,4 @@ daemon.kill = function (lock, callback) {
callback(ex);
}
});
-};
+};

0 comments on commit b3ceb4c

Please sign in to comment.