version 1.4, 2000/11/28 04:52:05 |
version 1.5, 2000/11/28 18:11:42 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.3 2000/11/28 04:02:56 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.4 2000/11/28 04:52:05 ohara Exp $ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <string.h> |
#include <string.h> |
|
#include <sys/types.h> |
#include <signal.h> |
#include <signal.h> |
#include <ox_toolkit.h> |
#include <ox_toolkit.h> |
#include "sm.h" |
#include "sm.h" |
Line 21 static db db_sm[] = { |
|
Line 22 static db db_sm[] = { |
|
{sm_set_mathcap, SM_setMathCap}, |
{sm_set_mathcap, SM_setMathCap}, |
{sm_popCMO, SM_popCMO}, |
{sm_popCMO, SM_popCMO}, |
{sm_pops, SM_pops}, |
{sm_pops, SM_pops}, |
|
{sm_control_reset_pid, SM_control_reset_connection_pid}, |
|
{sm_control_kill_pid, SM_control_kill_pid}, |
|
{sm_control_kill, SM_control_kill}, |
{NULL, NULL} |
{NULL, NULL} |
}; |
}; |
|
|
Line 82 static int getargs(cmo ***args) |
|
Line 86 static int getargs(cmo ***args) |
|
return argc; |
return argc; |
} |
} |
|
|
static int pids[1024] = {0}; |
#define MAX_PROCESS 1024 |
|
|
|
static pid_t *pids = NULL; |
static int pid_ptr = 0; |
static int pid_ptr = 0; |
|
static int pid_size = 0; |
|
|
int pid_lookup(int pid) |
void pids_extend() |
{ |
{ |
|
int size2 = pid_size + MAX_PROCESS; |
|
pid_t *pids2 = (pid_t *)malloc(sizeof(pid_t)*size2); |
|
if (pids != NULL) { |
|
memcpy(pids2, pids, sizeof(pid_t)*pid_size); |
|
free(pids); |
|
} |
|
pid_size = size2; |
|
pids = pids2; |
|
} |
|
|
|
int pid_lookup(pid_t pid) |
|
{ |
int i; |
int i; |
for(i=0; i<pid_ptr; i++) { |
for(i=0; i<pid_ptr; i++) { |
if (pids[i] == pid) { |
if (pids[i] == pid) { |
Line 96 int pid_lookup(int pid) |
|
Line 115 int pid_lookup(int pid) |
|
return -1; |
return -1; |
} |
} |
|
|
int pid_registed(int pid) |
int pid_registed(pid_t pid) |
{ |
{ |
return pid_lookup(pid)+1; |
return pid_lookup(pid)+1; |
} |
} |
|
|
int pid_regist(int pid) |
void pid_regist(pid_t pid) |
{ |
{ |
if (pid_ptr < 1024) { |
if (pid_ptr >= pid_size) { |
pids[pid_ptr++] = pid; |
pids_extend(); |
return pid; |
|
} |
} |
return 0; |
pids[pid_ptr++] = pid; |
} |
} |
|
|
void pid_delete(int pid) |
void pid_delete(pid_t pid) |
{ |
{ |
int i = pid_lookup(pid); |
int i = pid_lookup(pid); |
if (i >= 0 && i != --pid_ptr) { |
if (i >= 0 && i != --pid_ptr) { |
Line 118 void pid_delete(int pid) |
|
Line 136 void pid_delete(int pid) |
|
} |
} |
} |
} |
|
|
|
int pid_reset(pid_t pid) |
|
{ |
|
if (pid_registed(pid)) { |
|
kill(pid, SIGUSR1); |
|
return 1; |
|
} |
|
return 0; |
|
} |
|
|
|
int pid_kill(pid_t pid) |
|
{ |
|
if (pid_registed(pid)) { |
|
kill(pid, SIGKILL); |
|
pid_delete(pid); |
|
return 1; |
|
} |
|
return 0; |
|
} |
|
|
|
/* Killing all child processes */ |
|
void pid_kill_all() |
|
{ |
|
while(pid_ptr > 0) { |
|
kill(pids[--pid_ptr], SIGKILL); |
|
} |
|
} |
|
|
int lf_oxc_open() |
int lf_oxc_open() |
{ |
{ |
cmo **argv; |
cmo **argv; |
char *cmd; |
char *cmd; |
int port; |
int port; |
int pid; |
pid_t pid; |
|
|
if (getargs(&argv) != 2 || argv[0]->tag != CMO_STRING |
if (getargs(&argv) != 2 || argv[0]->tag != CMO_STRING |
|| argv[1]->tag != CMO_INT32) { |
|| argv[1]->tag != CMO_INT32) { |
Line 159 void sm_set_mathcap(OXFILE *oxfp) |
|
Line 204 void sm_set_mathcap(OXFILE *oxfp) |
|
|
|
void sm_control_kill(OXFILE *oxfp) |
void sm_control_kill(OXFILE *oxfp) |
{ |
{ |
|
pid_kill_all(); |
|
} |
|
|
|
void sm_control_kill_pid(OXFILE *oxfp) |
|
{ |
cmo_int32 *m = (cmo_int32 *)pop(); |
cmo_int32 *m = (cmo_int32 *)pop(); |
int pid = m->i; |
pid_t pid = m->i; |
if (m->tag != CMO_INT32 || !pid_registed(pid)) { |
if (m->tag != CMO_INT32 || !pid_kill(pid)) { |
push_error(-1, m); |
push_error(-1, m); |
}else { |
|
kill(pid, SIGKILL); |
|
pid_delete(pid); |
|
} |
} |
} |
} |
|
|
void sm_control_reset(OXFILE *oxfp) |
void sm_control_reset_pid(OXFILE *oxfp) |
{ |
{ |
cmo_int32 *m = (cmo_int32 *)pop(); |
cmo_int32 *m = (cmo_int32 *)pop(); |
int pid = m->i; |
pid_t pid = m->i; |
if (m->tag != CMO_INT32 || !pid_registed(pid)) { |
if (m->tag != CMO_INT32 || !pid_reset(pid)) { |
push_error(-1, m); |
push_error(-1, m); |
}else { |
return; |
kill(pid, SIGUSR1); |
|
} |
} |
|
/* ... */ |
} |
} |
|
|
void sm_control_spawn_server(OXFILE *oxfp); |
void sm_control_spawn_server(OXFILE *oxfp); |