diff options
author | dos-reis <gdr@axiomatics.org> | 2007-12-05 13:38:37 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2007-12-05 13:38:37 +0000 |
commit | 905ae3df3f5d3bca80577042a8de132ab59cb598 (patch) | |
tree | b7fc7f34c401cdd2ac611982041ec83c78ff50d0 | |
parent | ee26a6e18cb066ba7ed43cfe74315a41191dcd04 (diff) | |
download | open-axiom-905ae3df3f5d3bca80577042a8de132ab59cb598.tar.gz |
* Makefile.pamphlet: Remove rules for extracting files from
pamphlets.
(%.lo): Adjust include directory.
(mostlyclean-local): Don't remove source files and headers.
* nagman.c.pamphlet: Remove.
* session.c.pamphlet: Likewise.
* sman.c.pamphlet: Likewise.
* sessions.c: New.
* sman.h: Likewise.
* sman.c: Likewise.
-rw-r--r-- | src/sman/ChangeLog | 13 | ||||
-rw-r--r-- | src/sman/Makefile.in | 31 | ||||
-rw-r--r-- | src/sman/Makefile.pamphlet | 39 | ||||
-rw-r--r-- | src/sman/nagman.c.pamphlet | 636 | ||||
-rw-r--r-- | src/sman/session.c (renamed from src/sman/session.c.pamphlet) | 254 | ||||
-rw-r--r-- | src/sman/sman.c (renamed from src/sman/sman.c.pamphlet) | 489 | ||||
-rw-r--r-- | src/sman/sman.h | 54 |
7 files changed, 266 insertions, 1250 deletions
diff --git a/src/sman/ChangeLog b/src/sman/ChangeLog index a5722d5f..98482cdd 100644 --- a/src/sman/ChangeLog +++ b/src/sman/ChangeLog @@ -1,3 +1,16 @@ +2007-12-05 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Remove rules for extracting files from + pamphlets. + (%.lo): Adjust include directory. + (mostlyclean-local): Don't remove source files and headers. + * nagman.c.pamphlet: Remove. + * session.c.pamphlet: Likewise. + * sman.c.pamphlet: Likewise. + * sessions.c: New. + * sman.h: Likewise. + * sman.c: Likewise. + 2007-09-13 Alfredo Portes <alfredo.portes@gmail.com> Waldek Hebisch <hebisch@math.uni.wroc.pl> diff --git a/src/sman/Makefile.in b/src/sman/Makefile.in index ca0b270f..edd36314 100644 --- a/src/sman/Makefile.in +++ b/src/sman/Makefile.in @@ -16,25 +16,22 @@ bin_PROGRAMS = session$(EXEEXT) \ libspad_la = $(axiom_target_libdir)/libspad.la -session_sources = session.c -session_SOURCES = $(addsuffix .pamphlet, $(session_sources)) -session_objects = $(session_sources:.c=.lo) +session_SOURCES = session.c +session_objects = $(session_SOURCES:.c=.lo) session_LDADD = $(libspad_la) @axiom_c_runtime_extra@ session_DEPENDENCIES = -spadclient_sources = spadclient.c -spadclient_objects = $(spadclient_sources:.c=.lo) +spadclient_SOURCES = spadclient.c +spadclient_objects = $(spadclient_SOURCES:.c=.lo) spadclient_LDADD = $(libspad_la) @axiom_c_runtime_extra@ spadclient_DEPENDENCIES = -sman_sources = sman.c -sman_SOURCES = $(addsuffix .pamphlet, $(sman_sources)) -sman_objects = $(sman_sources:.c=.lo) +sman_SOURCES = sman.c +sman_objects = $(sman_SOURCES:.c=.lo) sman_LDADD = $(libspad_la) @axiom_c_runtime_extra@ sman_DEPENDENCIES = -pamphlets = $(session_SOURCES) $(sman_SOURCES) .PHONY: all all-sman @@ -51,14 +48,9 @@ stamp: $(OUTLIB)/session$(EXEEXT) \ .SUFFIXES: .SUFFIXES: .c .h .lo .$(OBJEXT) .PRECIOUS: %.lo %.obj -.PRECIOUS: %.c -.PRECIOUS: %.h %.lo: %.c - $(COMPILE) ${CCF} -o $@ $(axiom_includes) -I$(builddir) $< - -%.c: $(srcdir)/%.c.pamphlet - $(axiom_build_document) --tangle --output=$@ $< + $(COMPILE) ${CCF} -o $@ $(axiom_includes) -I$(srcdir) $< ${OUTLIB}/session$(EXEEXT): $(session_objects) $(session_DEPENDENCIES) $(LINK) -o $@ $(session_objects) $(session_LDADD) ${LDF} @@ -74,13 +66,10 @@ ${OUT}/sman$(EXEEXT): $(sman_objects) $(sman_DEPENDENCIES) $(sman_objects): sman.h $(axiom_c_macros_h) -sman.h: $(srcdir)/sman.c.pamphlet - $(axiom_build_document) --tangle=$@ --output=$@ $< - mostlyclean-local: - @rm -f $(session_sources) $(session_objects) sman.h - @rm -f $(spadclient_sources) $(session_objects) - @rm -f $(sman_sources) $(sman_objects) + @rm -f $(session_objects) sman.h + @rm -f $(session_objects) + @rm -f $(sman_objects) clean-local: mostlyclean-local @rm -f $(OUTLIB)/session$(EXEEXT) diff --git a/src/sman/Makefile.pamphlet b/src/sman/Makefile.pamphlet index db980d94..d7a50858 100644 --- a/src/sman/Makefile.pamphlet +++ b/src/sman/Makefile.pamphlet @@ -34,25 +34,22 @@ bin_PROGRAMS = session$(EXEEXT) \ libspad_la = $(axiom_target_libdir)/libspad.la -session_sources = session.c -session_SOURCES = $(addsuffix .pamphlet, $(session_sources)) -session_objects = $(session_sources:.c=.lo) +session_SOURCES = session.c +session_objects = $(session_SOURCES:.c=.lo) session_LDADD = $(libspad_la) @axiom_c_runtime_extra@ session_DEPENDENCIES = -spadclient_sources = spadclient.c -spadclient_objects = $(spadclient_sources:.c=.lo) +spadclient_SOURCES = spadclient.c +spadclient_objects = $(spadclient_SOURCES:.c=.lo) spadclient_LDADD = $(libspad_la) @axiom_c_runtime_extra@ spadclient_DEPENDENCIES = -sman_sources = sman.c -sman_SOURCES = $(addsuffix .pamphlet, $(sman_sources)) -sman_objects = $(sman_sources:.c=.lo) +sman_SOURCES = sman.c +sman_objects = $(sman_SOURCES:.c=.lo) sman_LDADD = $(libspad_la) @axiom_c_runtime_extra@ sman_DEPENDENCIES = -pamphlets = $(session_SOURCES) $(sman_SOURCES) @ \section{session} @@ -61,14 +58,6 @@ ${OUTLIB}/session$(EXEEXT): $(session_objects) $(session_DEPENDENCIES) $(LINK) -o $@ $(session_objects) $(session_LDADD) ${LDF} @ -\section{nagman} -Note that we do not build the nagman component as we do not have the -necessary code (for instance, [[callnag]]). -<<nagman>>= -${OUT}/nagman$(EXEEXT): $(nagman_objects) $(nagman_DEPENDENCIES) - $(LINK) -o $@ $(nagman_objects) $(nagman_LDADD) ${LDF} -@ - \section{spadclient} <<spadclient>>= ${OUTLIB}/spadclient$(EXEEXT): $(spadclient_objects) $(spadclient_DEPENDENCIES) @@ -84,9 +73,6 @@ ${OUT}/sman$(EXEEXT): $(sman_objects) $(sman_DEPENDENCIES) $(LINK) -o $@ $(sman_objects) $(sman_LDADD) ${LDF} $(sman_objects): sman.h $(axiom_c_macros_h) - -sman.h: $(srcdir)/sman.c.pamphlet - $(axiom_build_document) --tangle=$@ --output=$@ $< @ <<*>>= @@ -110,14 +96,9 @@ stamp: $(OUTLIB)/session$(EXEEXT) \ .SUFFIXES: .SUFFIXES: .c .h .lo .$(OBJEXT) .PRECIOUS: %.lo %.obj -.PRECIOUS: %.c -.PRECIOUS: %.h %.lo: %.c - $(COMPILE) ${CCF} -o $@ $(axiom_includes) -I$(builddir) $< - -%.c: $(srcdir)/%.c.pamphlet - $(axiom_build_document) --tangle --output=$@ $< + $(COMPILE) ${CCF} -o $@ $(axiom_includes) -I$(srcdir) $< <<session>> @@ -126,9 +107,9 @@ stamp: $(OUTLIB)/session$(EXEEXT) \ <<sman>> mostlyclean-local: - @rm -f $(session_sources) $(session_objects) sman.h - @rm -f $(spadclient_sources) $(session_objects) - @rm -f $(sman_sources) $(sman_objects) + @rm -f $(session_objects) + @rm -f $(session_objects) + @rm -f $(sman_objects) clean-local: mostlyclean-local @rm -f $(OUTLIB)/session$(EXEEXT) diff --git a/src/sman/nagman.c.pamphlet b/src/sman/nagman.c.pamphlet deleted file mode 100644 index c8db5f61..00000000 --- a/src/sman/nagman.c.pamphlet +++ /dev/null @@ -1,636 +0,0 @@ -\documentclass{article} -\usepackage{axiom} -\begin{document} -\title{\$SPAD/src/sman nagman.c} -\author{The Axiom Team} -\maketitle -\begin{abstract} -\end{abstract} -\eject -\tableofcontents -\eject -\section{nag.x} -<<nag.x>>= - -/* - * msg.x: Remote message printing protocol - */ -const MAXASP = 10; - -/* - * the nago structure is essentially a variable length string - */ - -struct nago { - opaque z <>; - }; -struct nagerr { -nago p; -nago q; -}; - -struct host{ -nago h <>; -}; - -struct nagst { - -/* Okay, if you understand this bit you know the essentials of how the link - * works. h <> is an array of nago, which is an array of fortran source - * code, the length of the array being the no. of asps (0 for most routines). - * y is the actual (XDR) input data for the routine. nm is the name of the - * routine. id is a tag identifying the host/axiom session. Finally per is a - * number telling whether or not to erase old fortran files on the remote - * machine (persistence - the number per distinct fortran files will be - * stored, any more than this and earlier ones will be deleted. - */ - - nago h <>; - nago y; - nago nm; - nago id; - int per; - }; -program NAGPROG { - version NAGVERS { - nagerr CALLNAG(nagst) = 1; - nago NAGMON(int)=2; - void AXEND(nago)=3; - } = 1; -/* - * the following number is very important. It tells the - * portmapper what number to register the nag daemon under. - * There are rules about which number to pick - check SUN - * technical info for more details - */ -} = 100088; - - -@ -\section{nagman} -\subsection{includes} -<<includes>>= -#include "axiom-c-macros.h" -#include "useproto.h" -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <termios.h> -#include <signal.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <rpc/rpc.h> /* always needed */ -#include <fcntl.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include "nag.h" /* generated by rpcgen */ -#include "com.h" -#include "bsdsignal.h" -#include "sockio-c.H1" -#include "bsdsignal.H1" -#include "nagman.H1" - -@ -\subsection{variables} -<<variables>>= -#ifdef ALPHAplatform -extern int getdomainname( char *, int ); -#endif -#ifdef SUN4OS5platform -extern int getdomainname( char *, int ); -extern int gethostname( char *, int ); -#endif - -#ifdef _NO_PROTO -nagerr * callnag_1(); -nago * nagmon_1(); -void * axend_1(); -#else -nagerr * callnag_1(nagst *,CLIENT *); -nago * nagmon_1(int *,CLIENT *); -void * axend_1(nago *,CLIENT *); -#endif - -#define DO 1 -#define DONT 0 - -int hnum, vmax; -char *datafile, *resultsfile; - -struct hostnode { - char * name; - struct hostnode *next; -} *hlist=NULL; - -nagst nag4; -Sock *sock1; - -@ -\subsection{term} -this code runs when the user quits axiom. before nagman dies, it does -an rpc call to nagd to tell it to get rid of files etc. The rpc call in -question is [[axend_1]] -we also send a USR1 to sman to beget another nagman -<<term>>= -static void -#ifdef _NO_PROTO -term(sig) - int sig; -#else -term(int sig) -#endif -{ - CLIENT *cld; - void *res; - struct hostnode *pnode; - -#ifndef HP9platform /* can't figure out a way to do this on HP/UX 9 */ - kill(atoi(getenv("SPADNUM")) , SIGUSR1); -#endif - - - if(hnum!=0) - { - unlink(datafile); - unlink(resultsfile); - } - - for(pnode=hlist;pnode!=NULL;pnode=pnode->next) - { - cld=clnt_create(pnode->name,NAGPROG, NAGVERS, "tcp"); - if (cld == NULL) - goto NOHOST; - - res=axend_1(&(nag4.id),cld); - NOHOST: - clnt_destroy(cld); - } - exit(0); -} - -@ -\subsection{size\_of\_file} -<<sizeoffile>>= -static long -#ifdef _NO_PROTO -size_of_file(filename) - char *filename; -#else -size_of_file(char *filename) -#endif -{ - struct stat buf_stat; - - stat(filename,&buf_stat); - return (buf_stat.st_size); - -} - -@ -\subsection{rpcloop} -<<rpcloop>>= -static void -#ifdef _NO_PROTO -rpcloop() -#else -rpcloop(void) -#endif -{ - CLIENT *cl; - int res,j,v=0,u,showMessage; - long i; - register struct hostent *alias1, *alias2; - struct in_addr *addrnum; - u_long junk; - struct timeval tv; - nagerr *result; - char *Buf , *buf1; - char *ffile[MAXASP]; - char routine[12], naghost[256]; - FILE *nfp1, *nfp2, *nfp3; - struct hostnode *phost; - int fd; - - for (;;) - { - - if((Buf=get_string(sock1))==NULL) term(1); /* one string carries all */ - - if(hnum!=0) - { - /* call parameters */ - free(nag4.nm.z.z_val); /* the routine name */ - free(nag4.y.z.z_val); /* the XDR data */ - for(i=0;i<v;i++) - { - unlink(ffile[i]); - free(ffile[i]); /* the asp filenames */ - free(nag4.h.h_val[i].z.z_val); /* the asps themselves*/ - } - free(nag4.h.h_val); /* the asps array */ - unlink(datafile); - unlink(resultsfile); - free(resultsfile); - free(datafile); - vmax= (v>vmax)? v : vmax; - } - - - - - buf1=strtok(Buf," "); - if (buf1) strcpy(naghost,buf1); - else printf("can't parse the naghost\n"); - /* INFO printf("%s\n",naghost);*/ - - buf1=strtok(NULL," "); - if (buf1) strcpy(routine,buf1); - else printf("can't parse the routine\n"); - /* INFO printf("%s\n",routine);*/ - - /* make copy of filenames because we will reuse Buf before deleting the files*/ - buf1=strtok(NULL," "); - if (buf1) resultsfile=strdup(buf1); - else printf("can't parse the resultsfile file\n"); - /* INFO printf("%s\n",resultsfile);*/ - - buf1=strtok(NULL," "); - if (buf1) datafile=strdup(buf1); - else printf("can't parse the datafile file\n"); - /* INFO printf("%s\n",datafile);*/ - - buf1=strtok(NULL," "); - if (buf1) nag4.per=atoi(buf1); - else printf("can't parse the persistence\n"); - /* INFO printf("%d\n",nag4.per);*/ - - buf1=strtok(NULL," "); - if (buf1) { - if (!strcmp(buf1,"on")) showMessage=DO; - else showMessage=DONT; - } - else printf("can't parse the messages flag\n"); - /* INFO printf("%s\n",buf1);*/ - - v=0; /* asp counter */ - while( (buf1=strtok(NULL," ")) ) - { - ffile[v++]=strdup(buf1); - /* INFO printf("%s\n",ffile[v-1]);*/ - } - - /* INFO printf("number of asps seen %d\n",v);*/ - - if(showMessage==DO) printf("nagman:acknowledging request for %s\n",routine); - - res=0; /* prepare result integer to be sent to Lisp */ - - if((nfp3=fopen(resultsfile,"w"))==NULL) - { - printf("can't open output file\n"); - goto END; - } - - /* nag4.h is the XDR array of asp text */ - nag4.h.h_len=v; - nag4.h.h_val=(nago *)malloc((v)*sizeof(nago)); - - - /* get asp text in call argument */ - for(u=0;u<v;u++) - { - /* this should be done by mmap */ - if((nfp1=fopen(ffile[u],"r"))==NULL) - { - fprintf(stderr,"can't open asp file %s\n",ffile[u]); - fclose(nfp1); - goto END; - } - fclose(nfp1); - i=size_of_file(ffile[u]); - - /* allocs memory for the file */ - nag4.h.h_val[u].z.z_val= (char *)malloc((i+1)*sizeof(char)); - - fd=open(ffile[u],O_RDONLY); - read(fd,nag4.h.h_val[u].z.z_val,i); - close(fd); - /* make null-term. string */ - nag4.h.h_val[u].z.z_val[i]='\0'; - /* set the length */ - nag4.h.h_val[u].z.z_len=strlen(nag4.h.h_val[u].z.z_val); - } - - - nag4.nm.z.z_val=strdup(routine); - nag4.nm.z.z_len=strlen(routine); - - /* get XDR data in call argument */ - /* should be done by mmap */ - if((nfp2=fopen(datafile,"r"))==NULL) - { - fprintf(stderr,"can't open data file\n"); - fclose(nfp2); - goto END; - } - - fclose(nfp2); - i=size_of_file(datafile); - nag4.y.z.z_val=(char *)malloc(i*sizeof(char)); - - fd=open(datafile,O_RDONLY); - read(fd,nag4.y.z.z_val,i); - close(fd); - nag4.y.z.z_len=i; - - - /* - * Create client "handle" used for calling MESSAGEPROG on - * the server designated on the command line. We tell - * the RPC package to use the "tcp" protocol when - * contacting the server. - */ - - /* update naghost by lookup */ - - if ((junk = inet_addr(naghost))!=-1) - { - addrnum=(struct in_addr *)junk; - if((alias2=gethostbyaddr((char *)&addrnum, - sizeof(addrnum), - AF_INET))!=NULL) - strcpy(naghost,alias2->h_name); - else - if((alias1=gethostbyname(naghost))!=NULL) - strcpy(naghost,alias1->h_name); - } - else - if((alias1=gethostbyname(naghost))!=NULL) - strcpy(naghost,alias1->h_name); - - - - - cl = clnt_create(naghost, NAGPROG, NAGVERS, "tcp"); - if (cl == NULL) - { - /* - * Couldn't establish connection with server. - * Print error message and die. - */ - clnt_pcreateerror(naghost); - goto END; - } - else - if (showMessage==DO) - printf("nagman:connection successful to %s\n",naghost); - - /* - * this number here sets the "timeout" for the rpc call. after this number - * of seconds, the call will quit if no response is received - * - */ - - tv.tv_sec=1000000; - tv.tv_usec=0; - clnt_control(cl,CLSET_TIMEOUT,(char *)&tv); - - - result = callnag_1(&nag4, cl); - - for(phost=hlist;phost!=NULL;phost=phost->next) - { - /* - * hlist is the "hostlist" of sites that have been contacted by nagman. - * here we check if this call is contacting a new site, and if so add it - * to the hostlist - * - */ - - if(!strcmp(phost->name,naghost)) - goto SKIP; - } - - if(hnum==0) { - hlist=(struct hostnode *)malloc(sizeof(struct hostnode)); - hlist->name=strdup(naghost); - hlist->next=NULL; - } - - else { - phost=(struct hostnode *)malloc(sizeof(struct hostnode)); - phost->name=strdup(naghost); - phost->next=hlist; - hlist=phost; - } - hnum++; - - - SKIP: - if (result == NULL) - { - /* - * An error occurred while calling the server. - * Print error message and die. - */ - if (showMessage==DO) - printf("nagman:no results (error) from %s\n",naghost); - clnt_perror(cl,naghost); - clnt_destroy(cl); - goto END; - } - - /* - * (*result).p is the part of the result with the XDRed results in it - * (numbers). (*result).q is the part with (text) error messages that - * have come from the NAG library. If there is neither an XDR result, - * nor a text error message from the library, then something is wrong - * so we just print out the "no result or error returned" message. - * - */ - - else if ((*result).p.z.z_len==0) - { - if((*result).q.z.z_len==0) - { - if (showMessage==DO) - printf("nagman:empty result (error) from %s\n",naghost); - clnt_destroy(cl); - goto END; - } - else - { - if (showMessage==DO) - printf("nagman:receiving results from %s\n\n",naghost); - for(j=0;j<(*result).q.z.z_len;j++) - printf("%c",(*result).q.z.z_val[j]); - clnt_destroy(cl); - goto END; - } - } - else - if (showMessage==DO) - printf("nagman:receiving results from %s\n\n",naghost); - - if (showMessage==DO) - fwrite(result->q.z.z_val,sizeof(char),result->q.z.z_len,stdout); - - /*INFO printf("\nRESULTS of length %d\n",(*result).p.z.z_len);*/ - - fwrite(result->p.z.z_val,sizeof(char),result->p.z.z_len, nfp3); - res=1; - clnt_destroy(cl); - - /* - * in case of any type of error, a goto END in the above code causes - * nagman to skip here and return to AXIOM - * - */ - - - END: - fclose(nfp3); - /* - * if everything has gone alright, send_int returns the integer res=1. If - * not it returns res=0. This is detected by the boot code which acts - * accordingly. - */ - send_int(sock1,res); - free(Buf); - } - - -} - -@ -\subsection{catchSignals} -catchSignals sets up signal handling. If nagman gets a sigterm it does not -die but goes back to rpcloop -<<catchSignals>>= -static void -#ifdef _NO_PROTO -catchSignals() -#else -catchSignals(void) -#endif -{ - bsdSignal(SIGTERM,term,RestartSystemCalls); - bsdSignal(SIGSEGV,term,RestartSystemCalls); -} - -@ -\subsection{main} -<<main>>= -void -#ifdef _NO_PROTO -main(argc,argv) -int argc; -char **argv; -#else -main(int argc,char **argv) -#endif -{ - char this[256],*hname,*dname,*spadnum; - int stat; - - catchSignals(); - stat=gethostname(this,256); - if (stat!=0) perror("gethostname"); - hname=strdup(this); - - stat=getdomainname(this,256); - if (stat!=0) perror("getdomainname"); - dname=strdup(this); - spadnum=getenv("SPADNUM"); - if (spadnum==0) { - fprintf(stderr,"nagman error: SPADNUM is not in the environment\n"); - exit(0); - } - - /* some machines return a full name from hostname - need to check hname has a . in it */ - - if (strchr(hname,'.')) - /* '.' found */ - sprintf(this,"%s_%i",hname,atoi(spadnum)); - else - /* substring not found */ - sprintf(this,"%s.%s_%i",hname,dname,atoi(spadnum)); - - /* this must contain the Internet address of the current host */ - nag4.id.z.z_val=strdup(this); - nag4.id.z.z_len=strlen(nag4.id.z.z_val); - hnum=0; - vmax=0; - /* - * this line sets up a socket for communication with the lisp - */ - - sock1 = connect_to_local_server(SpadServer, DebugWindow, 120 /*seconds*/); - if (!sock1) exit(0); - - rpcloop(); -} - -@ -\subsection{nagman} -<<nagman>>= -#define _NAGMAN_C -<<includes>> -<<variables>> -<<term>> -<<sizeoffile>> -<<rpcloop>> -<<catchSignals>> -<<main>> -@ -\section{License} -<<license>>= -/* -Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - - Neither the name of The Numerical ALgorithms Group Ltd. nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -@ -<<*>>= -<<license>> -<<nagman>> -@ -\eject -\begin{thebibliography}{99} -\bibitem{1} nothing -\end{thebibliography} -\end{document} diff --git a/src/sman/session.c.pamphlet b/src/sman/session.c index 8b6f3e92..1294fe1a 100644 --- a/src/sman/session.c.pamphlet +++ b/src/sman/session.c @@ -1,17 +1,42 @@ -\documentclass{article} -\usepackage{axiom} -\begin{document} -\title{\$SPAD/src/sman session.c} -\author{The Axiom Team} -\maketitle -\begin{abstract} -\end{abstract} -\eject -\tableofcontents -\eject -\section{session} -\subsection{includes} -<<includes>>= +/* + Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd. + All rights reserved. + + Copyright (C) 2007, Gabriel Dos Reis. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* #define DEBUG */ +#define _SESSION_C + #include "axiom-c-macros.h" #include <stdlib.h> #include <sys/time.h> @@ -27,42 +52,31 @@ #include "bsdsignal.H1" #include "session.H1" -@ -\subsection{variables} -<<variables>>= -#define BufSize 4096 /* size of communication buffer */ +#define BufSize 4096 /* size of communication buffer */ typedef struct sock_list { /* linked list of Sock */ Sock Socket; struct sock_list *next; } Sock_List; -Sock *spad_io = (Sock *) 0; /* to_server socket for SessionIO */ +Sock *spad_io = (Sock *) 0; /* to_server socket for SessionIO */ Sock *spad_server = (Sock *) 0; /* to_server socket for SpadServer */ -Sock *menu_client = (Sock *) 0; /* to_client socket for MenuServerName */ +Sock *menu_client = (Sock *) 0; /* to_client socket for MenuServerName */ Sock *active_session = (Sock *) 0; /* pointer to currently active session */ Sock_List *plSock = (Sock_List *) 0; -char big_bad_buf[BufSize]; /* big I/O buffer */ -int num_active_clients = 0; /* number of InterpWindows attached */ +char big_bad_buf[BufSize]; /* big I/O buffer */ +int num_active_clients = 0; /* number of InterpWindows attached */ int reading_output = 0; fd_set session_socket_mask; -@ -\subsection{usr1\_handler} -<<usr1handler>>= static void usr1_handler(int sig) { return; } -@ -\subsection{usr2\_handler} -SIGUSR2 is generated by spadclients. -We interpret it as an interrupt for the Lisp. -<<usr2handler>>= static void usr2_handler(int sig) { @@ -70,18 +84,12 @@ usr2_handler(int sig) return; } -@ -\subsection{term\_handler} -<<termhandler>>= static void term_handler(int sig) { exit(1); } -@ -\subsection{pr} -<<pr>>= static void pr() { @@ -94,9 +102,6 @@ pr() fprintf(stderr,"\n"); } -@ -\subsection{close\_client} -<<closeclient>>= static void close_client(int frame) { @@ -143,25 +148,25 @@ fprintf(stderr,"trying to clear %u\n",socket_fd); else { for (pSock=plSock; pSock->next != (Sock_List *) 0 ; pSock=pSock->next) if (pSock->next->Socket.frame == frame){ - socket_fd = pSock->next->Socket.socket; - send_signal((Sock *)pSock->next, SIGTERM); - if ( menu_client != (Sock *) 0){ - send_int(menu_client,CloseClient); - send_int(menu_client,(*plSock).Socket.pid); - } + socket_fd = pSock->next->Socket.socket; + send_signal((Sock *)pSock->next, SIGTERM); + if ( menu_client != (Sock *) 0){ + send_int(menu_client,CloseClient); + send_int(menu_client,(*plSock).Socket.pid); + } #ifdef DEBUG fprintf(stderr,"trying to clear %u\n",socket_fd); #endif - FD_CLR(socket_fd,&session_socket_mask); - locSock = pSock->next; - if ( pSock->next->next == (Sock_List *) 0 ) - { pSock->next= (Sock_List *) 0;} - else - { pSock->next = pSock->next->next;} - num_active_clients--; - active_session = (Sock *) 0; - free(locSock); - break; + FD_CLR(socket_fd,&session_socket_mask); + locSock = pSock->next; + if ( pSock->next->next == (Sock_List *) 0 ) + { pSock->next= (Sock_List *) 0;} + else + { pSock->next = pSock->next->next;} + num_active_clients--; + active_session = (Sock *) 0; + free(locSock); + break; } } #ifdef DEBUG @@ -169,9 +174,6 @@ pr(); #endif } -@ -\subsection{read\_SpadServer\_command} -<<readSpadServercommand>>= static void read_SpadServer_command(void) { @@ -199,9 +201,6 @@ read_SpadServer_command(void) } } -@ -\subsection{test\_sock\_for\_process} -<<testsockforprocess>>= static int test_sock_for_process(Sock *sock) { @@ -209,9 +208,6 @@ test_sock_for_process(Sock *sock) return kill(sock->pid, 0); } -@ -\subsection{read\_menu\_client\_command} -<<readmenuclientcommand>>= static void read_menu_client_command(void) { @@ -229,7 +225,7 @@ read_menu_client_command(void) } cmd = get_int(menu_client); switch(cmd) { - case -1: /* socket closed */ + case -1: /* socket closed */ FD_CLR(socket_fd,&session_socket_mask); menu_client = (Sock *) 0; reading_output = 0; @@ -243,9 +239,9 @@ fprintf(stderr,"menu:SwitchFrames\n"); send_int(spad_server, frame); for(i=0,pSock=plSock; pSock != (Sock_List *) 0 ; i++,pSock=pSock->next) if ((pSock->Socket.frame == frame)) { - active_session = (Sock *)pSock; - reading_output = 1; - break; + active_session = (Sock *)pSock; + reading_output = 1; + break; } if (i == num_active_clients) { /* fprintf(stderr, "Couldn't find socket for frame %d\n", frame); */ @@ -264,9 +260,6 @@ fprintf(stderr,"menu:QuerySpad\n"); } } -@ -\subsection{read\_from\_spad\_io} -<<readfromspadio>>= static void read_from_spad_io(void) { @@ -275,13 +268,10 @@ read_from_spad_io(void) if (ret_code == -1) return; if(active_session != (Sock *) 0) { ret_code = swrite(active_session, big_bad_buf, ret_code, - NULL); + NULL); } } -@ -\subsection{kill\_spad} -<<killspad>>= static void kill_spad(void) { @@ -290,8 +280,8 @@ kill_spad(void) send_signal(spad_server, SIGTERM); for (pSock=plSock,i=0; - (i<num_active_clients) && (pSock != (Sock_List *) 0); - i++,pSock=pSock->next) { + (i<num_active_clients) && (pSock != (Sock_List *) 0); + i++,pSock=pSock->next) { if ((pSock->Socket).socket != 0) send_signal((Sock *)pSock, SIGTERM); } @@ -299,9 +289,6 @@ kill_spad(void) exit(0); } -@ -\subsection{accept\_session\_connection} -<<acceptsessionconnection>>= static int accept_session_connection(Sock *server_sock) { @@ -338,12 +325,12 @@ accept_session_connection(Sock *server_sock) /* new Sock is put at the head of the list */ if (plSock == (Sock_List *)0 ) { - plSock = pls; - plSock->next = (Sock_List *)0 ; + plSock = pls; + plSock->next = (Sock_List *)0 ; } else{ - pls->next = plSock; - plSock = pls; + pls->next = plSock; + plSock = pls; } /* we need to maintain session_socket_mask here since we roll our own accept */ @@ -354,9 +341,9 @@ accept_session_connection(Sock *server_sock) active_session = (Sock *)plSock; get_string_buf(spad_server, big_bad_buf, BufSize); ret_code = swrite((Sock *)plSock, big_bad_buf, strlen(big_bad_buf)+1, - "session: writing to InterpWindow"); + "session: writing to InterpWindow"); if (ret_code == -1) - return -1; + return -1; num_active_clients++; #ifdef DEBUG pr(); @@ -366,9 +353,6 @@ pr(); return (-1); } -@ -\subsection{read\_from\_session} -<<readfromsession>>= static void read_from_session(Sock *sock) { @@ -379,14 +363,14 @@ read_from_session(Sock *sock) } active_session = sock; ret_code = sread(sock, big_bad_buf, BufSize, - "session: reading InterpWindow"); + "session: reading InterpWindow"); if (ret_code == -1) { active_session = (Sock *) 0; reading_output = 0; return; } ret_code = swrite(spad_io, big_bad_buf, ret_code, - "session: writing SessionIO"); + "session: writing SessionIO"); if (ret_code == -1) { active_session = (Sock *)0 ; reading_output = 0; @@ -395,9 +379,6 @@ read_from_session(Sock *sock) reading_output = 1; } -@ -\subsection{manage\_sessions} -<<managesessions>>= static void manage_sessions(void) { @@ -429,7 +410,7 @@ fprintf(stderr,"[rd=%u ",*((long *)rd.fds_bits)); ret_code = sselect(FD_SETSIZE, &rd, &wr, &ex, NULL); if (ret_code == -1) { - break; + break; } #ifdef DEBUG fprintf(stderr,"rd=%u]\n",*((long *)rd.fds_bits)); @@ -452,9 +433,9 @@ fprintf(stderr,"rd=%u]\n",*((long *)rd.fds_bits)); for(pSock=plSock; pSock != (Sock_List *) 0 ; pSock=pSock->next) { if ((active_session == (Sock *)pSock || !reading_output) && - (pSock->Socket).socket>0 && FD_ISSET(pSock->Socket.socket, &rd)) { - /* An InterpWindow */ - read_from_session((Sock *)pSock); } + (pSock->Socket).socket>0 && FD_ISSET(pSock->Socket.socket, &rd)) { + /* An InterpWindow */ + read_from_session((Sock *)pSock); } } @@ -464,9 +445,6 @@ fprintf(stderr,"rd=%u]\n",*((long *)rd.fds_bits)); } } -@ -\subsection{main} -<<main>>= int main(void) { @@ -486,7 +464,7 @@ main(void) else { #ifdef DEBUG fprintf(stderr, "session: connected SpadServer , fd = %d\n", - spad_server->socket); + spad_server->socket); #endif FD_SET(spad_server->socket, &session_socket_mask); } @@ -502,7 +480,7 @@ main(void) else { #ifdef DEBUG fprintf(stderr,"session: connected SessionIOName , fd = %d\n", - spad_io->socket); + spad_io->socket); #endif FD_SET(spad_io->socket, &session_socket_mask); } @@ -522,7 +500,7 @@ main(void) else { #ifdef DEBUG fprintf(stderr, "session: opened SessionServer , fd = %d\n", - server[1].socket); + server[1].socket); #endif FD_SET(server[1].socket,&session_socket_mask); } @@ -530,72 +508,4 @@ main(void) return(0); } -@ -\subsection{session} -<<session>>= -/* #define DEBUG */ -#define _SESSION_C - -<<includes>> -<<variables>> -<<usr1handler>> -<<usr2handler>> -<<termhandler>> -<<pr>> -<<closeclient>> -<<readSpadServercommand>> -<<testsockforprocess>> -<<readmenuclientcommand>> -<<readfromspadio>> -<<killspad>> -<<acceptsessionconnection>> -<<readfromsession>> -<<managesessions>> -<<main>> - -@ -\section{License} -<<license>>= -/* -Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - - Neither the name of The Numerical ALgorithms Group Ltd. nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -@ -<<*>>= -<<license>> -<<session>> -@ -\eject -\begin{thebibliography}{99} -\bibitem{1} nothing -\end{thebibliography} -\end{document} diff --git a/src/sman/sman.c.pamphlet b/src/sman/sman.c index 84243dd9..9cb3a0ba 100644 --- a/src/sman/sman.c.pamphlet +++ b/src/sman/sman.c @@ -1,43 +1,41 @@ -\documentclass{article} -\usepackage{axiom} - -\title{\$SPAD/src/sman sman} -\author{The Axiom Team} - -\begin{document} -\maketitle - -\begin{abstract} -\end{abstract} -\eject - -\tableofcontents -\eject - -\section{sman.h} -<<sman.h>>= -/* Process control definitions. Used by fork_you and spawn_of_hell */ - -/* When a process dies it kills off everything else */ -#define Die 1 -/* When a process dies, do nothing */ -#define NadaDelShitsky 2 -/* When a process dies start it up again */ -#define DoItAgain 3 -/* When hypertex dies, clean its socket */ -#define CleanHypertexSocket 4 - -typedef struct spad_proc { - int proc_id; /* process id of child */ - int death_action; /* one of the above constants */ - char *command; /* sh command line to restart the process */ - struct spad_proc *next; -} SpadProcess; - -@ -\section{sman} -\subsection{includes} -<<includes>>= +/* + Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. + All rights reserved. + + Copyright (C) 2007, Gabriel Dos Reis. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#define _SMAN_C + #include <stdlib.h> #include <unistd.h> #include <string.h> @@ -65,63 +63,29 @@ typedef struct spad_proc { #include "openpty.H1" #include "sman.H1" -@ -\subsection{variables} -We add a debug flag so we can print information about what \Tool{sman} -is trying to do. This change is pervasive as it touches nearly every -routine. -<<debugflag>>= -int tpd=0; /* to-print-debug information */ -@ -This line is no longer used. We would completely elide it except that -it would raise spurious issues about deleting credit and/or copyright -information. -\begin{verbatim} -char *start_line = -"AKCL (Austin Kyoto Common Lisp) Version(1.568) Thu Aug 22 16:49:01 EDT 1991\ -\r\nContains Enhancements by W. Schelter\r\n"; -\end{verbatim} -We modified the place where the command list lives. -The command list used to live in -\begin{verbatim} -$AXIOM/../../share/algebra/command.list -\end{verbatim} -but the open source version of the system no longer has a share -subdirectory so we move this to the lib subdirectory. -<<clefprogram>>= -char *ClefProgram = - "$AXIOM/bin/clef -f $AXIOM/lib/command.list -e "; -@ -and we change the command line arguments -<<clefprogram1>>= - ClefProgram = - strcat(ClefCommandLine, " -f $AXIOM/lib/command.list -e "); -@ -<<variables>>= char *ws_path; /* location of the AXIOM executable */ -int start_clef; /* start clef under spad */ -int start_graphics; /* start the viewman */ -int start_nagman; /* start the nagman */ -int start_ht; /* start hypertex */ -int start_spadclient; /* Start the client spad buffer */ -int start_local_spadclient; /* Start the client spad buffer */ -int use_X; /* Use the X windows environment */ -int server_num; /* AXIOM server number */ -<<debugflag>> +int start_clef; /* start clef under spad */ +int start_graphics; /* start the viewman */ +int start_ht; /* start hypertex */ +int start_spadclient; /* Start the client spad buffer */ +int start_local_spadclient; /* Start the client spad buffer */ +int use_X; /* Use the X windows environment */ +int server_num; /* AXIOM server number */ +int tpd=0; /* to-print-debug information */ /************************************************/ /* definitions of programs which sman can start */ /************************************************/ -char *GraphicsProgram = "$AXIOM/lib/viewman"; -char *NagManagerProgram = "$AXIOM/lib/nagman"; -char *HypertexProgram = "$AXIOM/lib/hypertex -s"; -<<clefprogram>> -char *SessionManagerProgram = "$AXIOM/lib/session"; -char *SpadClientProgram = "$AXIOM/lib/spadclient"; -char *PasteFile = NULL; -char *MakeRecordFile = NULL; -char *VerifyRecordFile = NULL; +char *GraphicsProgram = "$AXIOM/lib/viewman"; +char *HypertexProgram = "$AXIOM/lib/hypertex -s"; +char *ClefProgram = + "$AXIOM/bin/clef -f $AXIOM/lib/command.list -e "; +char *SessionManagerProgram = "$AXIOM/lib/session"; +char *SpadClientProgram = "$AXIOM/lib/spadclient"; +char *PasteFile = NULL; +char *MakeRecordFile = NULL; +char *VerifyRecordFile = NULL; SpadProcess *spad_process_list = NULL; /***************************/ @@ -132,7 +96,7 @@ SpadProcess *spad_process_list = NULL; char ClefCommandLine[256]; -#define BufSize 4096 /* size of communication buffer */ +#define BufSize 4096 /* size of communication buffer */ char big_bad_buf[BufSize]; /* big I/O buffer */ Sock *session_io = NULL; /* socket connecting to session manager */ @@ -156,12 +120,8 @@ struct termios oldbuf; /* the original settings */ struct termios childbuf; /* terminal structure for user i/o */ -int nagman_signal=0; int death_signal = 0; -@ -\subsection{process\_arguments} -<<processarguments>>= static void process_arguments(int argc,char ** argv) { @@ -178,10 +138,6 @@ process_arguments(int argc,char ** argv) start_graphics = 1; else if (strcmp(argv[arg], "-nogr") == 0) start_graphics = 0; - else if (strcmp(argv[arg], "-nag") == 0) - start_nagman = 1; - else if (strcmp(argv[arg], "-nonag") == 0) - start_nagman = 0; else if (strcmp(argv[arg], "-ht") == 0) start_ht = 1; else if (strcmp(argv[arg], "-noht") == 0) @@ -200,21 +156,20 @@ process_arguments(int argc,char ** argv) ws_path = "$AXIOM/etc/images/comp"; else if (strcmp(argv[arg], "-nox") == 0) { - use_X = 0; - start_local_spadclient = 1; - start_spadclient = 0; - start_ht = 0; - start_graphics = 0; + use_X = 0; + start_local_spadclient = 1; + start_spadclient = 0; + start_ht = 0; + start_graphics = 0; } else if (strcmp(argv[arg], "-grprog") == 0) GraphicsProgram = argv[++arg]; - else if (strcmp(argv[arg], "-nagprog") == 0) - NagManagerProgram = argv[++arg]; else if (strcmp(argv[arg], "-htprog") == 0) HypertexProgram = argv[++arg]; else if (strcmp(argv[arg], "-clefprog") == 0) { strcpy(ClefCommandLine,argv[++arg]); -<<clefprogram1>> + ClefProgram = + strcat(ClefCommandLine, " -f $AXIOM/lib/command.list -e "); } else if (strcmp(argv[arg], "-sessionprog") == 0) SessionManagerProgram = argv[++arg]; @@ -228,8 +183,8 @@ process_arguments(int argc,char ** argv) PasteFile = argv[++arg]; else { fprintf(stderr, "Usage: sman <-clef|-noclef> \ -<-gr|-nogr> <-ht|-noht> <-iw|-noiw> <-nag|-nonag> <-nox> <-comp> <-ws spad_workspace> \ -<-grprog path> <-htprog path> <-clefprog path> <-sessionprog path> <-nagprog path> \ +<-gr|-nogr> <-ht|-noht> <-iw|-noiw> <-nox> <-comp> <-ws spad_workspace> \ +<-grprog path> <-htprog path> <-clefprog path> <-sessionprog path> \ <-clientprog path>\n"); exit(-1); } @@ -244,10 +199,6 @@ process_arguments(int argc,char ** argv) fprintf(stderr,"-nogr "); else fprintf(stderr,"-gr "); - if (start_nagman == 0) - fprintf(stderr,"-nonag "); - else - fprintf(stderr,"-nag "); if (start_ht == 0) fprintf(stderr,"-noht "); else @@ -270,8 +221,6 @@ process_arguments(int argc,char ** argv) fprintf(stderr,"'%s' ",ws_path); fprintf(stderr,"-grprog "); fprintf(stderr,"'%s' ",GraphicsProgram); - fprintf(stderr,"-nagprog "); - fprintf(stderr,"'%s' ",NagManagerProgram); fprintf(stderr,"-htprog "); fprintf(stderr,"'%s' ",HypertexProgram); fprintf(stderr,"-clefprog "); @@ -291,18 +240,12 @@ process_arguments(int argc,char ** argv) if (tpd == 1) fprintf(stderr,"sman:process_arguments exit\n"); } -@ -\subsection{should\_I\_clef} -<<shouldIclef>>= static int should_I_clef(void) { return(1); } -@ -\subsection{in\_X} -<<inX>>= static int in_X(void) { @@ -310,24 +253,12 @@ in_X(void) return 0; } -@ -\subsection{set\_up\_defaults} -These are the default values for sman. A '1' value means that -sman will try to start the given process, a '0' value means not -starting the process. - -We do not have replacement code for the [[nagman]] process nor -do we have a copy of the [[nag fortran library]] to test the process. -Until this changes we set [[start_nagman = 0]] in order to disable -starting this process by default. -<<setupdefaults>>= static void set_up_defaults(void) { if (tpd == 1) fprintf(stderr,"sman:set_up_defaults entered\n"); start_clef = should_I_clef(); start_graphics = 1; - start_nagman = 0; start_ht = 1; start_spadclient = 0; start_local_spadclient = 1; @@ -336,9 +267,6 @@ set_up_defaults(void) if (tpd == 1) fprintf(stderr,"sman:set_up_defaults exit\n"); } -@ -\subsection{process\_options} -<<processoptions>>= static void process_options(int argc, char **argv) { @@ -348,27 +276,12 @@ process_options(int argc, char **argv) if (tpd == 1) fprintf(stderr,"sman:process_options exit\n"); } -@ -\subsection{death\_handler} -<<deathhandler>>= static void death_handler(int sig) { death_signal = 1; } -@ -\subsection{nagman\_handler} -<<nagmanhandler>>= -static void -nagman_handler(int sig) -{ - nagman_signal=1; -} - -@ -\subsection{sman\_catch\_signals} -<<smancatchsignals>>= static void sman_catch_signals(void) { @@ -383,27 +296,9 @@ sman_catch_signals(void) bsdSignal(SIGIOT, death_handler,RestartSystemCalls); bsdSignal(SIGBUS, death_handler,RestartSystemCalls); bsdSignal(SIGSEGV, death_handler,RestartSystemCalls); - /* don't restart wait call on SIGUSR1 */ - bsdSignal(SIGUSR1, nagman_handler,DontRestartSystemCalls); - /* ONLY nagman should send this. - If an error (such as C-c) interrupts a NAGLINK call, nagman - gets a signal to clean up. We need to start another nagman - almost immediately to process the next NAGLINK request. - Since nagman takes a while to clean up, we treat it specially. - nagman should send a signal (USR1) to sman. - sman should respond by spawning a new nagman. - - so nagman is NOT a DoItAgain but a NadaDelShitsky. - - The USR1 mechanism does not work for HPUX 9 - use DoItAgain - */ } -@ -\subsection{fix\_env} -insert SPADSERVER and SPADNUM variables into the environemnt -<<fixenv>>= static void fix_env(char **envp, int spadnum) { @@ -419,20 +314,17 @@ fix_env(char **envp, int spadnum) new_envp[i+2] = envp[i]; } -@ -\subsection{init\_term\_io} -<<inittermio>>= static void init_term_io(void) { if(!isatty(0)) return; if( tcgetattr(0, &oldbuf) == -1) { perror("getting termios"); - return ; /* exit(-1); */ + return ; /* exit(-1); */ } if( tcgetattr(0, &childbuf) == -1) { perror("getting termios"); - return ; /* exit(-1); */ + return ; /* exit(-1); */ } _INTR = oldbuf.c_cc[VINTR]; _QUIT = oldbuf.c_cc[VQUIT]; @@ -442,9 +334,6 @@ init_term_io(void) _EOL = oldbuf.c_cc[VEOL]; } -@ -\subsection{strPrefix} -<<strPrefix>>= static char * strPrefix(char *prefix,char * s) { @@ -456,9 +345,6 @@ strPrefix(char *prefix,char * s) return NULL; } -@ -\subsection{check\_spad\_proc} -<<checkspadproc>>= static void check_spad_proc(char *file, char *prefix) { @@ -469,15 +355,12 @@ check_spad_proc(char *file, char *prefix) if (pid > 2) { kill(pid, 0); if (kill(pid, 0) == -1 && errno == ESRCH) { - unlink(file); + unlink(file); } } } } -@ -\subsection{clean\_up\_old\_sockets} -<<cleanupoldsockets>>= static void clean_up_old_sockets(void) { @@ -486,7 +369,7 @@ clean_up_old_sockets(void) int len; sprintf(tmp_file, "/tmp/socks.%d", server_num); sprintf(com, "ls /tmp/.d* /tmp/.s* /tmp/.i* /tmp/.h* 2> %s > %s", - tmp_file, tmp_file); + tmp_file, tmp_file); system(com); file = fopen(tmp_file, "r"); if (file == NULL) { @@ -506,9 +389,6 @@ clean_up_old_sockets(void) unlink(tmp_file); } -@ -\subsection{fork\_you} -<<forkyou>>= static SpadProcess * fork_you(int death_action) { @@ -526,9 +406,6 @@ fork_you(int death_action) return proc; } -@ -\subsection{exec\_command\_env} -<<execcommandenv>>= static void exec_command_env(char *command,char ** env) { @@ -537,9 +414,6 @@ exec_command_env(char *command,char ** env) execle("/bin/sh","/bin/sh", "-c", new_command, 0, env); } -@ -\subsection{spawn\_of\_hell} -<<spawnofhell>>= static SpadProcess * spawn_of_hell(char *command, int death_action) { @@ -552,10 +426,6 @@ spawn_of_hell(char *command, int death_action) return NULL; } -@ -\subsection{start\_the\_spadclient} -run a AXIOM client in the main process -<<startthespadclient>>= static void start_the_spadclient(void) { @@ -563,31 +433,28 @@ start_the_spadclient(void) if (start_clef) #ifdef RIOSplatform sprintf(command, - "aixterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s %s", - ClefProgram, SpadClientProgram); + "aixterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s %s", + ClefProgram, SpadClientProgram); #else sprintf(command, - "xterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s %s", - ClefProgram, SpadClientProgram); + "xterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s %s", + ClefProgram, SpadClientProgram); #endif else #ifdef RIOSplatform sprintf(command, - "aixterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s", - SpadClientProgram); + "aixterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s", + SpadClientProgram); #else sprintf(command, - "xterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s", - SpadClientProgram); + "xterm -sb -sl 500 -name axiomclient -n AXIOM -T AXIOM -e %s", + SpadClientProgram); #endif if (tpd == 1) fprintf(stderr,"sman:start_the_spadclient: %s\n",command); spawn_of_hell(command, NadaDelShitsky); } -@ -\subsection{start\_the\_local\_spadclient} -<<startthelocalspadclient>>= static void start_the_local_spadclient(void) { @@ -601,31 +468,12 @@ start_the_local_spadclient(void) spawn_of_hell(command, NadaDelShitsky); } -@ -\subsection{start\_the\_nagman} -<<startthenagman>>= -static void -start_the_nagman(void) -{ -#if defined(HP9platform) - spawn_of_hell(NagManagerProgram,DoItAgain); -#else - spawn_of_hell(NagManagerProgram,NadaDelShitsky ); -#endif -} - -@ -\subsection{start\_the\_session\_manager} -<<startthesessionmanager>>= static void start_the_session_manager(void) { spawn_of_hell(SessionManagerProgram, Die); } -@ -\subsection{start\_the\_hypertex} -<<startthehypertex>>= static void start_the_hypertex(void) { @@ -643,21 +491,15 @@ start_the_hypertex(void) sprintf(prog, "%s -k -rv %s", HypertexProgram, VerifyRecordFile); spawn_of_hell(prog, NadaDelShitsky); } - else spawn_of_hell(HypertexProgram, CleanHypertexSocket); + else spawn_of_hell(HypertexProgram, CleanHypertexSocket); } -@ -\subsection{start\_the\_graphics} -<<startthegraphics>>= static void start_the_graphics(void) { spawn_of_hell(GraphicsProgram, DoItAgain); } -@ -\subsection{fork\_Axiom} -<<forkAxiom>>= /* Start the AXIOM session in a separate process, */ /* using a pseudo-terminal to catch all input and output */ static void @@ -730,9 +572,6 @@ fork_Axiom(void) } } -@ -\subsection{start\_the\_Axiom} -<<starttheAxiom>>= static void start_the_Axiom(char **envp) { @@ -751,9 +590,6 @@ start_the_Axiom(char **envp) close(ptsNum); } -@ -\subsection{clean\_up\_sockets} -<<cleanupsockets>>= static void clean_hypertex_socket(void) { @@ -775,9 +611,6 @@ clean_up_sockets(void) clean_hypertex_socket(); } -@ -\subsection{read\_from\_spad\_io} -<<readfromspadio>>= static void read_from_spad_io(int ptcNum) { @@ -793,17 +626,17 @@ read_from_spad_io(int ptcNum) mes_len -= ret_code; else { if (mes_len > 0) { - i = mes_len; - mes_len = 0; + i = mes_len; + mes_len = 0; } else - i = 0; + i = 0; ret_code = write(1, big_bad_buf+i, ret_code-i); } } else ret_code = swrite(session_io, big_bad_buf, ret_code, - "writing to session man"); + "writing to session man"); if (ret_code == -1) { perror("writing output to session manager"); clean_up_sockets(); @@ -811,9 +644,6 @@ read_from_spad_io(int ptcNum) } } -@ -\subsection{read\_from\_manager} -<<readfrommanager>>= static void read_from_manager(int ptcNum) { @@ -828,9 +658,6 @@ read_from_manager(int ptcNum) } } -@ -\subsection{manage\_spad\_io} -<<managespadio>>= static void manage_spad_io(int ptcNum) { @@ -852,17 +679,17 @@ manage_spad_io(int ptcNum) } for(i=0; i<2; i++) { if (server[i].socket > 0 && FD_ISSET(server[i].socket, &rd)) { - p = accept_connection(server+i); - switch(p) { - case SessionIO: - session_io = purpose_table[SessionIO]; - /* printf("connected session manager\n\r");*/ - printf("\n"); - break; - default: - printf("sman: Unkown connection request type: %d\n", p); - break; - } + p = accept_connection(server+i); + switch(p) { + case SessionIO: + session_io = purpose_table[SessionIO]; + /* printf("connected session manager\n\r");*/ + printf("\n"); + break; + default: + printf("sman: Unkown connection request type: %d\n", p); + break; + } } } if (session_io != NULL && FD_ISSET(session_io->socket, &rd)) { @@ -871,18 +698,12 @@ manage_spad_io(int ptcNum) } } -@ -\subsection{init\_spad\_process\_list} -<<initspadprocesslist>>= static void init_spad_process_list(void) { spad_process_list = NULL; } -@ -\subsection{print\_spad\_process\_list} -<<printspadprocesslist>>= #if 0 static void print_spad_process_list() @@ -890,13 +711,10 @@ print_spad_process_list() SpadProcess *proc; for(proc = spad_process_list; proc != NULL; proc = proc->next) fprintf(stderr, "proc_id = %d, death_action = %d\n", proc->proc_id, - proc->death_action); + proc->death_action); } #endif -@ -\subsection{find\_child} -<<findchild>>= static SpadProcess * find_child(int proc_id) { @@ -906,9 +724,6 @@ find_child(int proc_id) return NULL; } -@ -\subsection{kill\_all\_children} -<<killallchildren>>= static void kill_all_children(void) { @@ -924,18 +739,12 @@ kill_all_children(void) } -@ -\subsection{clean\_up\_terminal} -<<cleanupterminal>>= static void clean_up_terminal(void) { tcsetattr(0, TCSAFLUSH, &oldbuf); } -@ -\subsection{monitor\_children} -<<monitorchildren>>= static void monitor_children(void) { @@ -952,13 +761,6 @@ monitor_children(void) sleep(2); exit(0); } - /* Check the value of dead_baby, since wait may have returned - a pid but subsequently we have received a signal. Yeuch! */ - if(dead_baby == -1 && nagman_signal) { - nagman_signal=0; - spawn_of_hell(NagManagerProgram,NadaDelShitsky); - continue; - } if (dead_baby == -1) { fprintf(stderr, "sman: wait returned -1\n"); @@ -967,8 +769,8 @@ monitor_children(void) proc = find_child(dead_baby); if (proc == NULL) { /* fprintf(stderr, "sman: %d is not known to be a child process\n", - dead_baby); - */ + dead_baby); + */ continue; } switch(proc->death_action) { @@ -989,14 +791,6 @@ monitor_children(void) } } -@ -\subsection{main} -The main procedure should return an [[int]]. We change the return value -here and in [[src/include/sman.H1]]. -<<result>>= - return(0); -@ -<<main>>= int main(int argc, char *argv[],char *envp[]) { @@ -1015,7 +809,6 @@ main(int argc, char *argv[],char *envp[]) start_the_session_manager(); if (start_spadclient) start_the_spadclient(); if (start_local_spadclient) start_the_local_spadclient(); - if (start_nagman) start_the_nagman(); if (start_ht) start_the_hypertex(); if (start_graphics) start_the_graphics(); sleep(1); @@ -1027,95 +820,7 @@ main(int argc, char *argv[],char *envp[]) } manage_spad_io(ptcNum); if (tpd == 1) fprintf(stderr,"sman:main exit\n"); -<<result>> + return(0); } -@ -\subsection{sman} -<<sman>>= -#define _SMAN_C - -<<includes>> -<<variables>> -<<processarguments>> -<<shouldIclef>> -<<inX>> -<<setupdefaults>> -<<processoptions>> -<<deathhandler>> -<<nagmanhandler>> -<<smancatchsignals>> -<<fixenv>> -<<inittermio>> -<<strPrefix>> -<<checkspadproc>> -<<cleanupoldsockets>> -<<forkyou>> -<<execcommandenv>> -<<spawnofhell>> -<<startthespadclient>> -<<startthelocalspadclient>> -<<startthenagman>> -<<startthesessionmanager>> -<<startthehypertex>> -<<startthegraphics>> -<<forkAxiom>> -<<starttheAxiom>> -<<cleanupsockets>> -<<readfromspadio>> -<<readfrommanager>> -<<managespadio>> -<<initspadprocesslist>> -<<printspadprocesslist>> -<<findchild>> -<<killallchildren>> -<<cleanupterminal>> -<<monitorchildren>> -<<main>> - -@ -\section{License} -<<license>>= -/* -Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - - Neither the name of The Numerical ALgorithms Group Ltd. nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -@ -<<*>>= -<<license>> -<<sman>> -@ -\eject -\begin{thebibliography}{99} -\bibitem{1} nothing -\end{thebibliography} -\end{document} diff --git a/src/sman/sman.h b/src/sman/sman.h new file mode 100644 index 00000000..262b62d9 --- /dev/null +++ b/src/sman/sman.h @@ -0,0 +1,54 @@ +/* + Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. + All rights reserved. + + Copyright (C) 2007, Gabriel Dos Reis. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Process control definitions. Used by fork_you and spawn_of_hell */ + +/* When a process dies it kills off everything else */ +#define Die 1 +/* When a process dies, do nothing */ +#define NadaDelShitsky 2 +/* When a process dies start it up again */ +#define DoItAgain 3 +/* When hypertex dies, clean its socket */ +#define CleanHypertexSocket 4 + +typedef struct spad_proc { + int proc_id; /* process id of child */ + int death_action; /* one of the above constants */ + char *command; /* sh command line to restart the process */ + struct spad_proc *next; +} SpadProcess; + |