Created
August 14, 2011 07:19
-
-
Save bentomas/1144663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Daemon.node: A node.JS addon that allows creating Unix/Linux Daemons in pure Javascript. | |
* | |
* Copyright 2010 (c) <arthur@norgic.com> | |
* Modified By: Pedro Teixeira 2010 | |
* Modified By: James Haliday 2010 | |
* Modified By: Charlie Robbins 2010 | |
* Modified By: Zak Taylor 2010 | |
* Modified By: Daniel Bartlett 2011 | |
* Modified By: Charlie Robbins 2011 | |
* | |
* Under MIT License. See LICENSE file. | |
* | |
*/ | |
#include <v8.h> | |
#include <node.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <pwd.h> | |
#define PID_MAXLEN 10 | |
using namespace v8; | |
using namespace node; | |
const char* ToCString(const v8::String::Utf8Value& value) { | |
return *value ? *value : "<string conversion failed>"; | |
} | |
// | |
// Go through special routines to become a daemon. | |
// if successful, returns daemon pid | |
// | |
static Handle<Value> Start(const Arguments& args) { | |
if (!args[0]->IsString()) | |
return Boolean::New(false); | |
String::Utf8Value cmdUtf8(args[0]->ToString()); | |
const char *cmd = ToCString(cmdUtf8); | |
execlp(cmd, NULL); | |
return Boolean::New(true); | |
} | |
// | |
// Initialize this add-on | |
// | |
extern "C" void init(Handle<Object> target) { | |
HandleScope scope; | |
NODE_SET_METHOD(target, "start", Start); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment