diff options
author | pixel <pixel> | 2008-07-16 09:38:03 +0000 |
---|---|---|
committer | pixel <pixel> | 2008-07-16 09:38:03 +0000 |
commit | 0ca7e7e67883af752430f5095d262424f71619d5 (patch) | |
tree | 027fbebb225cbdadcf273dc71af54401c2a37542 /src/lua-interface.cpp | |
parent | c9d2172efbc91b2709dd782a06c936d79e8e0802 (diff) |
Adding daemon mode.
Diffstat (limited to 'src/lua-interface.cpp')
-rw-r--r-- | src/lua-interface.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/lua-interface.cpp b/src/lua-interface.cpp index dc97f12..9da24d9 100644 --- a/src/lua-interface.cpp +++ b/src/lua-interface.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: lua-interface.cpp,v 1.4 2008-07-05 06:24:43 pixel Exp $ */ +/* $Id: lua-interface.cpp,v 1.5 2008-07-16 09:38:03 pixel Exp $ */ #define WIP @@ -377,6 +377,9 @@ struct option long_options[] = { {"hport", 1, NULL, 'h'}, {"tport", 1, NULL, 't'}, {"server_fname", 1, NULL, 'f'}, +#ifdef HAVE_FORK + {"daemonize", 1, NULL, 'z'}, +#endif {0, 0, NULL, 0 } }; @@ -489,6 +492,9 @@ void showhelp(bool longhelp = false) { " -p <hp> http port to bind to.\n" " -t <tp> telnet port to bind to.\n" " -f <fil> filename of http server to use (server.lua by default).\n" +#ifdef HAVE_FORK +" -z daemonize; incompatible with -i; use with -g.\n" +#endif " -h for a help page.\n" , argv[0]); @@ -518,7 +524,7 @@ class lua_interface_printer_t : public printer_t { (*log) << tmp; - return true; + return false; } private: Handle * log; @@ -612,7 +618,7 @@ static void * interactive_prompt(void * __L) { virtual int startup() throw (GeneralException) { char c; - bool strip = true, todo = false, write = false, builtin = false; + bool strip = true, todo = false, write = false, builtin = false, daemonize = false; char * file = 0, * output = 0, * compile = 0, * exec = 0; Lua * L = 0; String hport = "1500", tport = "1550"; @@ -624,7 +630,7 @@ virtual int startup() throw (GeneralException) { /* Let's start parsing options */ - while ((c = getopt_long(argc, argv, "Hhva:c:dile:bg:st:p:f:", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "Hhva:c:dile:bg:st:p:f:z", long_options, NULL)) != EOF) { switch (c) { case 'h': case 'H': @@ -673,6 +679,11 @@ virtual int startup() throw (GeneralException) { case 'f': server_fname = optarg; break; +#ifdef HAVE_FORK + case 'z': + daemonize = true; + break; +#endif case 0: if (!getopt_flag) { showhelp(); @@ -689,6 +700,11 @@ virtual int startup() throw (GeneralException) { throw Exit(-1); } } + + if (interactive && daemonize) { + printm(M_ERROR, "Can not use daemonize and interactive mode.\n"); + Exit(-1); + } if (interactive) L = start_full_lua(); @@ -743,6 +759,14 @@ virtual int startup() throw (GeneralException) { L->load(&command); } +#ifdef HAVE_FORK + if (daemonize) { + if (fork()) { + throw GeneralException("Going daemon..."); + } + } +#endif + if (server) { TaskMan::Init(); } @@ -751,7 +775,7 @@ virtual int startup() throw (GeneralException) { pthread_create(&interactive_thread, NULL, interactive_prompt, L->thread(true)); L->pop(); } - + if (server) { HttpServ * httpserv = new HttpServ(new Message("Welcome", "Welcome.", "start"), hport.to_int(), "Lua Interface"); new Form("LUACall", "luacallform", "Enter the function name to call", LUACall_Names, LUACall_Invites, LUACall_Defaults, LUACall_Lists, LUACall_Descs, 1, new LUACall(L)); |