Skip to content
Snippets Groups Projects
Commit 9109c3e6 authored by rswindell's avatar rswindell
Browse files

Revert Cyan's mod (removing global kill() function), created system.check_pid()

and system.terminate_pid() methods - untested.
parent 63082ff9
Branches
Tags
No related merge requests found
......@@ -2792,34 +2792,6 @@ 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);
if (ds == -1)
ds = errno;
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)
{
......@@ -3328,13 +3300,6 @@ 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 system process, returns 0 on success, and "
"a non-zero errno value upon failure that is likely platform dependent."
" Useful for checking process ID validity (i.e., by sending signal 0.)")
,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), "
......
......@@ -1473,6 +1473,47 @@ js_chkname(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return(JS_TRUE);
}
static JSBool
js_chkpid(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
int32 pid=0;
jsrefcount rc;
*rval = JSVAL_FALSE;
if(argc<1)
return(JS_TRUE);
JS_ValueToInt32(cx,argv[0],&pid);
rc=JS_SUSPENDREQUEST(cx);
*rval = BOOLEAN_TO_JSVAL(check_pid(pid));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_killpid(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
int32 pid=0;
jsrefcount rc;
*rval = JSVAL_FALSE;
if(argc<1)
return(JS_TRUE);
JS_ValueToInt32(cx,argv[0],&pid);
rc=JS_SUSPENDREQUEST(cx);
*rval = BOOLEAN_TO_JSVAL(terminate_pid(pid));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static jsSyncMethodSpec js_system_functions[] = {
{"username", js_username, 1, JSTYPE_STRING, JSDOCSTR("number")
,JSDOCSTR("returns name of user in specified user record <i>number</i>, or empty string if not found")
......@@ -1571,6 +1612,16 @@ static jsSyncMethodSpec js_system_functions[] = {
"returns <i>true</i> if it is valid")
,315
},
{"check_pid", js_chkpid, 1, JSTYPE_BOOLEAN, JSDOCSTR("process-ID")
,JSDOCSTR("checks that the provided process ID is a valid executing process on the system, "
"returns <i>true</i> if it is valid")
,315
},
{"terminate_pid", js_killpid, 1, JSTYPE_BOOLEAN, JSDOCSTR("process-ID")
,JSDOCSTR("terminates executing process on the system with the specified process ID, "
"returns <i>true</i> on success")
,315
},
{0}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment