X-Spam-Check-By: sourceware.org Message-ID: <4428F3FD.6060507@bull.net> Date: Tue, 28 Mar 2006 10:29:49 +0200 From: Martine Carannante User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.6) Gecko/20050319 MIME-Version: 1.0 To: cygwin AT cygwin DOT com, Martine Carannante Subject: Problem setenv/putenv for msgget Content-Type: multipart/mixed; boundary="------------030007010903050309030504" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 --------------030007010903050309030504 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed I 'm using CYGWIN (the last version 1.5.19.4). My application use the IPC messages queue. The cygserver is started correctly. The application server side (is a service) is launched by cygrunsrv ... with -e CYGWIN=server , it is OK If I launch the application client in a shell script, it is OK if I set before launching the application, the CYGWIN variable to server. It's normal. My problem is : ---------------------- - The application client is a CGI written in C, launched by Apache or IIS , and I don't know how to set the CYGWIN variable before the application is launched.If I use Apache I can use the SetEnv directive to set a variable in the Apache configuration file. But with IIS I don't know to do that. I need a global solution for Apache and IIS. So , I tried to set the environment variable CYGWIN to server with the routines setenv(), putenv(), SetEnvironmentVariable() inside the CGI code. I have always the "Bad system call " error when the program executes msgget. It seems that the setenv function doesn't run while the getenv function returns the right value !! I wrote a test program to reproduce the problem: - rcv_msg.c waits for messages - send_msg.c sends messages The test programs are launched in a shell window. _Test NOK _The variable CYGWIN is set in the shell for the server rcv_msg . The variable CYGWIN is set inside the send_msg.c program (setenv routine) The file /tmp/xx must exist. The programs are launched in 2 different shell windows /$/ */export CYGWIN=server/* /$ ./rcv_msg.exe /tmp/xx Call ftok /tmp/xx command_file=/tmp/xx,key=16068417 Call msgget Return msgget 3538944 Loop msgrcv $ *unset CYGWIN* $ ./send_msg.exe /tmp/xx AAA Call getenv CYGWIN Value returned by getenv CYGWIN =(null) Call setenv CYGWIN=server Value returned by setenv CYGWIN result=0 Call getenv CYGWIN Value returned by getenv CYGWIN =server Call msgget Bad system call /_Test OK (CYGWIN variable set in the shell for the server and client application ): _ /$/ */export CYGWIN=server/* /$ ./rcv_msg.exe /tmp/xx Call ftok /tmp/xx command_file=/tmp/xx,key=16068417 Call msgget Return msgget 3538944 Loop msgrcv Message=AAA //$/* /export CYGWIN=server/* /$ ./send_msg.exe /tmp/xx AAA Call getenv CYGWIN Value returned by getenv CYGWIN =(null) Call setenv CYGWIN=server Value returned by setenv CYGWIN result=0 Call getenv CYGWIN Value returned by getenv CYGWIN =server Call msgget/ _Note:_ I used ipc-daemon in my previous version, and it was OK. There was no environment variable to set. Thanks to help me. Martine -- Martine Carannante System Software Development R&D Bull, Architect of an Open World TM Tél : (+33) 1 30 80 71 87 http://www.bull.com --------------030007010903050309030504 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="rcv_msg.c" Content-Disposition: inline; filename="rcv_msg.c" #include #include #include #include #include int message_queue_id; #define MAX_INPUT_BUFFER 1024 int main(int argc, char **argv){ char buffer[1024]; char command_file[1024]; int result; struct My_msgbuf { long mtype; char mtext[1024]; }rbuf ; /*struct msgbuf rbuf;*/ if (argc < 2) { printf("Key (existing)file argument missing\n"); printf("Usage: rcv_msg \n"); exit(-1); } strcpy(command_file,argv[1]); result=open_command_file(command_file); if (result != 0) exit(-1); printf("Loop msgrcv\n"); while (result=msgrcv(message_queue_id,&rbuf,MAX_INPUT_BUFFER,0,0) != -1) { printf("Message=%s\n",rbuf.mtext); } } int open_command_file(char * command_file) { key_t key; int result; result=open(command_file,O_CREAT|O_RDWR,S_IWUSR); printf("Call ftok %s\n",command_file); key=ftok(command_file,'A'); printf("command_file=%s,key=%d\n",command_file,key); if (key == -1){ perror("Ftok\n"); return -1; } printf("Call msgget \n"); message_queue_id = msgget(key,(IPC_CREAT|IPC_EXCL|0666)); printf("Return msgget %d \n",message_queue_id); if (message_queue_id == -1){ perror("msgget\n"); return -1; } return 0; } --------------030007010903050309030504 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="send_msg.c" Content-Disposition: inline; filename="send_msg.c" #include #include #include #include #include #define MAX_FILENAME_LENGTH 1024 #define MAX_INPUT_BUFFER 1024 #define OK 0 extern char ** environ; #define ERROR -1 char command_file[MAX_FILENAME_LENGTH]; char command_line[MAX_INPUT_BUFFER]; /* write a command entry to the command file */ int main(int argc, char **argv){ FILE *fp; int message_queue_id; key_t key; /*struct msgbuf sbuf;*/ struct msgbuf { long mtype; char mtext[1024]; }sbuf; int result; char *value; if (argc < 3) { printf("Argument missing"); printf("Usage : send_msg \n"); exit(ERROR); } /* get the command line argument*/ strcpy(command_file,argv[1]); strcpy(command_line,argv[2]); key=ftok(command_file,'A'); printf("Call getenv CYGWIN\n"); value=getenv("CYGWIN"); printf("Value returned by getenv CYGWIN =%s\n",value); printf("Call setenv CYGWIN=server\n"); result=setenv("CYGWIN","server",1); printf("Value returned by setenv CYGWIN result=%d\n",result); printf("Call getenv CYGWIN\n"); value=getenv("CYGWIN"); printf("Value returned by getenv CYGWIN =%s\n",value); /*SetEnvironmentVariable("CYGWIN","server");*/ /* open the command for writing (since this is a pipe, it will really be appended) */ printf("Call msgget\n"); message_queue_id = msgget(key,0666); if (message_queue_id == -1) { perror("Error: msgget 0666 !\n"); printf("command_file =%s key=%d\n",command_file,key); return ERROR; } sbuf.mtype=1; strcpy(sbuf.mtext,command_line); if(msgsnd(message_queue_id,&sbuf,strlen(sbuf.mtext)+1,IPC_NOWAIT) <0){ perror("Error: msgsnd!\n"); return ERROR; } return OK; } --------------030007010903050309030504 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------030007010903050309030504--