Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
netproc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  NETPROC
struct  pserver

Defines

#define LHOSTNAME   "localhost" /* accepted name for local host */
#define pserverOK(ps)   (wait4job(ps, startjob(ps, "true", NULL)) == 0)

Typedefs

typedef struct pserver PSERVER
typedef int pscompfunc (PSERVER *ps, int pn, int status)

Functions

PSERVERaddpserver (char *host, char *dir, char *usr, int np)
void delpserver (PSERVER *ps)
PSERVERfindjob (int *pnp)
int startjob (PSERVER *ps, char *command, pscompfunc *compf)
int wait4job (PSERVER *ps, int pid)

Variables

PSERVERpslist

Class Documentation

struct pserver

Definition at line 23 of file netproc.h.

Collaboration diagram for pserver:
Class Members
char directory
char hostname
struct pserver * next
short nprocs
NETPROC proc
char username

Define Documentation

#define LHOSTNAME   "localhost" /* accepted name for local host */

Definition at line 42 of file netproc.h.

#define pserverOK (   ps)    (wait4job(ps, startjob(ps, "true", NULL)) == 0)

Definition at line 44 of file netproc.h.


Typedef Documentation

typedef int pscompfunc(PSERVER *ps, int pn, int status)

Definition at line 37 of file netproc.h.

typedef struct pserver PSERVER

Function Documentation

PSERVER* addpserver ( char *  host,
char *  dir,
char *  usr,
int  np 
)

Definition at line 41 of file netproc.c.

{
       register PSERVER     *ps;
                                   /* allocate the struct */
       if (np < 1)
              return(NULL);
       ps = (PSERVER *)malloc(sizeof(PSERVER)+(np-1)*sizeof(NETPROC));
       if (ps == NULL)
              return(NULL);
       if (!ourhost[0]) {          /* initialize */
              char   dirtmp[PATH_MAX];
              register char *cp;
              register int  len;

              strcpy(ourhost, myhostname());
              getcwd(dirtmp, sizeof(dirtmp));
              if ((cp = getenv("HOME")) != NULL) {
                     if (!strcmp(cp, dirtmp))
                            ourdir[0] = '\0';
                     else if (!strncmp(cp, dirtmp, len=strlen(cp)) &&
                                   dirtmp[len] == '/')
                            strcpy(ourdir, dirtmp+len+1);
                     else
                            strcpy(ourdir, dirtmp);
              } else
                     strcpy(ourdir, dirtmp);
              if ((cp = getenv("USER")) != NULL)
                     strcpy(ouruser, cp);
              if ((ourshell = getenv("SHELL")) == NULL)
                     ourshell = "/bin/sh";
              FD_ZERO(&errdesc);
              maxfd = -1;
       }
                                   /* assign host, directory, user */
       if (host == NULL || !strcmp(host, ourhost) ||
                     !strcmp(host, LHOSTNAME))
              ps->hostname[0] = '\0';
       else
              strcpy(ps->hostname, host);
       if (dir == NULL)
              strcpy(ps->directory, ourdir);
       else
              strcpy(ps->directory, dir);
       if (usr == NULL || !strcmp(usr, ouruser))
              ps->username[0] = '\0';
       else
              strcpy(ps->username, usr);
                                   /* clear process slots */
       ps->nprocs = np;
       while (np--) {
              ps->proc[np].com = NULL;
              ps->proc[np].pid = -1;
              ps->proc[np].efd = -1;
              ps->proc[np].errs = NULL;
              ps->proc[np].elen = 0;
              ps->proc[np].cf = NULL;
       }
                                   /* insert in our list */
       ps->next = pslist;
       pslist = ps;
                                   /* check for signs of life */
       if (!pserverOK(ps)) {
              delpserver(ps);                    /* failure -- abort */
              return(NULL);
       }
       return(ps);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void delpserver ( PSERVER ps)

Definition at line 116 of file netproc.c.

{
       PSERVER       pstart;
       register PSERVER     *psp;
       register int  i;
                                   /* find server in our list */
       pstart.next = pslist;
       for (psp = &pstart; ps != psp->next; psp = psp->next)
              if (psp->next == NULL)
                     return;                     /* not in our list! */
                                   /* kill any running jobs */
       for (i = 0; i < ps->nprocs; i++)
              if (ps->proc[i].com != NULL) {
                     kill(SIGTERM, ps->proc[i].pid);
                     wait4job(ps, ps->proc[i].pid);
              }
                                   /* remove server from list */
       psp->next = ps->next;
       pslist = pstart.next;
       free((void *)ps);           /* free associated memory */
}

Here is the call graph for this function:

Here is the caller graph for this function:

PSERVER* findjob ( int *  pnp)

Definition at line 109 of file win_netproc.c.

{
       static PSERVER ps;
       return &ps;
}
int startjob ( PSERVER ps,
char *  command,
pscompfunc compf 
)

Definition at line 116 of file win_netproc.c.

{
       return 0;
}
int wait4job ( PSERVER ps,
int  pid 
)

Definition at line 325 of file netproc.c.

{
       int    status, psn, psn2;
       PSERVER       *ps2;

       if (pid == -1) {                   /* wait for first job */
              if (ps != NULL) {
                     for (psn = ps->nprocs; psn--; )
                            if (ps->proc[psn].com != NULL)
                                   break;
                     if (psn < 0)
                            return(-1);   /* no processes this server */
              }
              do {
                     wait4end();          /* wait for something to end */
                     if ((psn2 = wait(&status)) == -1)
                            return(-1);   /* none left */
                     ps2 = findjob(&psn2);
                     if (ps2 != NULL)     /* clean up job if ours */
                            status = finishjob(ps2, psn2, status);
              } while (ps2 == NULL || (ps != NULL && ps2 != ps));
              return(status);                    /* return job status */
       }
       psn = pid;                         /* else find specific job */
       ps2 = findjob(&psn);               /* find process slot */
       if (ps2 == NULL || (ps != NULL && ps2 != ps))
              return(-1);          /* inconsistent target */
       ps = ps2;
       do {
              wait4end();                 /* wait for something to end */
              if ((psn2 = wait(&status)) == -1)
                     return(-1);          /* none left */
              ps2 = findjob(&psn2);
              if (ps2 != NULL)            /* clean up job if ours */
                     status = finishjob(ps2, psn2, status);
       } while (ps2 != ps || psn2 != psn);
       return(status);                           /* return job status */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 21 of file netproc.c.