=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/oxf_old.c,v retrieving revision 1.1 retrieving revision 1.9 diff -u -p -r1.1 -r1.9 --- OpenXM/src/ox_toolkit/oxf_old.c 2000/10/10 05:23:21 1.1 +++ OpenXM/src/ox_toolkit/oxf_old.c 2015/08/27 03:03:34 1.9 @@ -1,18 +1,29 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/ox_toolkit/oxf_old.c,v 1.8 2009/03/20 18:41:16 iwane Exp $ */ /* このモジュールは互換性のためのものです。*/ #include #include #include -#include -#include #include +#include + +#if defined(_MSC_VER) || defined(__MINGW32__) +#include +#define MAXHOSTNAMELEN 256 +#else +#include #include #include -#include +#endif +#if defined(__sun__) +#include +#include +#include +#endif + #include "mysocket.h" #include "ox_toolkit.h" @@ -22,6 +33,7 @@ OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *ctl) return oxfp; } +static char *OpenXM_HOME = "/usr/local/OpenXM"; static char *concat_openxm_home_bin(char *s); OXFILE * ox_start(char* host, char* prog1, char* prog2); @@ -77,30 +89,33 @@ static OXFILE *mysocketAccept2(int listened, char *pas static char *concat_openxm_home_bin(char *s) { char *path; - char *base; /* if s includes '/' then it is not concaticated. */ if (strchr(s, '/') != NULL) { return s; } - base = getenv("OpenXM_HOME"); - path = malloc(strlen(base)+6+strlen(s)); - sprintf(path, "%s/bin/%s", base, s); + path = MALLOC(strlen(OpenXM_HOME)+6+strlen(s)); + sprintf(path, "%s/bin/%s", OpenXM_HOME, s); return path; } void set_OpenXM_HOME() { - /* Solaris does not have the setenv(). */ - if (getenv("OpenXM_HOME") == NULL) { - putenv("OpenXM_HOME=/usr/local/OpenXM"); + char *e; + if ((e = getenv("OpenXM_HOME")) != NULL +#if defined(__CYGWIN__) + || (e = getenv("OPENXM_HOME")) != NULL +#endif + ) { + OpenXM_HOME = e; } } -void ox_exec_local(char* host, char* ctl_prog, char* dat_prog, int portControl, int portStream, char *passwd) +void ox_exec_local(char* ctl_prog, char* dat_prog, int portControl, int portStream, char *passwd) { char ctl[128], dat[128]; + char localhost[MAXHOSTNAMELEN]; sprintf(ctl, "%d", portControl); sprintf(dat, "%d", portStream); @@ -109,14 +124,15 @@ void ox_exec_local(char* host, char* ctl_prog, char* d ctl_prog = concat_openxm_home_bin(ctl_prog); dat_prog = concat_openxm_home_bin(dat_prog); - if (fork() == 0) { - execlp("oxlog", "oxlog", "xterm", "-icon", "-e", ctl_prog, - "-reverse", "-ox", dat_prog, - "-data", dat, "-control", ctl, "-pass", passwd, - "-host", host, NULL); - exit(1); - } - + if (gethostname(localhost, MAXHOSTNAMELEN)==0) { + if (fork() == 0) { + execlp("oxlog", "oxlog", "xterm", "-icon", "-e", ctl_prog, + "-reverse", "-ox", dat_prog, + "-data", dat, "-control", ctl, "-pass", passwd, + "-host", localhost, NULL); + exit(1); + } + } } /* @@ -133,13 +149,13 @@ OXFILE *ox_start(char* host, char* ctl_prog, char* dat OXFILE *st, *ct; char *passwd = generate_otp(); int listen[2]; - short ports[2] = {0}; /* short! */ + int ports[2] = {0}; - listen[0] = mysocketListen(host, &ports[0]); - listen[1] = mysocketListen(host, &ports[1]); + /* host を無視 */ + listen[0] = oxf_listen(&ports[0]); + listen[1] = oxf_listen(&ports[1]); - ox_exec_local(host, ctl_prog, dat_prog, ports[0], ports[1], passwd); - + ox_exec_local(ctl_prog, dat_prog, ports[0], ports[1], passwd); ct = mysocketAccept2(listen[0], passwd); if (ct != NULL) { usleep(10); /* zzz... */ @@ -176,16 +192,25 @@ OXFILE *ox_start_insecure(char* host, short portContro /* ssh -f host oxlog xterm -e ox -ox ox_asir ... */ void ssh_ox_server(char *remote_host, char *ctl_prog, char *dat_prog, short portControl, short portStream) { + char buf[2][10]; +/* ctl_prog = concat_openxm_home_bin(ctl_prog); dat_prog = concat_openxm_home_bin(dat_prog); +*/ if (fork() == 0) { + + sprintf(buf[0], "%hd", portStream); + sprintf(buf[1], "%hd", portControl); + execlp("ssh", "ssh", "-f", remote_host, "oxlog", "xterm", "-icon", "-e", ctl_prog, "-insecure", "-ox", dat_prog, - "-data", portStream, "-control", portControl, + "-data", buf[0], "-control", buf[1], "-host", remote_host, NULL); exit(1); } + + sleep(1); /* wait ssh */ } OXFILE *ox_start_remote_with_ssh(char *dat_prog, char* remote_host) @@ -193,4 +218,3 @@ OXFILE *ox_start_remote_with_ssh(char *dat_prog, char* ssh_ox_server(remote_host, "ox", dat_prog, 1200, 1300); return ox_start_insecure(remote_host, 1200, 1300); } -