From:	MERC::"uunet!WKUVX1.BITNET!FILESERV-Mgr" 12-JUN-1992 15:41:12.02
To:	galaxy::gleeve
CC:	
Subj:	JOBLOG.05_OF_07

-+-+-+-+-+-+-+-+ START OF PART 5 -+-+-+-+-+-+-+-+
X`7D`09/*** save_log ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09retrieve_log
X
X  Purpose:`09Allow a user to retrieve JOBLOG file(s).
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09stage_dir`09`09staging directory for log files
X  `09args`09`09`09run-time arguments
X`09tt_chan`09`09`09TTY channel
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09tt_d`09`09`09`09`09X
X
X  Return Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status`09`09`09return code from user_retrieve or
X`09`09`09`09class_retrieve
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status`09`09`09couldn't assign channel to TTY
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG retrieve_log(char *stage_dir,ARG_DEF *args,USHORT *tt_chan)
X
X`7B`09/*** retrieve_log ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  status;`09`09/* return code status holder`09      */
X`09 USHORT`09  length,`09`09/* length of buf`09`09      */
X`09`09  channel;`09`09/* TTY channel`09`09`09      */
X`09 char`09  buf`5BBUFSIZ`5D;`09`09/* for storing the retrieve key`09      *
V/
X$DESCRIPTOR(buf_d,buf);`09`09`09/* for getting retrieve key string    */
X$DESCRIPTOR(class_d,"CLASS");`09`09/* to check for /CLASS`09`09      */
X$DESCRIPTOR(user_d,"USER");`09`09/* to check for /USER`09`09      */
X
X
X   /* get a channel for the TTY so my_puts() will work */
X
X   status = SYS$ASSIGN(&tt_d,tt_chan,0,0);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(status);
X
X   if(CLI$PRESENT(&class_d) == CLI$_PRESENT)
X   `7B
X      /* get the class string */
X
X      status = CLI$GET_VALUE(&class_d,&buf_d,&length);
X
X      if(status == SS$_NORMAL)
X      `7B
X`09 buf`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X`09 status = class_retrieve(stage_dir,buf);
X      `7D
X      else
X`09 status = FAILURE;
X   `7D
X   else if(CLI$PRESENT(&user_d) == CLI$_PRESENT)
X   `7B
X      /* get the user string */
X
X      status = CLI$GET_VALUE(&user_d,&buf_d,&length);
X
X      if(status == SS$_NORMAL)
X      `7B
X`09 buf`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X`09 status = user_retrieve(stage_dir,buf);
X      `7D
X      else
X`09 status = FAILURE;
X   `7D
X
X   return(status);
X
X`7D`09/*** retrieve_log ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09user_retrieve
X
X  Purpose:`09Allow a user to retrieve a JOBLOG file that s/he "owns".
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09stage_dir`09`09staging directory for log files
X`09from`09`09`09user who sent the log file
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09SUCCESS
X`09FAILURE
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG user_retrieve(char *stage_dir,char *from)
X
X`7B`09/*** user_retrieve ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  fcontext,`09`09/* file context for getting file      */
X`09`09  status;`09`09/* return code status holder`09      */
X`09 char`09  *tptr;`09`09/* temporary character pointer`09      */
X`09 USHORT`09  verified;`09`09/* set if log is VERIFIED`09      */
X`09 char`09  newfile`5BNAM$C_MAXRSS+1`5D, /* what to copy logfile to`09
V      */
X`09`09  username`5BUSERNAME_MAX+1`5D, /* who sent the log file`09      */
X`09`09  recipient`5BUSERNAME_MAX+1`5D, /* who the log file was sent to  */
X`09`09  filename`5BNAM$C_MAXRSS+1`5D, /* for wildcard searching`09      */
X`09`09  logfile`5BNAM$C_MAXRSS+1`5D, /* logfile name`09`09      */
X`09`09  tempbuf`5BTEMPBUF_MAX+1`5D;
X$DESCRIPTOR(file_d,filename);
X$DESCRIPTOR(file2_d,logfile);
X
X
X   /* make the wildcard filename to be used */
X
X   cat(filename,stage_dir,from,"_",getenv("USER"),"_*.*");
X  `20
X   file_d.dsc$w_length = (USHORT) strlen(filename);
X   fcontext = 0L;
X
X   /* see if the file exists */
X
X   status = LIB$FIND_FILE(&file_d,&file2_d,&fcontext);
X
X   if(status != RMS$_NORMAL)
X   `7B
X      cat(tempbuf,"\n\7No log file for you from user ",from,"\n\n",from);
X      my_puts(tempbuf);
X      return(FAILURE);
X   `7D
X
X   tptr = strchr(logfile,' ');`09`09/* find the end of the filename`09
V      */
X   *tptr = '\0';`09`09`09/* make the filename a string`09      */
X
X   /* find out if the log file was verified */
X
X   parse_filename(logfile,NULL,NULL,&verified);
X
X   if(verified)
X      cat(newfile,from,".JOBLOG");
X   else
X      cat(newfile,from,".UNVERIFIED_JOBLOG");
X
X   /* copy the log file to user's area   */
X
X   status = copy_file(logfile,newfile,FALSE);
X
X   if(status == SUCCESS)
X   `7B
X      delete_log(logfile);
X      cat(tempbuf,"\n\nJOBLOG from user ",from," successfully retrieved.\n")
V;
X      my_puts(tempbuf);
X      cat(tempbuf,"The file is ",newfile,".\n\n");
X      my_puts(tempbuf);
X   `7D
X   else
X   `7B
X      cat(tempbuf,"\n\7*ERROR* retrieving JOBLOG from user ",from,".\n");
X      my_puts(tempbuf);
X   `7D
X
X   return(status);
X
X`7D`09/*** user_retrieve ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09class_retrieve
X
X  Purpose:`09Allow a user to retrieve JOBLOG file(s) for an entire class.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09stage_dir`09`09staging directory for log files
X`09class`09`09`09class to be retrieved
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09SUCCESS
X`09FAILURE
X
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG class_retrieve(char *stage_dir,char *class)
X
X`7B`09/*** class_retrieve ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  fcontext,`09`09/* file context for getting file      */
X`09`09  status;`09`09/* return code status holder`09      */
X`09 char`09  *name_ptr,`09`09/* pointer to filename of logfile     */
X`09`09  *tptr;`09`09/* temporary character pointer`09      */
X`09 USHORT`09  count = 0,`09`09/* number of files retrieved`09      */
X`09`09  length,`09`09/* length of formatted string`09      */
X`09`09  verified;`09`09/* set if log file is VERIFIED`09      */
X`09 char`09  newfile`5BNAM$C_MAXRSS+1`5D, /* what to copy logfile to`09
V      */
X`09`09  username`5BUSERNAME_MAX+1`5D, /* who sent the log file`09      */
X`09`09  filename`5BNAM$C_MAXRSS+1`5D, /* for wildcard searching`09      */
X`09`09  logfile`5BNAM$C_MAXRSS+1`5D, /* logfile name`09`09      */
X`09`09  tempbuf`5BTEMPBUF_MAX+1`5D;
X$DESCRIPTOR(file_d,filename);
X$DESCRIPTOR(file2_d,logfile);
X$DESCRIPTOR(format_d,"\n\n!ZW files retrieved for class !AD.\n\n");
X$DESCRIPTOR(buffer_d,tempbuf);
X
X
X   /* create the wildcard name for retrieving files */
X
X   squeeze_str(class);`09`09`09/* make sure class is free of spaces  */
X   cat(filename,stage_dir,"*_",getenv("USER"),"_",class,".*JOBLOG*;*");
X   file_d.dsc$w_length = (USHORT) strlen(filename);
X   fcontext = 0L;
X
X   status = LIB$FIND_FILE(&file_d,&file2_d,&fcontext);
X
X   while(status == RMS$_NORMAL)
X   `7B
X      count++;`09`09`09`09/* count it`09`09`09      */
X      tptr = strchr(logfile,' ');
X      *tptr = '\0';`09`09`09/* make filename a real string`09      */
X
X      name_ptr = strchr(logfile,'`5D') + 1L; /* skip past directory spec`09
V      */
X
X      /* create the filename that the log file is to be copied to */
X
X      parse_filename(name_ptr,username,NULL,&verified);
X
X      if(verified)
X`09 cat(newfile,username,".JOBLOG");
X      else
X`09 cat(newfile,username,".UNVERIFIED_JOBLOG");
X
X      if(copy_file(logfile,newfile,FALSE) == SUCCESS)
X`09 delete_log(logfile);
X      else
X      `7B
X`09 cat(tempbuf,"\n\n\7*ERROR* copying log file ",logfile,
X`09     " to your area\n");
X      `7D
X
X      status = LIB$FIND_FILE(&file_d,&file2_d,&fcontext);
X   `7D
X
X   if(status == RMS$_FNF)
X   `7B
X      cat(tempbuf,"\7\n\nNo JOBLOG files for you from class ",class,"\n\n");
X      my_puts(tempbuf);
X      return;
X   `7D
X
X   if(status != RMS$_NMF)`09`09/* did we stop for the right reason?  */
X      LIB$STOP(status);`09`09`09/* nope.....`09`09`09      */
X
X   /* terminate the "finding" of files */
X
X   status = LIB$FIND_FILE_END(&fcontext);
X
X   if((status != SS$_NORMAL) && (status != RMS$_NORMAL))
X      LIB$STOP(status);
X
X   status = SYS$FAO(&format_d,&length,&buffer_d,count,(ULONG) strlen(class),
X`09`09    class);
X
X   if(!(status & SS$_NORMAL))
X      LIB$SIGNAL(status);
X
X   tempbuf`5Blength`5D = '\0';
X   my_puts(tempbuf);
X
X   return;
X
X`7D`09/*** class_retrieve ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09delete_mlog
X
X  Purpose:`09Allow a user to delete JOBLOG file(s) from the staging area.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09stage_dir`09`09staging directory for log files
X`09tt_chan`09`09`09for getting a channel to the TTY
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09tt_d`09`09`09`09`09X
X`09JLG_CANT_DELETE_LOG`09`09`09X
X
X  Return Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09SUCCESS
X`09FAILURE
X
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG delete_mlog(char *stage_dir,USHORT *tt_chan)
X
X`7B`09/*** delete_mlog ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  status,`09`09/* return code status holder #1`09      */
X`09`09  status2,`09`09/*   "     "     "      "    #2`09      */
X`09`09  fcontext;`09`09/* context for FINDing files`09      */
X`09 USHORT`09  length;`09`09/* length of buffer`09`09      */
X`09 char`09  *username,`09`09/* name of user doing the deleting    */
X`09`09  *tptr,`09`09/* temporary character pointer`09      */
X`09`09  filename`5BNAM$C_MAXRSS+1`5D, /* logfile name`09`09      */
X`09`09  logfile`5BNAM$C_MAXRSS+1`5D, /* output of LIB$FIND_FILE`09      */
X`09`09  command`5BCOMMAND_MAX+1`5D, /* MAIL command buffer`09      */
X`09`09  buffer`5BBUFSIZ+1`5D;`09/* buffer for reading from TTY`09      */
X$DESCRIPTOR(command_d,command);
X$DESCRIPTOR(delete_d,"DELETE");
X$DESCRIPTOR(buf_d,buffer);
X$DESCRIPTOR(null_d,"");
X$DESCRIPTOR(file_d,"");
X$DESCRIPTOR(file2_d,"");
X$DESCRIPTOR(prompt_d,"");
X
X
X   /* get the name of the user to whom the log file was mailed */
X
X   status = CLI$GET_VALUE(&delete_d,&buf_d,&length);
X
X   if(status == SS$_NORMAL)
X      buffer`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X   else
X   `7B
X      /* need a channel to the TTY here */
X
X      status = SYS$ASSIGN(&tt_d,tt_chan,0,0);
X
X      if(!(status & SS$_NORMAL))
X`09 LIB$STOP(status);
X
X      status = my_gets(*tt_chan,buffer,
X`09`09       "\n\nWho was the log file originally mailed to: ",
X`09`09       &length,(USHORT) sizeof(buffer));
X
X      if(status == CANCEL)
X`09 return(SUCCESS);
X
X      *(buffer + strlen(buffer) - 1) = '\0'; /* get rid of newline `09
V      */
X      strlu(buffer);`09`09`09/* conver to all uppercase`09      */
X   `7D
X
X   username = getenv("USER");
X
X   /* create the wildcard filespec that we'll use to check for log files */
X
X   cat(filename,stage_dir,username,"_",buffer,"_*.*JOBLOG_*");
X
X   file_d.dsc$a_pointer = filename;
X   file_d.dsc$w_length = (USHORT) strlen(filename);
X   file2_d.dsc$a_pointer = logfile;
X   file2_d.dsc$w_length = (USHORT) NAM$C_MAXRSS+1;
X   fcontext = 0L;
X   status2 = SUCCESS;
X
X   status = LIB$FIND_FILE(&file_d,&file2_d,&fcontext);
X
X   while(status == RMS$_NORMAL && status2 == SUCCESS)
X   `7B
X      tptr = strchr(logfile,' ');
X      *tptr = '\0';`09`09`09/* make filename a real string`09      */
X
X      if(delete_log(logfile) == FAILURE) /* try to delete the file`09      *
V/
X`09 LIB$SIGNAL(JLG_CANT_DELETE_LOG,1L,logfile);
X      else
X      `7B
X`09 cat(command,"$MAIL/SUBJECT=\"JOBLOG from ",username,
X`09     " has been deleted\"\ NL: ",buffer);
X
X`09 command_d.dsc$w_length = (USHORT) strlen(command);
X
X`09 /* now try to spawn the command to mail the notice */
X
X`09 status = LIB$SPAWN(&command_d,&null_d,&null_d,NULL,NULL,0L,&status2,
X`09`09`09    0L,0L,0L,0L,NULL,NULL);
X
X`09 if(!(status & SS$_NORMAL))
X`09    LIB$SIGNAL(JLG_NO_SPAWN);
X
X`09 cat(command,"\nLogfile for user ",buffer," deleted.\n");
X`09 my_puts(command);
X      `7D
X
X      status = LIB$FIND_FILE(&file_d,&file2_d,&fcontext);
X   `7D
X
X   if(status == RMS$_FNF)
X   `7B
X      cat(command,"\7\n\nYou don't have any JOBLOG files for ",buffer,
X`09  " pending.\n\n");
X      my_puts(command);
X      return(FAILURE);
X   `7D
X   else`09if(status != RMS$_NMF)`09`09/* did we stop for the right reason?
V  */
X      LIB$SIGNAL(status);`09`09/* nope.....`09`09`09      */
X
X   /* don't care if these fail because we'll be exiting shortly */
X
X   status = LIB$FIND_FILE_END(&fcontext);
X   status = SYS$SETPRV(OFF,&privs,FALSE,NULL);
X
X   return(SUCCESS);
X
X`7D  `09/*** delete_mlog ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09get_logicals
X
X  Purpose:`09Translate the logicals for JOBLOG$STAGE and JOBLOG$LOG
X`09`09and save them for later.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09log_dir`09`09`09where to store translation of JOBLOG$LOG
X`09stage_dir`09`09where to store translation of JOBLOG$STAGE
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09none
X
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09JLG_NO_LOGICAL`09`09system logicals are not defined
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void get_logicals(char *log_dir,char *stage_dir)
X
X`7B`09/*** get_logicals ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X       `09 ULONG`09  status;`09`09/* return code status holder`09      */
X`09 USHORT`09  length;`09`09/* length of resulting string`09      */
X`09 ITM_LST  items`5B`5D = `7B`09`09/* items obtained during translation  */
X`7B0,LNM$_STRING,NULL,NULL`7D,`09`09/* things are filled in below`09      */
X`7B0,0,NULL,NULL`7D`7D;
X$DESCRIPTOR(table_d,"LNM$SYSTEM");
X$DESCRIPTOR(logdir_d,"JOBLOG$LOG");
X$DESCRIPTOR(stagedir_d,"JOBLOG$STAGE");
X
X
X   items`5B0`5D.buf_len = NAM$C_MAXRSS;
X   items`5B0`5D.buf_addr = log_dir;
X   items`5B0`5D.ret_len = &length;`09`09/* store it right back in length
V      */
X
X   status = SYS$TRNLNM(0,&table_d,&logdir_d,0,items);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(JLG_NO_LOGICAL,1L,logdir_d.dsc$a_pointer);
X
X   *(log_dir + length) = '\0';`09`09/* terminate it`09`09`09      */
X
X   items`5B0`5D.buf_addr = stage_dir;
X
X   status = SYS$TRNLNM(0,&table_d,&stagedir_d,0,items);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(JLG_NO_LOGICAL,1L,stagedir_d.dsc$a_pointer);
X
X   *(stage_dir + length) = '\0';`09/* terminate it`09`09`09      */
X   return;
X
X`7D`09/*** get_logicals ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09ctrly_trap
X
X  Purpose:`09Set up the AST for trapping control-Y.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09channel`09`09`09TTY channel
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09SUCCESS`09`09`09successful completion
X`09FAILURE`09`09`09unable to set control-Y AST
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG ctrly_trap(USHORT channel)
X
X`7B`09/*** ctrly_trap ***/
X
X   if(SYS$QIOW(0,channel,IO$_SETMODE `7C IO$M_CTRLYAST,0,0,0,ctrly_ast,0,
X`09       0,0,0,0) != SS$_NORMAL)
X      return(FAILURE);
X
X   return(SUCCESS);
X
X`7D`09/*** ctrly_trap ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09ctrly_ast
X
X  Purpose:`09AST routine alled when control-Y is detected.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09none
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09none
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void ctrly_ast(void)
X
X`7B`09/*** ctrly_ast ***/
X
X   ctrly_trap(tt_chan);     `20
X   return;
X
X`7D`09/*** ctrly_ast ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09ctrlc_trap
X
X  Purpose:`09Set up the AST for trapping control-C.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09none
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09tt_chan`09`09`09`09`09X
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09SUCCESS`09`09`09successful completion
X`09FAILURE`09`09`09unable to set control-C AST
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic ULONG ctrlc_trap(void)
X
X`7B`09/*** ctrlc_trap ***/
X
X   if(SYS$QIOW(0,tt_chan,IO$_SETMODE `7C IO$M_CTRLCAST,0,0,0,ctrlc_ast,0,
X`09       0,0,0,0) != SS$_NORMAL)
X      return(FAILURE);
X
X   return(SUCCESS);
X
X`7D`09/*** ctrlc_trap ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09ctrlc_ast
X
X  Purpose:`09AST routine alled when control-C is detected.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09none
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09none
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void ctrlc_ast(void)
X
X`7B`09/*** ctrlc_ast ***/
X
X   ctrlc_trap();`09`09`09/* reset the control-C AST`09      */
X   return;
X
X`7D`09/*** ctrlc_ast ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09joblog_check
X
X  Purpose:`09Make sure that the user isn't already running JOBLOG.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09none
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09JLG_INUSE`09`09`09`09X
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09none
X
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void joblog_check(void)
X
X`7B`09/*** joblog_check ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  status,`09`09/* return code status holder`09      */
X`09`09  owner;`09`09/* parent process PID`09`09      */
X`09 long`09  item_code;`09`09/* for LIB$GETJPI()'s sake`09      */
X`09 short`09  length;`09`09/* length of process name`09      */
X`09 char`09  procname`5BPNAME_MAX+1`5D,/* current process name array`09
V      */
X`09`09  newpname`5BPNAME_MAX+1`5D;/* process name for JOBLOG subprocess */
X$DESCRIPTOR(procname_d,procname);`09/* for getting process name`09      */
X$DESCRIPTOR(newpname_d,newpname);`09/* for creating new process name      */
X$DESCRIPTOR(format_d,"JOBLOG_!XL");`09/* for formatting test process name
V   */
X
X
X   /* make sure that the user doesn't run JOBLOG while they are already in
X    * JOBLOG
X    */
X
X   item_code = JPI$_PRCNAM;
X   status = LIB$GETJPI(&item_code,0,0,0,&procname_d,&length);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(status);
X
X   procname`5Blength`5D = '\0';
X
X   item_code = JPI$_OWNER;
X   status = LIB$GETJPI(&item_code,0,0,&owner,0,0);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(status);
X
X   /* create what would the process name be if the user ran JOBLOG while
X    * in JOBLOG
X    */
X
X   status = SYS$FAO(&format_d,&length,&newpname_d,owner & 0xFFFF);
X
X   if(!(status & SS$_NORMAL))
X      LIB$STOP(status);
X
X   newpname`5Blength`5D = '\0';
X
X   if(!strcmp(newpname,procname))
X      LIB$STOP(JLG_INUSE);
X
X   return;
X
X`7D`09/*** joblog_check ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09skim
X
X  Purpose:`09Skim the JOBLOG staging directory for old JOBLOG files, de-
X`09`09leting them if they are older than the /WAIT value and warning
X`09`09senders if they are older then the /WARN value.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09stage_dir`09`09staging directory for mailed log files
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09none
X
X  Termination Codes:
X
X`09Code`09 `09`09Reason
X`09----`09`09`09------
X`09status
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void skim(char *stage_dir)
X
X`7B`09/*** skim ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 char`09  *ptr;`09`09`09/* for skipping dev/directory spec    */
X`09 ULONG`09  fcontext,`09`09/* file context for getting file      */
X`09`09  status,`09`09/* return code status holder`09      */
X`09`09  wait_days,`09`09/* # days before deleting log`09      */
X`09`09  warn_days;`09`09/* # days before warning people`09      */
X`09 long`09  delete_time;`09`09/* time in secs when file is deleted  */
X`09 time_t`09  cur_time,`09`09/* current time value`09`09      */
X`09`09  elapsed_time;`09`09/* current time - file creation time  */
X`09 USHORT`09  length;`09`09/* for trimming trailing blanks`09      */
Xstruct`09 stat`09  statbuf;`09`09/* for getting file's age`09      */
Xstruct`09 tm`09  *del_tm;`09`09/* for getting delete date`09      */
X`09 char`09  wildname`5BNAM$C_MAXRSS+1`5D,
X`09`09  filename`5BNAM$C_MAXRSS+1`5D,
X`09`09  buf`5BINT_STR_MAX+1`5D;`09/* for getting int strings`09      */
X$DESCRIPTOR(wild_d,wildname);
X$DESCRIPTOR(file_d,filename);
X$DESCRIPTOR(wait_d,"WAIT");
X$DESCRIPTOR(warn_d,"WARN");
X$DESCRIPTOR(buf_d,buf);
X
X
X   if(CLI$PRESENT(&wait_d) == CLI$_PRESENT)
X   `7B
X      /* get the class string */
X
X      status = CLI$GET_VALUE(&wait_d,&buf_d,&length);
X
X      if(status == SS$_NORMAL)
X`09 buf`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X      else
X`09 LIB$STOP(status);
X
X      wait_days = (ULONG) atol(buf);
X   `7D
X
X   if(CLI$PRESENT(&warn_d) == CLI$_PRESENT)
X   `7B
X      /* get the class string */
X
X      status = CLI$GET_VALUE(&warn_d,&buf_d,&length);
X
X      if(status == SS$_NORMAL)
X`09 buf`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X      else
X`09 LIB$STOP(status);
X
X      warn_days = (ULONG) atol(buf);
X   `7D
X
X   fcontext = 0L;
X   time(&cur_time);
X   strcpy(wildname,stage_dir);
X   strcat(wildname,"*.*;*");`09`09/* look at all files`09`09      */
X   wild_d.dsc$w_length = (USHORT) strlen(wildname);
X
X   status = LIB$FIND_FILE(&wild_d,&file_d,&fcontext);
X
X   while(status == RMS$_NORMAL)
X   `7B
X      length = 0;
X
X      while(length < NAM$C_MAXRSS && filename`5Blength`5D != ' ')
X         ++length;
X
X      filename`5Blength`5D = '\0';`09`09/* make it a string`09`09      */
X      stat(filename,&statbuf);`09`09/* to find out how old it is`09      */
X
X      /* should we delete or warn the sender and recipient? */
X
X      elapsed_time = cur_time - statbuf.st_atime;
X
X      if(elapsed_time > (wait_days * SECONDS_IN_DAY))
X`09 delete_log(filename);
X      else if(elapsed_time > (warn_days * SECONDS_IN_DAY) &&
X`09      elapsed_time <= (warn_days + 1) * SECONDS_IN_DAY)
X      `7B
X`09 delete_time = (long) statbuf.st_ctime + (wait_days * SECONDS_IN_DAY);
X`09 del_tm = localtime(&delete_time);
X`09 ptr = (char *) (strchr(filename,'`5D') + 1L);
X`09 warn(ptr,statbuf.st_ctime,del_tm->tm_mon,del_tm->tm_mday,
X`09      del_tm->tm_year);
X      `7D
X
X      status = LIB$FIND_FILE(&wild_d,&file_d,&fcontext);
X   `7D
X
X   return;
X
X`7D`09/*** skim ***/
X`0C
X/***************************************************************************
V****
X****************************************************************************
V****
X
X  Function:`09warn
X
X  Purpose:`09Warn the sender and recipient of a logfile.
X
X  Formal Parameters:
X
X`09Name`09`09`09Description
X`09----`09`09`09-----------
X`09filename`09`09log file name
X`09create_time`09`09when log file was created
X`09month,day,year`09`09date when log file will be deleted
X
X  Global variables:
X
X`09Name`09`09`09Examine/Modify/Use/Read/Write
X`09----`09`09`09-----------------------------
X`09none
X
X  Return Codes:
X
X`09Code`09`09`09Reason
X`09----`09`09`09------
X`09none
X
X****************************************************************************
V****
X****************************************************************************
V***/
X
Xstatic void warn(char *filename,UINT create_time,int month,int day,int year)
X
X`7B`09/*** warn ***/
X`09`09`09`09`09/********   LOCAL  VARIABLES   ********/
X`09 ULONG`09  status,`09`09/* return code status holder`09      */
X`09`09  status2;
X`09 USHORT`09  verified,`09`09/* set if log file is verified`09      */
X`09`09  length;`09`09/* length of formatted string`09      */
X`09 char`09  username`5BUSERNAME_MAX+1`5D,
X`09`09  recipient`5BUSERNAME_MAX+1`5D,
+-+-+-+-+-+-+-+-  END  OF PART 5 +-+-+-+-+-+-+-+-
