#include "uucp.h"
#if USE_RCS_ID
const char uustat_rcsid[] = "$Id: uustat.c,v 1.61 2002/03/05 19:10:42 ian Rel $";
#endif
#include <ctype.h>
#include <errno.h>
#if TM_IN_SYS_TIME
#include <sys/time.h>
#else
#include <time.h>
#endif
#include "getopt.h"
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
#define JOB_SHOW (01)
#define JOB_INQUIRE (02)
#define JOB_KILL (04)
#define JOB_REJUVENATE (010)
#define JOB_MAIL (020)
#define JOB_NOTIFY (040)
struct scmdlist
{
struct scmdlist *qnext;
struct scmd s;
long itime;
};
static void ususage P((void));
static void ushelp P((void));
static boolean fsxqt_file_read P((pointer puuconf, FILE *));
static void usxqt_file_free P((void));
static int isxqt_cmd P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int isxqt_file P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int isxqt_user P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static boolean fsworkfiles P((pointer puuconf, int icmd, int csystems,
char **pazsystems, boolean fnotsystems,
int cusers, char **pazusers,
boolean fnotusers, long iold, long iyoung,
int ccommands, char **pazcommands,
boolean fnotcommands, const char *zcomment,
int cstdin));
static boolean fsworkfiles_system P((pointer puuconf,int icmd,
const struct uuconf_system *qsys,
int cusers, char **pazusers,
boolean fnotusers, long iold,
long iyoung, int ccommands,
char **pazcommands,
boolean fnotcommands,
const char *zcomment, int cstdin));
static boolean fsworkfile_show P((pointer puuconf, int icmd,
const struct uuconf_system *qsys,
const struct scmd *qcmd,
long itime, int ccommands,
char **pazcommands, boolean fnotcommands,
const char *zcomment, int cstdin));
static void usworkfile_header P((const struct uuconf_system *qsys,
const struct scmd *qcmd,
const char *zjobid,
long itime, boolean ffirst));
static boolean fsexecutions P((pointer puuconf, int icmd, int csystems,
char **pazsystems, boolean fnotsystems,
int cusers, char **pazusers,
boolean fnotusers, long iold, long iyoung,
int ccommands, char **pazcommands,
boolean fnotcommands, const char *zcomment,
int cstdin));
static boolean fsnotify P((pointer puuconf, int icmd, const char *zcomment,
int cstdin, boolean fkilled, const char *zcmd,
struct scmdlist *qcmd, const char *zid,
long itime, const char *zuser,
const struct uuconf_system *qsys,
const char *zstdin, pointer pstdinseq,
const char *zrequestor));
static boolean fsquery P((pointer puuconf, int csystems,
char **pazsystems, boolean fnotsystems,
long iold, long iyoung));
static int csunits_show P((long idiff));
static boolean fsmachines P((void));
static const struct option asSlongopts[] =
{
{ "all", no_argument, NULL, 'a' },
{ "mail-lines", required_argument, NULL, 'B' },
{ "command", required_argument, NULL, 'c' },
{ "not-command", required_argument, NULL, 'C' },
{ "executions", no_argument, NULL, 'e' },
{ "prompt", no_argument, NULL, 'i' },
{ "kill", required_argument, NULL, 'k' },
{ "kill-all", no_argument, NULL, 'K' },
{ "status", no_argument, NULL, 'm' },
{ "mail", no_argument, NULL, 'M' },
{ "notify", no_argument, NULL, 'N' },
{ "older-than", required_argument, NULL, 'o' },
{ "ps", no_argument, NULL, 'p' },
{ "list", no_argument, NULL, 'q' },
{ "no-list", no_argument, NULL, 'Q' },
{ "rejuvenate", required_argument, NULL, 'r' },
{ "rejuvenate-all", no_argument, NULL, 'R' },
{ "system", required_argument, NULL, 's' },
{ "not-system", required_argument, NULL, 'S' },
{ "user", required_argument, NULL, 'u' },
{ "not-user", required_argument, NULL, 'U' },
{ "comment", required_argument, NULL, 'W' },
{ "younger-than", required_argument, NULL, 'y' },
{ "config", required_argument, NULL, 'I' },
{ "debug", required_argument, NULL, 'x' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 }
};
int
main (argc, argv)
int argc;
char **argv;
{
boolean fall = FALSE;
int cstdin = 100;
int ccommands = 0;
char **pazcommands = NULL;
boolean fnotcommands = FALSE;
boolean fexecute = FALSE;
int ckills = 0;
char **pazkills = NULL;
boolean fmachine = FALSE;
int ioldhours = -1;
boolean fps = FALSE;
boolean fquery = FALSE;
int crejuvs = 0;
char **pazrejuvs = NULL;
int csystems = 0;
char **pazsystems = NULL;
boolean fnotsystems = FALSE;
int cusers = 0;
char **pazusers = NULL;
boolean fnotusers = FALSE;
const char *zcomment = NULL;
int iyounghours = -1;
const char *zconfig = NULL;
int icmd = JOB_SHOW;
int ccmds;
int iopt;
pointer puuconf;
int iuuconf;
long iold;
long iyoung;
const char *azoneuser[1];
boolean fret;
if (argc < 1)
{
zProgram = "uustat";
ususage ();
}
zProgram = argv[0];
while ((iopt = getopt_long (argc, argv,
"aB:c:C:eiI:k:KmMNo:pqQr:Rs:S:u:U:vW:x:y:",
asSlongopts, (int *) NULL)) != EOF)
{
switch (iopt)
{
case 'a':
fall = TRUE;
break;
case 'B':
cstdin = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'C':
fnotcommands = TRUE;
case 'c':
++ccommands;
pazcommands = (char **) xrealloc ((pointer) pazcommands,
ccommands * sizeof (char *));
pazcommands[ccommands - 1] = optarg;
break;
case 'e':
fexecute = TRUE;
break;
case 'i':
icmd |= JOB_INQUIRE;
break;
case 'I':
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 'k':
++ckills;
pazkills = (char **) xrealloc ((pointer) pazkills,
ckills * sizeof (char *));
pazkills[ckills - 1] = optarg;
break;
case 'K':
icmd |= JOB_KILL;
break;
case 'm':
fmachine = TRUE;
break;
case 'M':
icmd |= JOB_MAIL;
break;
case 'N':
icmd |= JOB_NOTIFY;
break;
case 'o':
ioldhours = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'p':
fps = TRUE;
break;
case 'q':
fquery = TRUE;
break;
case 'Q':
icmd &=~ JOB_SHOW;
break;
case 'r':
++crejuvs;
pazrejuvs = (char **) xrealloc ((pointer) pazrejuvs,
crejuvs * sizeof (char *));
pazrejuvs[crejuvs - 1] = optarg;
break;
case 'R':
icmd |= JOB_REJUVENATE;
break;
case 'S':
fnotsystems = TRUE;
case 's':
++csystems;
pazsystems = (char **) xrealloc ((pointer) pazsystems,
csystems * sizeof (char *));
pazsystems[csystems - 1] = optarg;
break;
case 'U':
fnotusers = TRUE;
case 'u':
++cusers;
pazusers = (char **) xrealloc ((pointer) pazusers,
cusers * sizeof (char *));
pazusers[cusers - 1] = optarg;
break;
case 'W':
zcomment = optarg;
break;
case 'x':
#if DEBUG > 1
iDebug |= idebug_parse (optarg);
#endif
break;
case 'y':
iyounghours = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'v':
printf ("uustat (Taylor UUCP) %s\n", VERSION);
printf ("Copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n");
printf ("This program is free software; you may redistribute it under the terms of\n");
printf ("the GNU General Public LIcense. This program has ABSOLUTELY NO WARRANTY.\n");
exit (EXIT_SUCCESS);
case 1:
ushelp ();
exit (EXIT_SUCCESS);
case 0:
break;
default:
ususage ();
}
}
if (optind != argc)
ususage ();
ccmds = 0;
if (fall)
++ccmds;
if (ckills > 0 || crejuvs > 0)
++ccmds;
if (fmachine)
++ccmds;
if (fps)
++ccmds;
if (fexecute || fquery || csystems > 0 || cusers > 0 || ioldhours != -1
|| iyounghours != -1 || ccommands > 0)
++ccmds;
if (fexecute && fquery)
++ccmds;
if (ccmds > 1)
{
fprintf (stderr, "%s: too many options\n", zProgram);
ususage ();
}
if ((icmd & JOB_KILL) != 0
&& (icmd & JOB_REJUVENATE) != 0)
{
fprintf (stderr, "%s: can not both rejuvenate and kill jobs\n",
zProgram);
ususage ();
}
iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
#if DEBUG > 1
{
const char *zdebug;
iuuconf = uuconf_debuglevel (puuconf, &zdebug);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (zdebug != NULL)
iDebug |= idebug_parse (zdebug);
}
#endif
usysdep_initialize (puuconf, INIT_SUID);
if (ccmds == 0)
{
cusers = 1;
azoneuser[0] = zsysdep_login_name ();
pazusers = (char **) azoneuser;
}
if (csystems > 0)
{
int i;
for (i = 0; i < csystems; i++)
{
struct uuconf_system ssys;
iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_FATAL, "%s: System not found", pazsystems[i]);
else
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
}
if (strcmp (pazsystems[i], ssys.uuconf_zname) != 0)
pazsystems[i] = zbufcpy (ssys.uuconf_zname);
(void) uuconf_system_free (puuconf, &ssys);
}
}
if (ioldhours == -1)
iold = (long) -1;
else
{
iold = (ixsysdep_time ((long *) NULL)
- (long) ioldhours * (long) 60 * (long) 60);
if (iold < 0L)
iold = 0L;
}
if (iyounghours == -1)
iyoung = (long) -1;
else
{
iyoung = (ixsysdep_time ((long *) NULL)
- (long) iyounghours * (long) 60 * (long) 60);
if (iyoung < 0L)
iyoung = 0L;
}
if (! fexecute
&& ! fquery
&& (fall
|| csystems > 0
|| cusers > 0
|| ioldhours != -1
|| iyounghours != -1
|| ccommands > 0))
fret = fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems,
cusers, pazusers, fnotusers, iold, iyoung,
ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
else if (fexecute)
fret = fsexecutions (puuconf, icmd, csystems, pazsystems, fnotsystems,
cusers, pazusers, fnotusers, iold, iyoung,
ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
else if (icmd != JOB_SHOW)
{
ulog (LOG_ERROR,
"-i, -K, -M, -N, -Q, -R not supported with -k, -m, -p, -q, -r");
ususage ();
fret = FALSE;
}
else if (fquery)
{
if (cusers > 0 || ccommands > 0)
{
ulog (LOG_ERROR, "-u, -c not supported with -q");
ususage ();
fret = FALSE;
}
else
fret = fsquery (puuconf, csystems, pazsystems, fnotsystems,
iold, iyoung);
}
else if (fmachine)
fret = fsmachines ();
else if (ckills > 0 || crejuvs > 0)
{
int i;
fret = TRUE;
for (i = 0; i < ckills; i++)
if (! fsysdep_kill_job (puuconf, pazkills[i]))
fret = FALSE;
for (i = 0; i < crejuvs; i++)
if (! fsysdep_rejuvenate_job (puuconf, pazrejuvs[i]))
fret = FALSE;
}
else if (fps)
fret = fsysdep_lock_status ();
else
{
#if DEBUG > 0
ulog (LOG_FATAL, "Can't happen");
#endif
fret = FALSE;
}
ulog_close ();
usysdep_exit (fret);
return 0;
}
static void
ususage ()
{
fprintf (stderr, "Usage: %s [options]\n", zProgram);
fprintf (stderr, "Use %s --help for help\n", zProgram);
exit (EXIT_FAILURE);
}
static void
ushelp ()
{
printf ("Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n",
VERSION);
printf ("Usage: %s [options]\n", zProgram);
printf (" -a,--all: list all UUCP jobs\n");
printf (" -B,--mail-lines num: number of lines to return in -M or -N mail message\n");
printf (" -c,--command command: list requests for named command\n");
printf (" -C,--not-command command: list requests for other than named command\n");
printf (" -e,--executions: list queued executions rather than job requests\n");
printf (" -i,--prompt: prompt for whether to kill each listed job\n");
printf (" -k,--kill job: kill specified UUCP job\n");
printf (" -K,--kill-all: kill each listed job\n");
printf (" -m,--status: report status for all remote machines\n");
printf (" -M,--mail: mail report on each listed job to UUCP administrator\n");
printf (" -N,--notify: mail report on each listed job to requestor\n");
printf (" -o,--older-than hours: list all jobs older than given number of hours\n");
printf (" -p,--ps: show status of all processes holding UUCP locks\n");
printf (" -q,--list: list number of jobs for each system\n");
printf (" -Q,--no-list: don't list jobs, just take actions (-i, -K, -M, -N)\n");
printf (" -r,--rejuvenate job: rejuvenate specified UUCP job\n");
printf (" -R,--rejuvenate-all: rejuvenate each listed job\n");
printf (" -s,--system system: list all jobs for specified system\n");
printf (" -S,--not-system system: list all jobs for other than specified system\n");
printf (" -u,--user user: list all jobs for specified user\n");
printf (" -U,--not-user user: list all jobs for other than specified user\n");
printf (" -W,--comment comment: comment to include in mail messages\n");
printf (" -y,--younger-than hours: list all jobs younger than given number of hours\n");
printf (" -x,--debug debug: Set debugging level\n");
#if HAVE_TAYLOR_CONFIG
printf (" -I,--config file: Set configuration file to use\n");
#endif
printf (" -v,--version: Print version and exit\n");
printf (" --help: Print help and exit\n");
printf ("Report bugs to taylor-uucp@gnu.org\n");
}
static char *zSxqt_user;
static char *zSxqt_system;
static const char *zSxqt_requestor;
static char *zSxqt_prog;
static char *zSxqt_cmd;
static int cSxqt_files;
static char **pazSxqt_files;
static const char *zSxqt_stdin;
static const struct uuconf_cmdtab asSxqt_cmds[] =
{
{ "C", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_cmd },
{ "I", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_stdin, NULL },
{ "F", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_file },
{ "R", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_requestor, NULL },
{ "U", UUCONF_CMDTABTYPE_FN | 3, NULL, isxqt_user },
{ NULL, 0, NULL, NULL }
};
static boolean
fsxqt_file_read (puuconf, e)
pointer puuconf;
FILE *e;
{
int iuuconf;
boolean fret;
zSxqt_user = NULL;
zSxqt_system = NULL;
zSxqt_stdin = NULL;
zSxqt_requestor = NULL;
zSxqt_prog = NULL;
zSxqt_cmd = NULL;
cSxqt_files = 0;
pazSxqt_files = NULL;
iuuconf = uuconf_cmd_file (puuconf, e, asSxqt_cmds, (pointer) NULL,
(uuconf_cmdtabfn) NULL,
UUCONF_CMDTABFLAG_CASE, (pointer) NULL);
if (iuuconf == UUCONF_SUCCESS)
fret = TRUE;
else
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
}
if (zSxqt_user == NULL)
zSxqt_user = zbufcpy ("*unknown*");
if (zSxqt_system == NULL)
zSxqt_system = zbufcpy ("*unknown*");
if (zSxqt_prog == NULL)
{
zSxqt_prog = zbufcpy ("*none*");
zSxqt_cmd = zbufcpy ("*none*");
}
return fret;
}
static void
usxqt_file_free ()
{
int i;
ubuffree (zSxqt_user);
zSxqt_user = NULL;
ubuffree (zSxqt_system);
zSxqt_system = NULL;
ubuffree (zSxqt_prog);
zSxqt_prog = NULL;
ubuffree (zSxqt_cmd);
zSxqt_cmd = NULL;
for (i = 0; i < cSxqt_files; i++)
ubuffree (pazSxqt_files[i]);
cSxqt_files = 0;
xfree ((pointer) pazSxqt_files);
pazSxqt_files = NULL;
zSxqt_stdin = NULL;
zSxqt_requestor = NULL;
}
static int
isxqt_cmd (puuconf, argc, argv, pvar, pinfo)
pointer puuconf ATTRIBUTE_UNUSED;
int argc;
char **argv;
pointer pvar ATTRIBUTE_UNUSED;
pointer pinfo ATTRIBUTE_UNUSED;
{
size_t clen;
int i;
if (argc <= 1)
return UUCONF_CMDTABRET_CONTINUE;
zSxqt_prog = zbufcpy (argv[1]);
clen = 0;
for (i = 1; i < argc; i++)
clen += strlen (argv[i]) + 1;
zSxqt_cmd = zbufalc (clen);
zSxqt_cmd[0] = '\0';
for (i = 1; i < argc - 1; i++)
{
strcat (zSxqt_cmd, argv[i]);
strcat (zSxqt_cmd, " ");
}
strcat (zSxqt_cmd, argv[i]);
return UUCONF_CMDTABRET_CONTINUE;
}
static int
isxqt_file (puuconf, argc, argv, pvar, pinfo)
pointer puuconf ATTRIBUTE_UNUSED;
int argc;
char **argv;
pointer pvar ATTRIBUTE_UNUSED;
pointer pinfo ATTRIBUTE_UNUSED;
{
if (argc != 2 && argc != 3)
return UUCONF_CMDTABRET_CONTINUE;
if (! fspool_file (argv[1]))
return UUCONF_CMDTABRET_CONTINUE;
++cSxqt_files;
pazSxqt_files = (char **) xrealloc ((pointer) pazSxqt_files,
cSxqt_files * sizeof (char *));
pazSxqt_files[cSxqt_files - 1] = zbufcpy (argv[1]);
return UUCONF_CMDTABRET_CONTINUE;
}
static int
isxqt_user (puuconf, argc, argv, pvar, pinfo)
pointer puuconf ATTRIBUTE_UNUSED;
int argc ATTRIBUTE_UNUSED;
char **argv;
pointer pvar ATTRIBUTE_UNUSED;
pointer pinfo ATTRIBUTE_UNUSED;
{
zSxqt_user = zbufcpy (argv[1]);
zSxqt_system = zbufcpy (argv[2]);
return UUCONF_CMDTABRET_CONTINUE;
}
static boolean
fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems, cusers,
pazusers, fnotusers, iold, iyoung, ccommands, pazcommands,
fnotcommands, zcomment, cstdin)
pointer puuconf;
int icmd;
int csystems;
char **pazsystems;
boolean fnotsystems;
int cusers;
char **pazusers;
boolean fnotusers;
long iold;
long iyoung;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
boolean fret;
int i;
int iuuconf;
struct uuconf_system ssys;
fret = TRUE;
if (csystems > 0 && ! fnotsystems)
{
for (i = 0; i < csystems; i++)
{
iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_ERROR, "%s: System not found", pazsystems[i]);
else
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
continue;
}
if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
fnotusers, iold, iyoung, ccommands,
pazcommands, fnotcommands, zcomment,
cstdin))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
}
}
else
{
char **pznames, **pz;
iuuconf = uuconf_system_names (puuconf, &pznames, 0);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
return FALSE;
}
for (pz = pznames; *pz != NULL; pz++)
{
if (csystems > 0)
{
for (i = 0; i < csystems; i++)
if (strcmp (*pz, pazsystems[i]) == 0)
break;
if (i < csystems)
continue;
}
iuuconf = uuconf_system_info (puuconf, *pz, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
continue;
}
if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
fnotusers, iold, iyoung, ccommands,
pazcommands, fnotcommands, zcomment,
cstdin))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
xfree ((pointer) *pz);
}
xfree ((pointer) pznames);
}
return fret;
}
static boolean
fsworkfiles_system (puuconf, icmd, qsys, cusers, pazusers, fnotusers, iold,
iyoung, ccommands, pazcommands, fnotcommands, zcomment,
cstdin)
pointer puuconf;
int icmd;
const struct uuconf_system *qsys;
int cusers;
char **pazusers;
boolean fnotusers;
long iold;
long iyoung;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
boolean fret;
if (! fsysdep_get_work_init (qsys, UUCONF_GRADE_LOW, 0))
return FALSE;
while (TRUE)
{
struct scmd s;
long itime;
if (! fsysdep_get_work (qsys, UUCONF_GRADE_LOW, 0, &s))
{
usysdep_get_work_free (qsys);
return FALSE;
}
if (s.bcmd == 'H')
break;
if (cusers > 0)
{
boolean fmatch;
int i;
fmatch = fnotusers;
for (i = 0; i < cusers; i++)
{
if (s.zuser != NULL
&& strcmp (pazusers[i], s.zuser) == 0)
{
fmatch = ! fmatch;
break;
}
}
if (! fmatch)
continue;
}
itime = ixsysdep_work_time (qsys, s.pseq);
if (iold != (long) -1 && itime > iold)
continue;
if (iyoung != (long) -1 && itime < iyoung)
continue;
if (! fsworkfile_show (puuconf, icmd, qsys, &s, itime, ccommands,
pazcommands, fnotcommands, zcomment, cstdin))
{
usysdep_get_work_free (qsys);
return FALSE;
}
}
fret = fsworkfile_show (puuconf, icmd, qsys, (const struct scmd *) NULL,
0L, ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
usysdep_get_work_free (qsys);
return fret;
}
static boolean
fsworkfile_show (puuconf, icmd, qsys, qcmd, itime, ccommands, pazcommands,
fnotcommands, zcomment, cstdin)
pointer puuconf;
int icmd;
const struct uuconf_system *qsys;
const struct scmd *qcmd;
long itime;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
static struct scmdlist *qlist;
static char *zlistid;
char *zid;
if (qcmd == NULL)
zid = NULL;
else
{
zid = zsysdep_jobid (qsys, qcmd->pseq);
if (zid == NULL)
return FALSE;
}
if (qcmd != NULL
&& qlist != NULL
&& strcmp (zlistid, zid) == 0)
{
struct scmdlist *qnew, **pq;
ubuffree (zid);
qnew = (struct scmdlist *) xmalloc (sizeof (struct scmdlist));
qnew->qnext = NULL;
qnew->s = *qcmd;
qnew->itime = itime;
for (pq = &qlist; *pq != NULL; pq = &(*pq)->qnext)
;
*pq = qnew;
return TRUE;
}
if (qlist != NULL)
{
boolean fmatch;
const char *zprog, *zcmd, *zrequestor, *zstdin;
char *zfree;
struct scmdlist *qxqt;
FILE *exqt = NULL;
struct scmdlist *qfree;
fmatch = FALSE;
zprog = zcmd = zrequestor = zstdin = NULL;
zfree = NULL;
for (qxqt = qlist; qxqt != NULL; qxqt = qxqt->qnext)
{
if (qxqt->s.bcmd == 'E')
break;
if (qxqt->s.bcmd == 'S'
&& qxqt->s.zto[0] == 'X'
&& qxqt->s.zto[1] == '.'
&& fspool_file (qxqt->s.zfrom))
{
char *zxqt;
zxqt = zsysdep_spool_file_name (qsys, qxqt->s.zfrom,
qxqt->s.pseq);
if (zxqt == NULL)
return FALSE;
exqt = fopen (zxqt, "r");
ubuffree (zxqt);
if (exqt != NULL)
break;
}
}
if (qxqt == NULL)
{
if (ccommands == 0
|| (fnotcommands
&& strcmp (pazcommands[0], "ALL") == 0))
{
fmatch = TRUE;
if ((icmd & JOB_SHOW) != 0)
{
struct scmdlist *qshow;
for (qshow = qlist; qshow != NULL; qshow = qshow->qnext)
{
char *zfile;
long cbytes;
usworkfile_header (qsys, &qshow->s, zlistid,
qshow->itime, qshow == qlist);
switch (qshow->s.bcmd)
{
case 'S':
if (strchr (qshow->s.zoptions, 'C') != NULL
|| fspool_file (qshow->s.zfrom))
zfile = zsysdep_spool_file_name (qsys,
qshow->s.ztemp,
qshow->s.pseq);
else
zfile = zbufcpy (qshow->s.zfrom);
if (zfile == NULL)
cbytes = -1;
else
cbytes = csysdep_size (zfile);
if (cbytes >= 0)
printf ("Sending %s (%ld bytes) to %s",
qshow->s.zfrom, cbytes, qshow->s.zto);
ubuffree (zfile);
break;
case 'R':
printf ("Requesting %s to %s", qshow->s.zfrom,
qshow->s.zto);
break;
case 'X':
printf ("Requesting %s to %s", qshow->s.zfrom,
qshow->s.zto);
break;
case 'P':
printf ("(poll file)");
break;
#if DEBUG > 0
default:
printf ("Bad line %d", qshow->s.bcmd);
break;
#endif
}
printf ("\n");
}
}
}
}
else
{
long csize;
struct scmdlist *qsize;
if (qxqt->s.bcmd == 'E')
{
zfree = zbufcpy (qxqt->s.zcmd);
zfree[strcspn (zfree, " \t")] = '\0';
zprog = zfree;
zcmd = qxqt->s.zcmd;
if (strchr (qxqt->s.zoptions, 'R') != NULL)
zrequestor = qxqt->s.znotify;
}
else
{
if (! fsxqt_file_read (puuconf, exqt))
{
(void) fclose (exqt);
return FALSE;
}
(void) fclose (exqt);
zprog = zSxqt_prog;
zcmd = zSxqt_cmd;
zrequestor = zSxqt_requestor;
}
csize = 0L;
for (qsize = qlist; qsize != NULL; qsize = qsize->qnext)
{
if (qsize->s.bcmd == 'S' || qsize->s.bcmd == 'E')
{
char *zfile;
if (strchr (qsize->s.zoptions, 'C') != NULL
|| fspool_file (qsize->s.zfrom))
zfile = zsysdep_spool_file_name (qsys, qsize->s.ztemp,
qsize->s.pseq);
else
zfile = zbufcpy (qsize->s.zfrom);
if (zfile != NULL)
{
long cbytes;
cbytes = csysdep_size (zfile);
if (cbytes > 0)
csize += cbytes;
ubuffree (zfile);
}
}
}
if (ccommands == 0)
fmatch = TRUE;
else
{
int i;
fmatch = fnotcommands;
for (i = 0; i < ccommands; i++)
{
if (strcmp (pazcommands[i], "ALL") == 0
|| strcmp (pazcommands[i], zprog) == 0)
{
fmatch = ! fmatch;
break;
}
}
}
if (fmatch)
{
struct scmdlist *qstdin;
if (qxqt->s.bcmd == 'E')
qstdin = qxqt;
else if (zSxqt_stdin != NULL)
{
for (qstdin = qlist;
qstdin != NULL;
qstdin = qstdin->qnext)
if (qstdin->s.bcmd == 'S'
&& strcmp (qstdin->s.zto, zSxqt_stdin) == 0)
break;
}
else
qstdin = NULL;
if (qstdin != NULL)
{
if (strchr (qstdin->s.zoptions, 'C') != NULL
|| fspool_file (qstdin->s.zfrom))
zstdin = qstdin->s.ztemp;
else
zstdin = qstdin->s.zfrom;
}
}
if (fmatch && (icmd & JOB_SHOW) != 0)
{
usworkfile_header (qsys, &qxqt->s, zlistid, qxqt->itime,
TRUE);
printf ("Executing %s (sending %ld bytes)\n", zcmd, csize);
}
}
if (fmatch)
{
boolean fkill_or_rejuv;
fkill_or_rejuv = FALSE;
if ((icmd & JOB_INQUIRE) != 0)
{
int b;
fprintf (stderr, "%s: %s %s? ",
zProgram,
(icmd & JOB_REJUVENATE) != 0 ? "Rejuvenate" : "Kill",
zlistid);
(void) fflush (stderr);
b = getchar ();
fkill_or_rejuv = b == 'y' || b == 'Y';
while (b != EOF && b != '\n')
b = getchar ();
}
else if ((icmd & JOB_KILL) != 0
|| (icmd & JOB_REJUVENATE) != 0)
fkill_or_rejuv = TRUE;
if (fkill_or_rejuv
&& (qlist->s.zuser == NULL
|| strcmp (zsysdep_login_name (), qlist->s.zuser) != 0)
&& ! fsysdep_privileged ())
ulog (LOG_ERROR, "%s: Not submitted by you", zlistid);
else
{
if ((icmd & (JOB_MAIL | JOB_NOTIFY)) != 0)
{
if (! fsnotify (puuconf, icmd, zcomment, cstdin,
(fkill_or_rejuv &&
(icmd & JOB_REJUVENATE) == 0),
zcmd, qlist, zlistid, qlist->itime,
qlist->s.zuser, qsys, zstdin,
qlist->s.pseq, zrequestor))
return FALSE;
}
if (fkill_or_rejuv)
{
if ((icmd & JOB_REJUVENATE) == 0)
{
if (! fsysdep_kill_job (puuconf, zlistid))
return FALSE;
}
else
{
if (! fsysdep_rejuvenate_job (puuconf, zlistid))
return FALSE;
}
}
}
}
if (qxqt != NULL)
{
if (qxqt->s.bcmd == 'E')
ubuffree (zfree);
else
usxqt_file_free ();
}
qfree = qlist;
while (qfree != NULL)
{
struct scmdlist *qnext;
qnext = qfree->qnext;
xfree ((pointer) qfree);
qfree = qnext;
}
ubuffree (zlistid);
qlist = NULL;
zlistid = NULL;
}
if (qcmd != NULL)
{
qlist = (struct scmdlist *) xmalloc (sizeof (struct scmdlist));
qlist->qnext = NULL;
qlist->s = *qcmd;
qlist->itime = itime;
zlistid = zid;
}
return TRUE;
}
static void
usworkfile_header (qsys, qcmd, zjobid, itime, ffirst)
const struct uuconf_system *qsys;
const struct scmd *qcmd;
const char *zjobid;
long itime;
boolean ffirst;
{
const char *zshowid;
struct tm stime;
if (ffirst)
zshowid = zjobid;
else
zshowid = "-";
printf ("%s %s %s ", zshowid, qsys->uuconf_zname,
qcmd->zuser != NULL ? qcmd->zuser : OWNER);
usysdep_localtime (itime, &stime);
printf ("%02d-%02d %02d:%02d ",
stime.tm_mon + 1, stime.tm_mday, stime.tm_hour, stime.tm_min);
}
static boolean
fsexecutions (puuconf, icmd, csystems, pazsystems, fnotsystems, cusers,
pazusers, fnotusers, iold, iyoung, ccommands, pazcommands,
fnotcommands, zcomment, cstdin)
pointer puuconf;
int icmd;
int csystems;
char **pazsystems;
boolean fnotsystems;
int cusers;
char **pazusers;
boolean fnotusers;
long iold;
long iyoung;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
const char *zlocalname;
int iuuconf;
char *zfile;
char *zsystem;
boolean ferr;
iuuconf = uuconf_localname (puuconf, &zlocalname);
if (iuuconf == UUCONF_NOT_FOUND)
{
zlocalname = zsysdep_localname ();
if (zlocalname == NULL)
return FALSE;
}
else if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
return FALSE;
}
if (! fsysdep_get_xqt_init ((const char *) NULL))
return FALSE;
while ((zfile = zsysdep_get_xqt ((const char *) NULL, &zsystem, &ferr))
!= NULL)
{
boolean fmatch;
int i;
long itime;
FILE *e;
if (csystems > 0)
{
fmatch = fnotsystems;
for (i = 0; i < csystems; i++)
{
if (strcmp (pazsystems[i], zsystem) == 0)
{
fmatch = ! fmatch;
break;
}
}
if (! fmatch)
{
ubuffree (zfile);
ubuffree (zsystem);
continue;
}
}
itime = ixsysdep_file_time (zfile);
if ((iold != (long) -1 && itime > iold)
|| (iyoung != (long) -1 && itime < iyoung))
{
ubuffree (zfile);
ubuffree (zsystem);
continue;
}
e = fopen (zfile, "r");
if (e == NULL)
{
continue;
}
if (! fsxqt_file_read (puuconf, e))
{
(void) fclose (e);
ubuffree (zfile);
ubuffree (zsystem);
continue;
}
(void) fclose (e);
if (cusers == 0)
fmatch = TRUE;
else
{
fmatch = fnotusers;
for (i = 0; i < cusers; i++)
{
if (strcmp (zSxqt_user, pazusers[i]) == 0
|| (zSxqt_requestor != NULL
&& strcmp (zSxqt_requestor, pazusers[i]) == 0))
{
fmatch = ! fmatch;
break;
}
}
}
if (fmatch && ccommands > 0)
{
fmatch = fnotcommands;
for (i = 0; i < ccommands; i++)
{
if (strcmp (pazcommands[i], "ALL") == 0
|| strcmp (pazcommands[i], zSxqt_prog) == 0)
{
fmatch = ! fmatch;
break;
}
}
}
if (fmatch)
{
boolean fbad, fkill_or_rejuv;
struct uuconf_system ssys;
fbad = FALSE;
if ((icmd & JOB_SHOW) != 0)
{
struct tm stime;
printf ("%s %s!", zsystem, zSxqt_system);
if (zSxqt_requestor != NULL)
printf ("%s", zSxqt_requestor);
else
printf ("%s", zSxqt_user);
usysdep_localtime (itime, &stime);
printf (" %02d-%02d %02d:%02d ",
stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
stime.tm_min);
printf ("%s\n", zSxqt_cmd);
}
fkill_or_rejuv = FALSE;
if ((icmd & JOB_INQUIRE) != 0)
{
int b;
fprintf (stderr, "%s: %s %s? ",
zProgram,
(icmd & JOB_REJUVENATE) != 0 ? "Rejuvenate" : "Kill",
zSxqt_cmd);
(void) fflush (stderr);
b = getchar ();
fkill_or_rejuv = b == 'y' || b == 'Y';
while (b != EOF && b != '\n')
b = getchar ();
}
else if ((icmd & JOB_KILL) != 0
|| (icmd & JOB_REJUVENATE) != 0)
fkill_or_rejuv = TRUE;
if (fkill_or_rejuv)
{
if ((strcmp (zSxqt_user, zsysdep_login_name ()) != 0
|| strcmp (zsystem, zlocalname) != 0)
&& ! fsysdep_privileged ())
{
ulog (LOG_ERROR, "Job not submitted by you\n");
fbad = TRUE;
}
}
if (! fbad)
{
iuuconf = uuconf_system_info (puuconf, zsystem, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fbad = TRUE;
}
else if (strcmp (zsystem, zlocalname) == 0)
{
iuuconf = uuconf_system_local (puuconf, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fbad = TRUE;
}
ssys.uuconf_zname = (char *) zlocalname;
}
else if (! funknown_system (puuconf, zsystem, &ssys))
{
ulog (LOG_ERROR, "Job for unknown system %s",
zsystem);
fbad = TRUE;
}
}
}
if (! fbad && (icmd & (JOB_MAIL | JOB_NOTIFY)) != 0)
{
if (! fsnotify (puuconf, icmd, zcomment, cstdin,
fkill_or_rejuv && (icmd & JOB_REJUVENATE) == 0,
zSxqt_cmd, (struct scmdlist *) NULL,
(const char *) NULL, itime, zSxqt_user, &ssys,
zSxqt_stdin, (pointer) NULL, zSxqt_requestor))
{
ferr = TRUE;
usxqt_file_free ();
ubuffree (zfile);
ubuffree (zsystem);
break;
}
}
if (! fbad && fkill_or_rejuv)
{
for (i = 0; i < cSxqt_files; i++)
{
char *z;
z = zsysdep_spool_file_name (&ssys, pazSxqt_files[i],
(pointer) NULL);
if (z != NULL)
{
if ((icmd & JOB_REJUVENATE) != 0)
(void) fsysdep_touch_file (z);
else
(void) remove (z);
ubuffree (z);
}
}
if ((icmd & JOB_REJUVENATE) != 0)
(void) fsysdep_touch_file (zfile);
else
{
if (remove (zfile) != 0)
ulog (LOG_ERROR, "remove (%s): %s", zfile,
strerror (errno));
}
}
if (! fbad)
(void) uuconf_system_free (puuconf, &ssys);
}
usxqt_file_free ();
ubuffree (zfile);
ubuffree (zsystem);
}
usysdep_get_xqt_free ((const char *) NULL);
return ferr;
}
static boolean
fsnotify (puuconf, icmd, zcomment, cstdin, fkilled, zcmd, qcmd, zid, itime,
zuser, qsys, zstdin, pstdinseq, zrequestor)
pointer puuconf;
int icmd;
const char *zcomment;
int cstdin;
boolean fkilled;
const char *zcmd;
struct scmdlist *qcmd;
const char *zid;
long itime;
const char *zuser;
const struct uuconf_system *qsys;
const char *zstdin;
pointer pstdinseq;
const char *zrequestor;
{
const char **pz;
int cgot;
int i, istdin;
struct tm stime;
char ab[sizeof "1991-12-31 12:00:00"];
const char *zsubject;
boolean fret;
pz = (const char **) xmalloc (20 * sizeof (const char *));
cgot = 20;
i = 0;
if (zid == NULL)
pz[i++] = "A UUCP execution request";
else
{
pz[i++] = "UUCP job\n\t";
pz[i++] = zid;
pz[i++] = "\nfor system\n\t";
pz[i++] = qsys->uuconf_zname;
}
pz[i++] = "\nrequested by\n\t";
pz[i++] = zuser != NULL ? zuser : OWNER;
if (zid == NULL)
{
pz[i++] = "\non system\n\t";
pz[i++] = qsys->uuconf_zname;
}
pz[i++] = "\n";
if (fkilled)
pz[i++] = "has been killed.\n";
if (zcomment != NULL)
{
pz[i++] = zcomment;
pz[i++] = "\n";
}
pz[i++] = "The job was queued at ";
usysdep_localtime (itime, &stime);
sprintf (ab, "%04d-%02d-%02d %02d:%02d:%02d",
stime.tm_year + 1900, stime.tm_mon + 1, stime.tm_mday,
stime.tm_hour, stime.tm_min, stime.tm_sec);
pz[i++] = ab;
pz[i++] = ".\nIt ";
if (fkilled)
pz[i++] = "was\n";
else
pz[i++] = "is\n";
if (zcmd != NULL)
{
pz[i++] = "\t";
pz[i++] = zcmd;
}
else
{
struct scmdlist *qshow;
for (qshow = qcmd; qshow != NULL; qshow = qshow->qnext)
{
if (i + 10 > cgot)
{
cgot += 20;
pz = (const char **) xrealloc ((pointer) pz,
cgot * sizeof (const char *));
}
switch (qshow->s.bcmd)
{
case 'S':
pz[i++] = "\tsend ";
break;
default:
case 'R':
case 'X':
pz[i++] = "\trequest ";
break;
case 'P':
pz[i++] = "\tpoll ";
break;
#if DEBUG > 0
case 'E':
ulog (LOG_FATAL, "fsnotify: Can't happen");
break;
#endif
}
if (qshow->s.zfrom != NULL && qshow->s.zto != NULL)
{
pz[i++] = qshow->s.zfrom;
pz[i++] = " to ";
pz[i++] = qshow->s.zto;
}
}
}
istdin = i;
if (cstdin > 0 && zstdin != NULL)
{
boolean fspool;
char *zfile;
FILE *e;
fspool = fspool_file (zstdin);
if (fspool)
zfile = zsysdep_spool_file_name (qsys, zstdin, pstdinseq);
else
zfile = zsysdep_local_file (zstdin, qsys->uuconf_zpubdir,
(boolean *) NULL);
if (zfile != NULL
&& (fspool
|| fin_directory_list (zfile, qsys->uuconf_pzremote_send,
qsys->uuconf_zpubdir, TRUE, TRUE,
(const char *) NULL)))
{
e = fopen (zfile, "r");
if (e != NULL)
{
int clines, clen;
char *zline;
size_t cline;
pz[i++] = "\n";
istdin = i;
clines = 0;
zline = NULL;
cline = 0;
while ((clen = getline (&zline, &cline, e)) > 0)
{
if (memchr (zline, '\0', (size_t) clen) != NULL)
{
int ifree;
for (ifree = istdin; ifree < i; ifree++)
ubuffree ((char *) pz[ifree]);
i = istdin - 1;
break;
}
++clines;
if (clines > cstdin)
break;
if (i >= cgot)
{
cgot += 20;
pz = (const char **) xrealloc ((pointer) pz,
(cgot
* sizeof (char *)));
}
if (strncmp (zline, "From ", sizeof "From " - 1) != 0)
pz[i++] = zbufcpy (zline);
else
{
char *zalc;
zalc = zbufalc (strlen (zline) + 2);
zalc[0] = '>';
strcpy (zalc + 1, zline);
pz[i++] = zalc;
}
}
xfree ((pointer) zline);
(void) fclose (e);
}
}
ubuffree (zfile);
}
if (fkilled)
zsubject = "UUCP job killed";
else
zsubject = "UUCP notification";
fret = TRUE;
if ((icmd & JOB_MAIL) != 0)
{
if (! fsysdep_mail (OWNER, zsubject, i, pz))
fret = FALSE;
}
if ((icmd & JOB_NOTIFY) != 0
&& (zrequestor != NULL || zuser != NULL))
{
const char *zmail;
char *zfree;
if (zrequestor != NULL)
zmail = zrequestor;
else
zmail = zuser;
zfree = NULL;
if (zid == NULL)
{
int iuuconf;
const char *zloc;
iuuconf = uuconf_localname (puuconf, &zloc);
if (iuuconf == UUCONF_NOT_FOUND)
{
zloc = zsysdep_localname ();
if (zloc == NULL)
return FALSE;
}
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (strcmp (qsys->uuconf_zname, zloc) != 0
#if HAVE_INTERNET_MAIL
&& strchr (zmail, '@') == NULL
#endif
)
{
zfree = zbufalc (strlen (qsys->uuconf_zname)
+ strlen (zmail)
+ sizeof "!");
sprintf (zfree, "%s!%s", qsys->uuconf_zname, zmail);
zmail = zfree;
}
}
if (! fsysdep_mail (zmail, zsubject, i, pz))
fret = FALSE;
ubuffree (zfree);
}
while (istdin < i)
{
ubuffree ((char *) pz[istdin]);
istdin++;
}
xfree ((pointer) pz);
return fret;
}
struct sxqtlist
{
struct sxqtlist *qnext;
char *zsystem;
int cxqts;
long ifirst;
};
static boolean fsquery_system P((const struct uuconf_system *qsys,
struct sxqtlist **pq,
long inow, const char *zlocalname,
int csystems, char **pazsystems,
boolean fnotsystems, long iold, long iyoung));
static boolean fsquery_show P((const struct uuconf_system *qsys, int cwork,
long ifirstwork, struct sxqtlist *qxqt,
long inow, const char *zlocalname,
int csystems, char **pazsystems,
boolean fnotsystems, long iold, long iyoung));
static boolean
fsquery (puuconf, csystems, pazsystems, fnotsystems, iold, iyoung)
pointer puuconf;
int csystems;
char **pazsystems;
boolean fnotsystems;
long iold;
long iyoung;
{
int iuuconf;
const char *zlocalname;
struct sxqtlist *qlist;
char *zfile, *zsystem;
boolean ferr;
long inow;
char **pznames, **pz;
boolean fret;
iuuconf = uuconf_localname (puuconf, &zlocalname);
if (iuuconf == UUCONF_NOT_FOUND)
{
zlocalname = zsysdep_localname ();
if (zlocalname == NULL)
return FALSE;
}
else if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
return FALSE;
}
if (! fsysdep_get_xqt_init ((const char *) NULL))
return FALSE;
qlist = NULL;
while ((zfile = zsysdep_get_xqt ((const char *) NULL, &zsystem, &ferr))
!= NULL)
{
struct sxqtlist *qlook;
for (qlook = qlist; qlook != NULL; qlook = qlook->qnext)
if (strcmp (zsystem, qlook->zsystem) == 0)
break;
if (qlook != NULL)
{
long itime;
ubuffree (zsystem);
++qlook->cxqts;
itime = ixsysdep_file_time (zfile);
if (itime < qlook->ifirst)
qlook->ifirst = itime;
}
else
{
struct sxqtlist *qnew;
qnew = (struct sxqtlist *) xmalloc (sizeof (struct sxqtlist));
qnew->qnext = qlist;
qnew->zsystem = zsystem;
qnew->cxqts = 1;
qnew->ifirst = ixsysdep_file_time (zfile);
qlist = qnew;
}
ubuffree (zfile);
}
usysdep_get_xqt_free ((const char *) NULL);
if (ferr)
return FALSE;
inow = ixsysdep_time ((long *) NULL);
iuuconf = uuconf_system_names (puuconf, &pznames, 0);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
return FALSE;
}
fret = TRUE;
for (pz = pznames; *pz != NULL; pz++)
{
struct uuconf_system ssys;
iuuconf = uuconf_system_info (puuconf, *pz, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
continue;
}
if (! fsquery_system (&ssys, &qlist, inow, zlocalname, csystems,
pazsystems, fnotsystems, iold, iyoung))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
xfree ((pointer) *pz);
}
if (qlist != NULL)
{
struct sxqtlist **pq;
for (pq = &qlist; *pq != NULL; pq = &(*pq)->qnext)
{
if (strcmp ((*pq)->zsystem, zlocalname) == 0)
{
struct uuconf_system ssys;
struct sxqtlist *qfree;
iuuconf = uuconf_system_info (puuconf, zlocalname, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
break;
}
iuuconf = uuconf_system_local (puuconf, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
break;
}
ssys.uuconf_zname = (char *) zlocalname;
}
if (! fsquery_show (&ssys, 0, 0L, *pq, inow, zlocalname,
csystems, pazsystems, fnotsystems,
iold, iyoung))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
qfree = *pq;
*pq = qfree->qnext;
ubuffree (qfree->zsystem);
xfree ((pointer) qfree);
break;
}
}
}
while (qlist != NULL)
{
struct uuconf_system ssys;
struct sxqtlist *qnext;
if (! funknown_system (puuconf, qlist->zsystem, &ssys))
{
ulog (LOG_ERROR, "Executions queued up for unknown systems");
fret = FALSE;
break;
}
if (! fsquery_show (&ssys, 0, 0L, qlist, inow, zlocalname,
csystems, pazsystems, fnotsystems, iold, iyoung))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
qnext = qlist->qnext;
ubuffree (qlist->zsystem);
xfree ((pointer) qlist);
qlist = qnext;
}
return fret;
}
static boolean
fsquery_system (qsys, pq, inow, zlocalname, csystems, pazsystems,
fnotsystems, iold, iyoung)
const struct uuconf_system *qsys;
struct sxqtlist **pq;
long inow;
const char *zlocalname;
int csystems;
char **pazsystems;
boolean fnotsystems;
long iold;
long iyoung;
{
int cwork;
long ifirstwork;
char *zid;
boolean fret;
if (! fsysdep_get_work_init (qsys, UUCONF_GRADE_LOW, 0))
return FALSE;
cwork = 0;
ifirstwork = 0L;
zid = NULL;
while (TRUE)
{
struct scmd s;
long itime;
char *zthisid;
if (! fsysdep_get_work (qsys, UUCONF_GRADE_LOW, 0, &s))
return FALSE;
if (s.bcmd == 'H')
break;
zthisid = zsysdep_jobid (qsys, s.pseq);
if (zid != NULL && strcmp (zid, zthisid) == 0)
ubuffree (zthisid);
else
{
++cwork;
ubuffree (zid);
zid = zthisid;
}
itime = ixsysdep_work_time (qsys, s.pseq);
if (ifirstwork == 0L || ifirstwork > itime)
ifirstwork = itime;
}
usysdep_get_work_free (qsys);
ubuffree (zid);
while (*pq != NULL)
{
if (strcmp ((*pq)->zsystem, qsys->uuconf_zname) == 0)
break;
pq = &(*pq)->qnext;
}
if (cwork == 0 && *pq == NULL)
return TRUE;
fret = fsquery_show (qsys, cwork, ifirstwork, *pq, inow,
zlocalname, csystems, pazsystems, fnotsystems,
iold, iyoung);
if (*pq != NULL)
{
struct sxqtlist *qfree;
qfree = *pq;
*pq = qfree->qnext;
ubuffree (qfree->zsystem);
xfree ((pointer) qfree);
}
return fret;
}
static boolean
fsquery_show (qsys, cwork, ifirstwork, qxqt, inow, zlocalname,
csystems, pazsystems, fnotsystems, iold, iyoung)
const struct uuconf_system *qsys;
int cwork;
long ifirstwork;
struct sxqtlist *qxqt;
long inow;
const char *zlocalname;
int csystems;
char **pazsystems;
boolean fnotsystems;
long iold;
long iyoung;
{
boolean flocal;
struct sstatus sstat;
boolean fnostatus;
struct tm stime;
int cpad;
if (csystems > 0)
{
boolean fmatch;
int i;
fmatch = fnotsystems;
for (i = 0; i < csystems; i++)
{
if (strcmp (pazsystems[i], qsys->uuconf_zname) == 0)
{
fmatch = ! fmatch;
break;
}
}
if (! fmatch)
return TRUE;
}
if ((iold != (long) -1
&& (cwork == 0 || ifirstwork > iold)
&& (qxqt == NULL || qxqt->ifirst > iold))
|| (iyoung != (long) -1
&& (cwork == 0 || ifirstwork < iyoung)
&& (qxqt == NULL || qxqt->ifirst < iyoung)))
return TRUE;
flocal = strcmp (qsys->uuconf_zname, zlocalname) == 0;
if (! flocal)
{
if (! fsysdep_get_status (qsys, &sstat, &fnostatus))
return FALSE;
}
printf ("%-10s %3dC (", qsys->uuconf_zname, cwork);
if (cwork == 0)
{
printf ("0 secs");
cpad = 3;
}
else
cpad = csunits_show (inow - ifirstwork);
printf (") ");
while (cpad-- != 0)
printf (" ");
if (qxqt == NULL)
printf (" 0X (0 secs) ");
else
{
printf ("%3dX (", qxqt->cxqts);
cpad = csunits_show (inow - qxqt->ifirst);
printf (")");
while (cpad-- != 0)
printf (" ");
}
if (flocal || fnostatus)
{
printf ("\n");
if (! flocal)
ubuffree (sstat.zstring);
return TRUE;
}
usysdep_localtime (sstat.ilast, &stime);
printf (" %02d-%02d %02d:%02d ",
stime.tm_mon + 1,stime.tm_mday, stime.tm_hour, stime.tm_min);
if (sstat.zstring == NULL)
printf ("%s\n", azStatus[(int) sstat.ttype]);
else
{
printf ("%s\n", sstat.zstring);
ubuffree (sstat.zstring);
}
return TRUE;
}
static int
csunits_show (idiff)
long idiff;
{
const char *zunit;
long iunits;
int cpad;
if (idiff > (long) 24 * (long) 60 * (long) 60)
{
iunits = idiff / ((long) 24 * (long) 60 * (long) 60);
zunit = "day";
cpad = 4;
}
else if (idiff > (long) 60 * 60)
{
iunits = idiff / (long) (60 * 60);
zunit = "hour";
cpad = 3;
}
else if (idiff > (long) 60)
{
iunits = idiff / (long) 60;
zunit = "min";
cpad = 4;
}
else
{
iunits = idiff;
zunit = "sec";
cpad = 4;
}
printf ("%ld %s%s", iunits, zunit, iunits == 1 ? "" : "s");
if (iunits != 1)
--cpad;
if (iunits > 99)
--cpad;
if (iunits > 9)
--cpad;
return cpad;
}
static boolean
fsmachines ()
{
pointer phold;
char *zsystem;
boolean ferr;
struct sstatus sstat;
if (! fsysdep_all_status_init (&phold))
return FALSE;
while ((zsystem = zsysdep_all_status (phold, &ferr, &sstat)) != NULL)
{
struct tm stime;
usysdep_localtime (sstat.ilast, &stime);
printf ("%-14s %02d-%02d %02d:%02d ", zsystem,
stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
stime.tm_min);
if (sstat.zstring == NULL)
printf ("%s", azStatus[(int) sstat.ttype]);
else
{
printf ("%s", sstat.zstring);
ubuffree (sstat.zstring);
}
ubuffree (zsystem);
if (sstat.ttype != STATUS_TALKING
&& sstat.cwait > 0)
{
printf (" (%d %s", sstat.cretries,
sstat.cretries == 1 ? "try" : "tries");
if (sstat.ilast + sstat.cwait > ixsysdep_time ((long *) NULL))
{
usysdep_localtime (sstat.ilast + sstat.cwait, &stime);
printf (", next after %02d-%02d %02d:%02d",
stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
stime.tm_min);
}
printf (")");
}
printf ("\n");
}
usysdep_all_status_free (phold);
return ! ferr;
}