[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
[0415]
[0416]
[0417]
[0418]
[0419]
[0420]
[0421]
[0422]
[0423]
[0424]
[0425]
[0426]
[0427]
[0428]
[0429]
[0430]
[0431]
[0432]
[0433]
[0434]
[0435]
[0436]
[0437]
[0438]
[0439]
[0440]
[0441]
[0442]
[0443]
[0444]
[0445]
[0446]
[0447]
[0448]
[0449]
[0450]
[0451]
[0452]
[0453]
[0454]
[0455]
[0456]
[0457]
[0458]
[0459]
[0460]
[0461]
[0462]
[0463]
[0464]
[0465]
[0466]
[0467]
[0468]
[0469]
[0470]
[0471]
[0472]
[0473]
[0474]
[0475]
[0476]
[0477]
[0478]
[0479]
[0480]
[0481]
[0482]
[0483]
[0484]
[0485]
[0486]
[0487]
[0488]
[0489]
[0490]
[0491]
[0492]
[0493]
[0494]
[0495]
[0496]
[0497]
[0498]
[0499]
[0500]
[0501]
[0502]
[0503]
[0504]
[0505]
[0506]
[0507]
[0508]
[0509]
[0510]
[0511]
[0512]
[0513]
[0514]
[0515]
[0516]
[0517]
[0518]
[0519]
[0520]
[0521]
[0522]
[0523]
[0524]
[0525]
[0526]
[0527]
[0528]
[0529]
[0530]
[0531]
[0532]
[0533]
[0534]
[0535]
[0536]
[0537]
[0538]
[0539]
[0540]
[0541]
[0542]
[0543]
[0544]
[0545]
[0546]
[0547]
[0548]
[0549]
[0550]
[0551]
[0552]
[0553]
[0554]
[0555]
[0556]
[0557]
[0558]
[0559]
[0560]
[0561]
[0562]
[0563]
[0564]
[0565]
[0566]
[0567]
[0568]
[0569]
[0570]
[0571]
[0572]
[0573]
[0574]
[0575]
[0576]
[0577]
[0578]
[0579]
[0580]
[0581]
[0582]
[0583]
[0584]
[0585]
[0586]
[0587]
[0588]
[0589]
[0590]
[0591]
[0592]
[0593]
[0594]
[0595]
[0596]
[0597]
[0598]
[0599]
[0600]
[0601]
[0602]
[0603]
[0604]
[0605]
[0606]
[0607]
[0608]
[0609]
[0610]
[0611]
[0612]
[0613]
[0614]
[0615]
[0616]
[0617]
[0618]
[0619]
[0620]
[0621]
[0622]
[0623]
[0624]
[0625]
[0626]
[0627]
[0628]
[0629]
[0630]
[0631]
[0632]
[0633]
[0634]
/*****************************************************************************/
/*
                                  WAStee.c

WAStee is a utility to generate time-stamped log files containing intervals of
a long-lived WASD server process, and/or to consolidate all process log files
generated during the defined period.  It is the tee in a PIPE sequence.
And yes, an intended (somewhat lame) homophone.

The log files are generated as WASD_SERVER_LOGS:node_yyyymmdd.LOG and
reflect a shortened file name of the default, primary server log file. 
Alternate location for the log files may be specified using the logical name
WASTEE_LOCATION.  SYSPRV is used to create the file so the account must
possess that privilege, or the image INSTALLed with it, and the location permit
SYSPRV write access.

This utility is UNSUITABLE for sites using multiple instances and/or
environments on a node.  Only the first of multiple server processes will have
the log teed.  Subsequent processes see a message of the ilk:

%WASTEE-E-OPEN, 14-MAR-2021 01:28:11 WASD_SERVER_LOGS:KLAATU_20210308.LOG
-WASTEE-E-ERROR, file currently locked by another user

The teed logs may be identified (and distinguished from primary logs) using

  WASD_SERVER_LOGS:*_%%%%%%%%.LOG

Both the teed log file and primary log file have a %WASTEE-I-OPEN dd-mmm-yyyy
hh:mm:ss timestamp inserted each time a log file is opened (i.e. on interval
rollover and server startup), and a complementary %WASTEE-I-CLOSE at exit.

Intervals supported; DAILY, WEEKLY (default), MONTHLY. 

Interval can be changed from default by logical name WASTEE_INTERVAL.

Weekly days are 1..7 (Mon..Sun) defaulting to Mon.  The WASTEE_INTERVAL logical
name will accept a digit representing the weekday on which to rollover the log. 
For example, to rollover on Saturday

  $ DEFINE /SYSTEM WASTEE_INTERVAL WEEKLY6

The log file location may be specified using logical name WASTEE_LOCATION.

  $ DEFINE /SYSTEM WASTEE_LOCATION WASD_ROOT:[LOG_SERVER]

NOTE: just to emphasise; unlike the regular process logs where a new file is
created each time the [STARTUP]STARTUP.COM procedure is executed, these teed
logs accumulate any and all startups within the interval being logged.  The
regular server process log is also populated.  The PIPE introduces some latency
to this that the Server Statistics process Output report cannot control.


COMMAND-LINE
------------
When outside of a PIPE environment the utility merely exits without a qualifier.
All but the /ppf qualifier are intended as general command-line operation.

/next     display next interval log file name
/ppf      defines job-level logicals containing process-permanent file names
/this     display current interval log file name
/version  display utility version information


PIPED WASD LOGS
---------------
To WAStee WASD server process logs prepend the following TEN lines to
WASD_ROOT:[STARTUP]STARTUP_SERVER.COM (despite the "DO NOT MODIFY THIS
PROCEDURE!" :-) so it looks like this:

$! ~~~~ see WASD_ROOT:[SRC.UTILS]WASTEE.C ~~~
$ if f$trnlnm("SYS$PIPE") .eqs. ""
$ then
$    arch_name = f$edit(f$getsyi("arch_name"),"upcase")
$    if arch_name .eqs. "ALPHA" then arch_name = "axp"
$    wastee = "$wasd_root:[startup]wastee_''arch_name'.exe"
$    wastee /ppf
$    pipe @WASD_ROOT:[STARTUP]STARTUP_SERVER.COM | wastee
$    exit
$ endif
$!-----------------------------------------------------------------------------
$! STARTUP_SERVER.COM
8< snip 8<


BUILD DETAILS
-------------
$ @BUILD_WASTEE BUILD  !compile+link
$ @BUILD_WASTEE LINK   !link-only

NOTE: links executable as WASD_ROOT:[STARTUP]WASTEE_<arch>.EXE


COPYRIGHT
---------
Copyright (C) 2021 Mark G.Daniel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


VERSION HISTORY
---------------
20-MAR-2021  MGD  v1.1.0, refinements based on field-test
10-MAR-2021  MGD  v1.0.0, initial development
*/
/*****************************************************************************/

#define SOFTWAREVN "1.1.0"
#define SOFTWARENM "WASTEE"
#ifdef __ALPHA
#  define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN
#endif
#ifdef __ia64
#  define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN
#endif
#ifdef __VAX
#  error VAX no longer implemented
#endif
#ifdef __x86_64
#  define SOFTWAREID SOFTWARENM " X86-" SOFTWAREVN
#endif

/* standard C header files */
#include <ctype.h>
#include <errno.h>
#include <ints.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <types.h>

/* VMS-related header files */
#include <descrip.h>
#include <jpidef.h>
#include <fabdef.h>
#include <iledef.h>
#include <lnmdef.h>
#include <namdef.h>
#include <libdtdef.h>
#include <lib$routines.h>
#include <prvdef.h>
#include <ssdef.h>
#include <syidef.h>
#include <starlet.h>

int  louterrno;
char  interval[] = "weekly1";
FILE  *lout;

void WeekDay (int64*, ushort[], int, int);
void InaMinute ();
char* LogName (ushort[]);
void LogTime (int64*, ushort[], int);
void SetProcessName ();
void WASteeExit ();
void WASteeLogFileName (char*);
int WASteePPF();
void WASteeStamp (char*);

/*****************************************************************************/
/*
*/

main (int argc, char** argv)
       
{
   static char  record [2048];

   if (argc > 1)
   {
      if (!strcasecmp(argv[1],"/ppf"))
      {
         /* set process name only if NOT interactive */
         if (WASteePPF ()) SetProcessName ("WASD:pipe");
      }
      else
      if (!strcasecmp(argv[1],"/this"))
      {
         ushort  time7 [7];
         LogTime (0, time7, 0);
         if (interval[0] == '?') exit (SS$_IVTIME);
         fprintf (stdout, "%%%s-I-%s, %s\n",
                  SOFTWARENM, interval, LogName(time7));
      }
      else
      if (!strcasecmp(argv[1],"/next"))
      {
         ushort  time7 [7];
         LogTime (0, time7, 1);
         if (interval[0] == '?') exit (SS$_IVTIME);
         fprintf (stdout, "%%%s-I-%s, %s\n",
                  SOFTWARENM, interval, LogName(time7));
      }
      else
      if (!strcasecmp(argv[1],"/version"))
         puts (SOFTWAREID);
      exit (SS$_NORMAL);
   }
   else
   if (!getenv ("SYS$PIPE"))
      exit (SS$_NORMAL);

   atexit (WASteeExit);

   SetProcessName ("WAStee");
   InaMinute ();
   if (interval[0] == '?') exit (SS$_IVTIME);
   for (;;)
   {
      if (!fgets (record, sizeof(record), stdin)) break;
      if (fputs (record, stdout) == EOF) break;
      fsync (fileno(stdout));
      if (lout)
      {
         if (fputs (record, lout) == EOF) break;
         fsync (fileno(lout));
      }
   }
   exit (vaxc$errno);
}

/*****************************************************************************/
/*
On image exit put a timestamp into the log(s).
*/

void WASteeExit ()
       
{
   WASteeStamp ("CLOSE");
   if (lout) fclose (lout);
}

/*****************************************************************************/
/*
Put a timestamp into both primary and teed logs.
*/

void WASteeStamp (char *cptr)
       
{
   static char  stamp [48+256];
   static $DESCRIPTOR (StampDsc, stamp);
   static $DESCRIPTOR (StampFaoDsc, "%!AZ-!AZ-!AZ, !20%D !AZ\n\0");

   sys$fao (&StampFaoDsc, 0, &StampDsc,
            SOFTWARENM, louterrno ? "E" : "I", cptr, 0, LogName(NULL));
   fputs (stamp, stdout);
   fsync (fileno(stdout));
   fputs (stamp, lout);
   fsync (fileno(lout));
}

/*****************************************************************************/
/*
Called once a minute.
*/

void InaMinute ()
       
{
   static ulong  SysPrvMask [2] = { PRV$M_SYSPRV, 0 };

   static int64  d1min64 = -600000000;  /* one minute delta */
   static int  newlog, status,
               phour = -1,
               pday = -1,
               pmonth = -1;
   static int64  time64;
   static ushort  time7 [7],
                  roll7 [7];
   static char  *lname;

   sys$gettim (&time64);
   sys$numtim (&time7, &time64);

   if (time7[3] != phour)
   {
      phour = time7[3];
      LogTime (&time64, roll7, 0);
      newlog = ((pmonth < 0 && pday < 0) ||
                (pmonth != roll7[1] || pday != roll7[2]));

      if (newlog)
      {
         pmonth = roll7[1];
         pday = roll7[2];

         lname = LogName (roll7);

         sys$setprv (1, &SysPrvMask, 0, 0);
         if (lout)
         {
            WASteeStamp ("CLOSE");
            fclose (lout);
         }
         if (!(lout = fopen (lname, "a", "shr=get"))) louterrno = vaxc$errno;
         sys$setprv (0, &SysPrvMask, 0, 0);

         WASteeStamp ("OPEN");
         if (louterrno)
            fprintf (stdout, "-%s-E-ERROR, %s\n",
                     SOFTWARENM, strerror(EVMSERR, louterrno));
         else
            WASteeLogFileName (lname);
      }
   }

   status = sys$setimr (0, &d1min64, InaMinute, 0, 0);
   if (!(status & 1)) exit (status);
}

/*****************************************************************************/
/*
Generate and return a pointer to a log file name.
*/

char* LogName (ushort time7ptr[])
       
{
   static ushort  SyiNodeLength;
   static int  SyiNodeNameItem = SYI$_NODENAME;
   static char  SyiNodeName [16];
   static $DESCRIPTOR (SyiNodeNameDsc, SyiNodeName);

   static char  logname [256];

   int  status;
   char  *location;
   ushort  slen;

   if (!SyiNodeName[0])
   {
      status = lib$getsyi (&SyiNodeNameItem, 0, &SyiNodeNameDsc, &slen, 0, 0);
      if (!(status & 1)) exit (status);
      SyiNodeName[slen] = '\0';
   }

   if (!time7ptr) return (logname);

   if (!(location = getenv ("WASTEE_LOCATION")))
      location = "WASD_SERVER_LOGS:";

   sprintf (logname, "%s%s_%d%02d%02d.LOG",
            location, SyiNodeName, time7ptr[0], time7ptr[1], time7ptr[2]);

   return (logname);
}

/****************************************************************************/
/*
Calculate the data/time of the current/next log and populate the vector time.
*/

void LogTime (int64 *time64ptr, ushort time7ptr[], int next)

{
   static int64  d1day64 = (int64)-600000000 * 60 * 24;  /* one day delta */

   int64  time64;
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (time64ptr)
      time64 = *time64ptr;
   else
      sys$gettim (&time64);
   sys$numtim (time7ptr, &time64);

   if (!(cptr = getenv ("WASTEE_INTERVAL"))) cptr = "W1";

   if (*cptr == 'D')
   {
      strcpy (interval, "DAILY");
      if (next) time64 -= d1day64;
      sys$numtim (time7ptr, &time64);
   }
   else
   if (*cptr == 'W')
   {
      /* does the weekday also specify a day of the week integer */
      int  dayof = 1;
      while (*cptr && !isdigit(*cptr)) cptr++;
      if (*cptr >= '1' && *cptr <= '7') dayof = *cptr - '0';
      strcpy (interval, "WEEKLY");
      interval[6] = dayof + '0';
      WeekDay (&time64, time7ptr, dayof, next);
   }
   else
   if (*cptr == 'M')
   {
      int  pmonth;
      strcpy (interval, "MONTHLY");
      /* add a day until the month changes (q&d) */
      pmonth = time7ptr[1];
      for (;;)
      {
         if (next) 
            time64 -= d1day64;
         else
            time64 += d1day64;
         sys$numtim (time7ptr, &time64);
         if (time7ptr[1] != pmonth) break;
      }
      if (!next) time64 -= d1day64;
   }
   else
      strcpy (interval, "?");
}

/*****************************************************************************/
/*
Get the day of the week (1..7) and calculate the date (year/month/day) adjusted
for that day of the week.  Adjust the numeric time structure provided.
Return the day of the month, as calculated by the specified weekday.
*/

void WeekDay (int64 *time64ptr, ushort time7ptr[], int dayof, int next)
       
{
   static int  LibDayOfWeek = LIB$K_DAY_OF_WEEK;
   static int64  d1day64 = (int64)-600000000 * 60 * 24;  /* one day delta */
   static int64  dweek64;
   static int  aday, wday;
   static int64  ptime64;

   if (ptime64 == *time64ptr)
   {
      /* same time as previous call, no need to recalculate */
      sys$numtim (time7ptr, &dweek64);
      return;
   }
   ptime64 = *time64ptr;

   /* return 1 for Mon, 2 for Tue .. 7 for Sun */
   lib$cvt_from_internal_time (&LibDayOfWeek, &wday, time64ptr);
   if (wday < dayof)
   {
      aday = dayof - wday - 7;
      if (next) aday += 7;
      dweek64 = *time64ptr - (d1day64 * aday);
   }
   else
   {
      aday = wday - dayof;
      if (next) aday -= 7;
      dweek64 = *time64ptr + (d1day64 * aday);
   }
   sys$numtim (time7ptr, &dweek64);
}

/****************************************************************************/
/*
Set the process name so it's unique.  Must be a maximum of ten characters.
*/

void SetProcessName (char *name)

{
   static unsigned long  JpiPidItem = JPI$_PID;
   static char  PrcNam [16];
   static $DESCRIPTOR (PrcNamDsc, PrcNam);

   int  status;
   unsigned long  ScriptPid;
   struct dsc$descriptor_s  *dscptr;

   /*********/
   /* begin */
   /*********/

   lib$getjpi (&JpiPidItem, 0, 0, &ScriptPid, 0, 0);
   dscptr = &PrcNamDsc;
   dscptr->dsc$w_length = sprintf (PrcNam, "%s_%4.4X",
                                   name, ScriptPid & 0xffff);
   status = sys$setprn (dscptr);
   if (!(status & 1)) exit (status);
}

/*****************************************************************************/
/*
Get the values of the SYS$INPUT and SYS$OUTPUT process-permanent files (PPFs)
and create job-level logical names containing those values that can be used by
the HTTPd server for admin purposes.

Derived from WASD_ROOT:[SRC.HTTPD]HTTPD.C HttpdProcessInfo().
*/

int WASteePPF ()

{
   static $DESCRIPTOR (InpNameDsc, "WASTEE_SYS$INPUT");
   static $DESCRIPTOR (OutNameDsc, "WASTEE_SYS$OUTPUT");
   static $DESCRIPTOR (LnmJobDsc, "LNM$JOB");
   static $DESCRIPTOR (LnmProcessDsc, "LNM$PROCESS");
   static $DESCRIPTOR (SysOutputDsc, "SYS$OUTPUT");
   static $DESCRIPTOR (SysInputDsc, "SYS$INPUT");
   static int  JpiModeItem = JPI$_MODE;
   static ulong  JpiMode;
   static ushort  InpLen,
                  OutLen,
                  ValueLen;

   static char  LogValue [64],
                SysInput [256],
                SysOutput [256];
   static struct _ile3  TrnLnmItem [] =
   {
      { sizeof(LogValue)-1, LNM$_STRING, LogValue, &ValueLen },
      { 0,0,0,0 }
   };
   static struct _ile3  CreLnmInpItem [] =
   {
      { 0, LNM$_STRING, SysInput, 0 },
      { 0,0,0,0 }
   };
   static struct _ile3  CreLnmOutItem [] =
   {
      { 0, LNM$_STRING, SysOutput, 0 },
      { 0,0,0,0 }
   };

   int  status, inplen, outlen;
   struct FAB  aFab;
   struct NAM  aNam;

   /*********/
   /* begin */
   /*********/

   /* check process mode */
   status = lib$getjpi (&JpiModeItem, 0, 0, &JpiMode, 0, 0);
   if (!(status & 1)) exit (status);
   /* if interactive then do not proceed */
   if (JpiMode == 3) return (0);

   status = sys$trnlnm (0, &LnmProcessDsc, &SysInputDsc, 0, &TrnLnmItem);
   if (!(status & 1)) exit (status);

   if (*(ushort*)LogValue == 0x001b)
   {
      aFab = cc$rms_fab;
      aFab.fab$l_nam = &aNam;
      aFab.fab$b_fac = FAB$M_GET;
      aFab.fab$w_ifi = *(ushort*)(LogValue+2) | FAB$M_PPF_IND;
      aNam = cc$rms_nam;
      aNam.nam$l_rsa = SysInput;
      aNam.nam$b_rss = sizeof(SysInput)-1;

      status = sys$display (&aFab, 0, 0);

      SysInput[inplen = aNam.nam$b_rsl] = '\0';
      if (!(status & 1)) exit (status);
   }
   else
      strcpy (SysInput, "PPF?");

   status = sys$trnlnm (0, &LnmProcessDsc, &SysOutputDsc, 0, &TrnLnmItem);
   if (!(status & 1)) exit (status);

   if (*(ushort*)LogValue == 0x001b)
   {
      aFab = cc$rms_fab;
      aFab.fab$l_nam = &aNam;
      aFab.fab$b_fac = FAB$M_GET;
      aFab.fab$w_ifi = *(ushort*)(LogValue+2) | FAB$M_PPF_IND;

      aNam = cc$rms_nam;
      aNam.nam$l_rsa = SysOutput;
      aNam.nam$b_rss = sizeof(SysOutput)-1;

      status = sys$display (&aFab, 0, 0);

      SysOutput[outlen = aNam.nam$b_rsl] = '\0';
      if (!(status & 1)) exit (status);
   }
   else
      strcpy (SysOutput, "PPF?");

   CreLnmInpItem[0].ile3$w_length = inplen;
   status = sys$crelnm (0, &LnmJobDsc, &InpNameDsc, 0, &CreLnmInpItem);
   if (!(status & 1)) exit (status);

   CreLnmOutItem[0].ile3$w_length = outlen;
   status = sys$crelnm (0, &LnmJobDsc, &OutNameDsc, 0, &CreLnmOutItem);
   if (!(status & 1)) exit (status);

   return (1);
}

/*****************************************************************************/
/*
Define a job-level logical name containing the teed log file name.  Can be used
by the HTTPd server admin report.
*/

void WASteeLogFileName (char *lname)

{
   static $DESCRIPTOR (LnmJobDsc, "LNM$JOB");
   static $DESCRIPTOR (LogNameDsc, "WASTEE_LOGFILE");

   static struct _ile3  CreLnmItem [] =
   {
      { 0, LNM$_STRING, 0, 0 },
      { 0,0,0,0 }
   };

   int  status;

   /*********/
   /* begin */
   /*********/

   CreLnmItem[0].ile3$w_length = strlen(lname);
   CreLnmItem[0].ile3$ps_bufaddr = lname;
   status = sys$crelnm (0, &LnmJobDsc, &LogNameDsc, 0, &CreLnmItem);
   if (!(status & 1)) exit (status);
}

/*****************************************************************************/