From 78e53a21f022e5948e8c393a74f8e37aa4d7251b Mon Sep 17 00:00:00 2001 From: indexzero Date: Sat, 5 Feb 2011 03:56:15 -0500 Subject: [PATCH] [minor] Small updates to 0.2.0 --- README.md | 6 +++--- lib/daemon.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d163c6c..174e11a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Starting a daemon is easy, just call daemon.start() and daemon.lock(). // Your awesome code here fs.open('somefile.log', 'w+', function (err, fd) { - daemon.daemonize(); + daemon.daemonize(fd); daemon.lock('/tmp/yourprogram.pid'); }); @@ -43,11 +43,11 @@ This library also exposes a higher level facility through javascript for startin // Your awesome code here - daemon.daemonize('somefile.log', '/tmp/yourprogram.pid', function (err, started) { + daemon.daemonize('somefile.log', '/tmp/yourprogram.pid', function (err, pid) { // We are now in the daemon process if (err) return sys.puts('Error starting daemon: ' + err); - sys.puts('Daemon started successfully'); + sys.puts('Daemon started successfully with pid: ' + pid); }); diff --git a/lib/daemon.js b/lib/daemon.js index 5f0ebc6..f7a8820 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -16,11 +16,19 @@ var fs = require('fs'), Object.keys(binding).forEach(function (k) { daemon[k] = binding[k] }); // -// function run (out, lock, callback) +// 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); + // + if (arguments.length === 1) { + return binding.daemonize(out); + } + fs.open(out, 'w+', function (err, fd) { if (err) return callback(err);