Mail Archives: cygwin/2010/02/03/09:18:32
Hi, I wrote a program in C to launch rmiregistry and to start my RMI server=
. The
Program works fine but when I tried `cygrunsrv --install MvServer --path
/cygdrive/c/classes/MvServer/MvServer.exe` and finally `cygrunsrv -S MvServ=
er`
the RMI server seems to be death. I don't get any error messages in the log.
Below is my entire code of MvServer.c written in C.
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <jni.h>
typedef struct _MvServer MvServer;
struct _MvServer{
JavaVM *jvm;
JNIEnv *env;
} server =3D {
NULL, NULL
};
void* mv_server_rmi_thread(void *data);
void* mv_server_main_thread(void *data);
void mv_server_term_signal();
FILE *log_fd;
void*
mv_server_rmi_thread(void *data)
{
execl("/cygdrive/c/Programme/Java/jdk1.6.0_13/bin/rmiregistry.exe\0", NUL=
L);
return(NULL);
}
void
mv_server_term_signal()
{
jclass cls;
jmethodID mid;
jint rc;
cls =3D (*(server.env))->FindClass((server.env), "MvServer\0");
=20=20
if(cls =3D=3D 0){
fprintf(log_fd, "couldn't invoke MvServer\n\0");
fflush(log_fd);
exit(0);
}
mid =3D (*(server.env))->GetStaticMethodID((server.env), cls, "shutdown\0=
",
"([Ljava/lang/String;)V\0");
=20=20
if(mid =3D=3D 0){
fprintf(log_fd, "couldn't get shutdown\n\0");
fflush(log_fd);
fclose(log_fd);
exit(0);
}else{
(*(server.env))->CallStaticVoidMethod((server.env), cls, mid, 0);
(*(server.jvm))->DestroyJavaVM((server.jvm));
}
}
void*
mv_server_main_thread(void *data)
{
JavaVM *jvm; /* denotes a Java VM */
JNIEnv *env; /* pointer to native method interface */
JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
JavaVMOption options[3];
jclass cls;
jmethodID mid;
jint rc;
options[0].optionString =3D
"-Djava.class.path=3DC:\\classes\\MvServer;C:\\Programme\\jdom-1.1\\build\\=
jdom.jar;C:\\Programme\\Java\\jdk1.6.0_13;C:\\xampp\\tomcat\\lib\\servlet-a=
pi.jar\0";
options[1].optionString =3D
"-Djava.rmi.server.codebase=3Dfile:///c/classes/MvServer\0";
options[2].optionString =3D "-Djava.security.policy=3Dpolicy.txt\0";
vm_args.version =3D JNI_VERSION_1_6;
vm_args.nOptions =3D 3;
vm_args.options =3D options;
vm_args.ignoreUnrecognized =3D 0;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
rc =3D JNI_CreateJavaVM(&jvm, (void **) &env, (void *) &vm_args);
if(rc < 0){
fprintf(log_fd, "couldn't open Java VM\n\0");
fflush(log_fd);
fclose(log_fd);
return(0);
}
server.jvm =3D jvm;
server.env =3D env;
/* invoke the Main.test method using the JNI */
cls =3D (*env)->FindClass(env, "MvServer");
if(cls =3D=3D 0){
fprintf(log_fd, "couldn't invoke MvServer\n\0");
fflush(log_fd);
fclose(log_fd);
return(0);
}
mid =3D (*env)->GetStaticMethodID(env, cls, "main\0", "([Ljava/lang/Strin=
g;)V\0");
if(mid =3D=3D 0){
fprintf(log_fd, "couldn't get main\n\0");
fflush(log_fd);
fclose(log_fd);
return(0);
}
(*env)->CallStaticVoidMethod(env, cls, mid, 0);
/* We are done. */
(*jvm)->DestroyJavaVM(jvm);
return(NULL);
}
int
main(int argc, char **argv)
{
pthread_t rmi_thread;
pthread_t main_thread;
pid_t child_pid, wpid;
int status;
signal(SIGTERM, mv_server_term_signal);
log_fd =3D fopen("/cygdrive/c/classes/MvServer/error.log\0", "w+\0");
fprintf(log_fd, "starting MvServer\n\0");
fflush(log_fd);
if((child_pid =3D fork()) < 0){
fprintf(log_fd, "failed to fork process\n\0");
}else if(child_pid =3D=3D 0){
pthread_create(&rmi_thread, NULL, mv_server_rmi_thread, NULL);
usleep(5000);
pthread_create(&main_thread, NULL, mv_server_main_thread, NULL);
}else{
wpid =3D waitpid(child_pid, &status,
WUNTRACED | WCONTINUED);
}
=20=20
return(0);
}
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
- Raw text -