From d0ad66826c76a180cc4c7fdd40115f9a017653ca Mon Sep 17 00:00:00 2001 From: cyan <> Date: Tue, 1 Jun 2010 19:55:43 +0000 Subject: [PATCH] * Create kill(), a global JS function for checking process validity (sending signal zero), sending other signals (including KILL), amongst others. DM, I assume this will need to be fixed up for Windows? --- src/sbbs3/js_global.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/sbbs3/js_global.c b/src/sbbs3/js_global.c index 6dd6b103aa..82740aa6b0 100644 --- a/src/sbbs3/js_global.c +++ b/src/sbbs3/js_global.c @@ -2,7 +2,11 @@ /* Synchronet JavaScript "global" object properties/methods for all servers */ +<<<<<<< js_global.c /* $Id$ */ +======= +/* $Id$ */ +>>>>>>> 1.258 /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * @@ -2792,6 +2796,31 @@ js_disksize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return(JS_TRUE); } +static JSBool +js_kill(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int32 pid=0; + int32 sig=0; + int ds; + jsrefcount rc; + + if(JSVAL_IS_VOID(argv[0])) + return(JS_TRUE); + + if(argc<2) /* Require two arguments here - is this correct handling? */ + return(JS_FALSE); + + /* Convert JS values to C integers.. */ + JS_ValueToInt32(cx,argv[0],&sig); + JS_ValueToInt32(cx,argv[1],&pid); + + rc=JS_SUSPENDREQUEST(cx); + ds=kill(sig, pid); + JS_RESUMEREQUEST(cx, rc); + JS_NewNumberValue(cx,ds,rval); + + return(JS_TRUE); +} static JSBool js_socket_select(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) @@ -3301,6 +3330,12 @@ static jsSyncMethodSpec js_global_functions[] = { "specify a <i>unit_size</i> of <tt>1024</tt> to return the total disk size in <i>kilobytes</i>.") ,314 }, + {"kill", js_kill, 2, JSTYPE_NUMBER, +JSDOCSTR("processid, signal") + ,JSDOCSTR("send a signal to a process, returns a value that should be " + "parsed via signal.js. Useful for checking procees ID validity.") + ,311 + }, {"socket_select", js_socket_select, 0, JSTYPE_ARRAY, JSDOCSTR("[array of socket objects or descriptors] [,timeout=<tt>0</tt>] [,write=<tt>false</tt>]") ,JSDOCSTR("checks an array of socket objects or descriptors for read or write ability (default is <i>read</i>), " "default timeout value is 0.0 seconds (immediate timeout), " -- GitLab