X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Message-ID: <3526.1265373394@weedlight.ch> To: Reply-To: joel AT weedlight DOT ch Content-Type: text/plain; charset="utf-8" X-Origin: 91.137.10.18 X-Atmail-Account: joel AT weedlight DOT ch Date: Fri, 5 Feb 2010 13:36:34 +0100 Subject: service terminates after logging out of the desktop From: joel AT weedlight DOT ch Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hi, I wrote a small program that launches a java rmi server. And it should = run all the time. The service is running when the system is up but as soon = as I log out of the Desktop, the service terminates. I believed that there = must be a signal emitted but no luck, it doesn't log anything except "start= ing MvServer". the command I used for installing the service: `cygrunsrv -I MvServer -d "C= YGWIN MvServer" -p /bin/MvServer.exe` the command I used for compilling the service program: `gcc -D_JNI_IMPLEMEN= TATION_ -I/cygdrive/c/Programme/Java/jdk1.6.0_13/include -I/cygdrive/c/Prog= ramme/Java/jdk1.6.0_13/include/win32 MvServer.c -L/cygdrive/c/Programme/Jav= a/jdk1.6.0_13/lib/ -ljvm -o MvServer.exe` #include #include #include #include #include typedef struct _MvServer MvServer; struct _MvServer{ JavaVM *jvm; JNIEnv *env; } server =3D { NULL, NULL }; void mv_server_main_thread(); void mv_server_alarm_signal(); void mv_server_hup_signal(); void mv_server_term_signal(); void mv_server_quit_signal(); void mv_server_chld_signal(); void mv_server_int_signal(); FILE *log_fd; void mv_server_alarm_signal(int sig) { signal(SIGALRM, SIG_IGN); fprintf(log_fd, "received alarm signal: exiting\n\0"); fflush(log_fd); } void mv_server_hup_signal(int sig) { signal(SIGHUP, SIG_IGN); fprintf(log_fd, "received hup signal: exiting\n\0"); fflush(log_fd); } void mv_server_term_signal(int sig) { jclass cls; jmethodID mid; jint rc; signal(SIGTERM, SIG_IGN); fprintf(log_fd, "received term signal: exiting\n\0"); fflush(log_fd); 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_quit_signal(int sig) { signal(SIGQUIT, SIG_IGN); fprintf(log_fd, "received quit signal: exiting\n\0"); fflush(log_fd); } void mv_server_chld_signal(int sig) { signal(SIGCHLD, SIG_IGN); fprintf(log_fd, "received chld signal: exiting\n\0"); fflush(log_fd); } void mv_server_int_signal(int sig) { signal(SIGINT, SIG_IGN); fprintf(log_fd, "received int signal: exiting\n\0"); fflush(log_fd); } void mv_server_main() { JavaVM *jvm; JNIEnv *env; JavaVMInitArgs vm_args; 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-api.jar\0"; options[1].optionString =3D "-Djava.rmi.server.codebase=3Dfile:///c/class= es/MvServer\0"; options[2].optionString =3D "-Djava.security.policy=3DC:\\classes\\MvServ= er\\policy.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; 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; 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); } fprintf(log_fd, "calling main function of MvServer\n\0"); (*env)->CallStaticVoidMethod(env, cls, mid, 0); (*jvm)->DestroyJavaVM(jvm); } int main(int argc, char **argv) { pthread_t rmi_thread; pthread_t main_thread; pid_t child_pid, wpid; int status; log_fd =3D fopen("/cygdrive/c/classes/MvServer/error.log\0", "w+\0"); fprintf(log_fd, "starting MvServer\n\0"); fflush(log_fd); signal(SIGALRM, mv_server_alarm_signal); signal(SIGHUP, mv_server_hup_signal); signal(SIGTERM, mv_server_term_signal); signal(SIGQUIT, mv_server_quit_signal); signal(SIGCHLD, mv_server_chld_signal); signal(SIGINT, mv_server_int_signal); if((child_pid =3D fork()) < 0){ fprintf(log_fd, "failed to fork process\n\0"); }else if(child_pid =3D=3D 0){ mv_server_main(); }else{ do{ wpid =3D waitpid(child_pid, &status, WUNTRACED #ifdef WCONTINUED | WCONTINUED #endif ); if(wpid =3D=3D -1){ perror("waitpid\0"); exit(-1); } =20=20=20=20=20=20 if(WIFEXITED(status)){ fprintf(log_fd, "child exited, status=3D%d\n\0", WEXITSTATUS(status)); =09 =09 }else if(WIFSIGNALED(status)){ fprintf(log_fd, "child killed (signal %d)\n\0", WTERMSIG(status)); =09 =09 }else if(WIFSTOPPED(status)){ fprintf(log_fd, "child stopped (signal %d)\n\0", WSTOPSIG(status)); =09 =09 #ifdef WIFCONTINUED }else if(WIFCONTINUED(status)){ fprintf(log_fd, "child continued\n\0"); #endif }else{ fprintf(log_fd, "Unexpected status (0x%x)\n\0", status); } }while(!WIFEXITED(status) && !WIFSIGNALED(status)); } fprintf(log_fd, "MvServer terminated\n\0"); fflush(log_fd); fclose(log_fd); 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