version 1.11, 2016/04/01 18:12:39 |
version 1.12, 2016/04/02 15:01:46 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.10 2003/05/07 04:00:30 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.11 2016/04/01 18:12:39 ohara Exp $ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
Line 17 static int sm_control_reset_pid(); |
|
Line 17 static int sm_control_reset_pid(); |
|
|
|
static void pid_extend(); |
static void pid_extend(); |
static int pid_lookup(pid_t pid); |
static int pid_lookup(pid_t pid); |
static int pid_registed(pid_t pid); |
static int pid_registered(pid_t pid); |
static void pid_regist(pid_t pid); |
static void pid_register(pid_t pid); |
static void pid_delete(pid_t pid); |
static void pid_delete(pid_t pid); |
static int pid_reset(pid_t pid); |
static int pid_reset(pid_t pid); |
static int pid_kill(pid_t pid); |
static int pid_kill(pid_t pid); |
static void pid_kill_all(); |
static void pid_kill_all(); |
|
|
|
#define IS_CMO_INT32(c) ((c) && ((c)->tag == CMO_INT32)) |
|
#define IS_CMO_STRING(c) ((c) && ((c)->tag == CMO_STRING)) |
|
#define IS_CMO_LIST(c) ((c) && ((c)->tag == CMO_LIST)) |
|
#define IS_CMO_LIST_LEN(c,n) (IS_CMO_LIST(c) && (list_length((c)) >= (n))) |
|
|
/* ultra loose data base. */ |
/* ultra loose data base. */ |
static struct { int (*func_ptr)(); char *key; } tbl_lfunc[] = { |
static struct { int (*func_ptr)(); char *key; } tbl_lfunc[] = { |
{lf_oxc_open, "spawn"}, |
{lf_oxc_open, "spawn"}, |
Line 140 static int pid_lookup(pid_t pid) |
|
Line 145 static int pid_lookup(pid_t pid) |
|
return -1; |
return -1; |
} |
} |
|
|
static int pid_registed(pid_t pid) |
static int pid_registered(pid_t pid) |
{ |
{ |
return pid_lookup(pid)+1; |
return pid_lookup(pid)+1; |
} |
} |
|
|
static void pid_regist(pid_t pid) |
static void pid_register(pid_t pid) |
{ |
{ |
if (pid_ptr >= pid_size) { |
if (pid_ptr >= pid_size) { |
pids_extend(); |
pids_extend(); |
Line 163 static void pid_delete(pid_t pid) |
|
Line 168 static void pid_delete(pid_t pid) |
|
|
|
static int pid_reset(pid_t pid) |
static int pid_reset(pid_t pid) |
{ |
{ |
if (pid_registed(pid)) { |
if (pid_registered(pid)) { |
kill(pid, SIGUSR1); |
kill(pid, SIGUSR1); |
return 1; |
return 1; |
} |
} |
Line 172 static int pid_reset(pid_t pid) |
|
Line 177 static int pid_reset(pid_t pid) |
|
|
|
static int pid_kill(pid_t pid) |
static int pid_kill(pid_t pid) |
{ |
{ |
if (pid_registed(pid)) { |
if (pid_registered(pid)) { |
kill(pid, SIGKILL); |
kill(pid, SIGKILL); |
pid_delete(pid); |
pid_delete(pid); |
return 1; |
return 1; |
Line 207 int lf_oxc_open() |
|
Line 212 int lf_oxc_open() |
|
return -1; |
return -1; |
} |
} |
|
|
int sm_control_spawn_typecheck(cmo_list *args, cmo_list *ports, cmo_int32 *port, cmo_string *sname) |
int sm_control_spawn_typecheck(cmo_list *args, int *portp, char **s) |
{ |
{ |
char *cmd = sname->s; |
cmo_int32 *port; |
|
cmo_string *name; |
|
|
return args->tag == CMO_LIST |
if( IS_CMO_LIST_LEN(args,2) ) { |
&& list_length(args) > 1 |
name = (cmo_string *)list_nth(args, 1); |
&& ports->tag == CMO_LIST |
args = (cmo_list *)list_first_cmo(args); |
&& list_length(ports) > 0 |
if( IS_CMO_STRING(name) && IS_CMO_LIST_LEN(args,1) ) { |
&& port->tag == CMO_INT32 |
port = (cmo_int32 *)list_first_cmo(args); |
&& sname->tag == CMO_STRING |
if( IS_CMO_INT32(port) && name->s && which(name->s, getenv("PATH")) != NULL) { |
&& cmd != NULL |
*portp = port->i; |
&& which(cmd, getenv("PATH")) != NULL; |
*s = name->s; |
|
return 1; |
|
} |
|
} |
|
} |
|
return 0; |
} |
} |
|
|
static int sm_control_spawn() |
static int sm_control_spawn() |
{ |
{ |
cmo_list *args = (cmo_list *)pop(); |
int port; |
cmo_list *ports = (cmo_list *)list_first_cmo(args); |
char *s; |
cmo_int32 *port = (cmo_int32 *)list_first_cmo(ports); |
pid_t pid; |
cmo_string *sname = (cmo_string *)list_nth(args, 1); |
cmo *args = pop(); |
pid_t pid; |
|
|
|
if (sm_control_spawn_typecheck(args, ports, port, sname)) { |
if (sm_control_spawn_typecheck((cmo_list *)args, &port, &s)) { |
pid = lf_oxc_open_main(sname->s, (short)port->i); |
pid = lf_oxc_open_main(s, (short)port); |
if (pid > 0) { |
if (pid > 0) { |
push((cmo *)new_cmo_int32(pid)); |
push((cmo *)new_cmo_int32(pid)); |
pid_regist(pid); |
pid_register(pid); |
ox_printf("oxc: spawns %s\n", sname->s); |
ox_printf("oxc: spawns %s\n", s); |
return pid; |
return pid; |
} |
} |
} |
} |
push_error(-1, (cmo *)args); |
push_error(-1, (cmo *)args); |
return 0; |
return 0; |
|
|
} |
} |
|
|
int sm_mathcap() |
int sm_mathcap() |