📄 uustat.c
字号:
printmsg(2,"Scanning call file \"%s\"", callname );
stream = FOPEN( callname, "r",TEXT_MODE );
if ( stream == NULL )
{
printerr( callname );
panic();
}
while( fgets( buf, BUFSIZ, stream) != NULL)
{
switch (*buf)
{
case '#':
break;
case 'S':
case 'R':
*dname = '\0';
sscanf(buf, "%s %s %s %s %s %s",
type, fname, tname, user , flgs, dname);
this_call = *type;
if ( ! strlen( dname ) )
{
printmsg(0,"Invalid data in call file \"%s\"",callname);
panic();
}
/*--------------------------------------------------------------------*/
/* If returning job status, allocate next link in status queue */
/*--------------------------------------------------------------------*/
if ( action == JOB_STATUS )
{
if ( current == NULL)
*top = current = malloc( sizeof *current );
else {
current->next_link = malloc( sizeof *current );
current = current->next_link;
}
checkref( current );
current->next_link = NULL;
current->type = *buf;
} /* action */
/*--------------------------------------------------------------------*/
/* Get the UNIX and local filenames for data file to be */
/* processed; we always report the original file name, but we */
/* always look at and/or update the spool copy of the data; we */
/* never alter or delete the original */
/*--------------------------------------------------------------------*/
if ( this_call == SEND_CALL )
{
time_t created;
long size;
if (equal(dname, "D.0"))
strcpy( host, fname );
else
importpath( host, dname, remote );
created = stater( host, &size);
switch ( action )
{
case JOB_STATUS:
current->created = created;
current->size = size;
if ((created != -1) &&
(equaln(tname ,"X.",2))) // Execute file?
{
open_data( host, user, sys, current->name );
current->execute = TRUE;
}
else {
current->execute = FALSE;
strcpy( current->name , fname );
}
break;
case JOB_KILL:
if ((created != -1) && !equal(dname, "D.0"))
{
unlink( host );
printf("Deleted file %s (%s)\n", dname, host);
}
break;
case JOB_REFRESH:
if ((created != -1) && !equal(dname, "D.0"))
touch( host );
break;
default:
panic();
} /* switch */
}
else if ( action == JOB_STATUS )
{
current->execute = FALSE;
strcpy( current->name , fname );
current->created = stater( callname, ¤t->size);
}
break;
default:
printmsg(0,"Invalid line \"%s\" in call file \"%s\"",
buf, callname);
break;
} /* switch */
} /* while */
/*--------------------------------------------------------------------*/
/* Clean up and return to caller */
/*--------------------------------------------------------------------*/
if (ferror( stream ))
{
printerr( callname );
clearerr( stream );
}
fclose( stream );
return this_call;
} /* open call */
/*--------------------------------------------------------------------*/
/* o p e n _ d a t a */
/* */
/* Process a single execute file */
/*--------------------------------------------------------------------*/
static void open_data(const char *file,
char *user,
char *sys,
char *command)
{
FILE *data_fp;
char data_buf[BUFSIZ];
char *token = "(none)";
static char f_name[ FILENAME_MAX ];
size_t bytes = 0;
printmsg(1,"INSIDE OPEN_DATA(%s)",file);
*f_name = '\0';
printmsg(1,"OPENING(%s)",file);
data_fp = FOPEN(file, "r", BINARY_MODE);
if(data_fp == NULL){
printerr( file );
panic();
}
printmsg(1,"OPEN (%s) SIZE (%d)", file, BUFSIZ);
while(fgets(data_buf, (int) BUFSIZ, data_fp) != NULL){
size_t len = strlen( data_buf );
bytes += strlen( data_buf );
if ( data_buf[ --len ] == '\n')
data_buf[ len ] = '\0';
/*--------------------------------------------------------------------*/
/* Determine what kind of line it is */
/*--------------------------------------------------------------------*/
switch(data_buf[0]){
case '#':
printmsg(5,"COMMENT %s", data_buf);
break;
case 'U':
token = strtok( data_buf + 1, WHITESPACE );
if ( token == NULL )
break;
strncpy( user, token , MAXL );
user[ MAXL-1 ] = '\0';
token = strtok( NULL , WHITESPACE );
if ( token == NULL )
break;
strncpy( sys, token , MAXL);
sys[ MAXL-1 ] = '\0';
printmsg(1,"SYSTEM = (%s), USER = (%s)",sys,user);
break;
case 'F':
printmsg(5,"File %s", data_buf);
token = strtok( data_buf + 1 , WHITESPACE );
strncpy( f_name, token , FILENAME_MAX );
f_name[ FILENAME_MAX - 1 ] = '\0';
break;
case 'I':
printmsg(5,"Input %s", data_buf);
break;
case 'C':
printmsg(1,"Command %s", data_buf);
token = strchr(data_buf,' ') + 1;
strncpy(command, token , FILENAME_MAX - 1);
command[ FILENAME_MAX - 1] = '\0';
break;
default:
printmsg(1,"UNKNOWN LINE %s", data_buf);
break;
} /* switch */
} /* while */
printmsg(1,"CLOSED (%s), bytes = %d, d file = %s", file, bytes, token);
fclose(data_fp);
} /* open_data */
/*--------------------------------------------------------------------*/
/* p r i n t _ a l l */
/* */
/* Print all the information related to a job in the spool */
/*--------------------------------------------------------------------*/
static void print_all( char *job,
struct data_queue *current ,
const char *user,
const char *sys )
{
char blanks[FILENAME_MAX];
size_t subscript = 0;
/*--------------------------------------------------------------------*/
/* Create a blank buffer for printing all of the first line of data */
/*--------------------------------------------------------------------*/
while ( job[subscript] != '\0')
blanks[subscript++] = ' ';
blanks[ subscript ] = '\0';
/*--------------------------------------------------------------------*/
/* Loop through the files for this job */
/*--------------------------------------------------------------------*/
while ( current != NULL )
{
struct data_queue *save_data = current->next_link;
if ( current->execute)
printf("%s %s %c %-8.8s %-8.8s %s\n", job,
dater( current->created, NULL ),
current->type,
sys, user, current->name );
else
printf("%s %s %c %-8.8s %-8.8s %ld %s\n", job,
dater( current->created, NULL ),
current->type,
sys, user, current->size , current->name );
job = blanks; // Don't print job name more than once
free( current ); // Release the abused storage
current = save_data;
} /* while */
} /* print_all */
/*--------------------------------------------------------------------*/
/* i s _ j o b */
/* */
/* Determine if a file is a valid job */
/* */
/* The task of finding a proper job made is harder by the fact */
/* UUPC inserts all these jobs into separate directories. We */
/* brute force it, checking all known hosts for the wayward */
/* file. This is relatively cheap, since most hosts will fail */
/* on the host name and thus we never look on disk. Since job */
/* sequence numbers are global across UUPC/extende, a false hit */
/* on the host doesn't hurt because the job number will never */
/* match. */
/*--------------------------------------------------------------------*/
static char *is_job(const char *callfile)
{
struct HostTable *hostp;
char host[FILENAME_MAX];
boolean hit = FALSE;
/*--------------------------------------------------------------------*/
/* Get the first system to process */
/*--------------------------------------------------------------------*/
hostp = nexthost( TRUE );
/*--------------------------------------------------------------------*/
/* Begin loop to display local system */
/*--------------------------------------------------------------------*/
while(hostp != BADHOST )
{
if (equaln(hostp->hostname, &callfile[2],
min( strlen( hostp->hostname ), HOSTLEN)))
// Right host?
{ // Maybe --> Look for the file
importpath( host, callfile, hostp->hostname);
if ( !access( host, 0 )) // Does the host file exist?
return hostp->hostname; // Yes --> Return success
hit = TRUE;
}
hostp = nexthost( FALSE );
} /* while */
/*--------------------------------------------------------------------*/
/* We didn't get the host; report an error and exit */
/*--------------------------------------------------------------------*/
if ( hit )
printf("Unable to locate call file %s -- run uustat -a\n", callfile );
else
printf("Unable to locate call file %s -- hostname may be incorrect\n",
callfile);
exit(1);
return NULL; // Make C compiler happy
} /* is_job */
/*--------------------------------------------------------------------*/
/* t o u c h */
/* */
/* Update list modified time for a file by opening and closing it */
/*--------------------------------------------------------------------*/
static void touch( const char *fname)
{
printf("touch: function not available. Parameter was \"%s\"\n",
fname);
} /* touch */
/*--------------------------------------------------------------------*/
/* u s a g e */
/* */
/* Report how to use program */
/*--------------------------------------------------------------------*/
static void usage( void )
{
fputs("Usage:\tuustat\t[-m | -q | -a] [-u userid | all ] [-s system | all] [-x debug]\n\
\t\t[-k | -r ] jobid [-x debug]\n\
\t\t[-P system | all] [-x debug]\n\n\
\tDefault is to display jobs queued by current user\n\
\t-a\t\tDisplays all jobs for all users\n\
\t-k jobid\tKills job \"jobid\"\n\
\t-m\t\tDisplays accessability of known systems\n\
\t-q\t\tDisplays summary of queues for systems with work\n\
\t-r jobid\tRefreshes timestamps on job \"jobid\"\n\
\t-s system\tRestricts output to system (Ignored by -k -P -r)\n\
\t-u userid\tRestricts output to userid (Ignored by -k -m -P -q -r)\n\
\t-P system\tQueues dummy job for system \"system\" to force poll\n\
\t-x debuglevel",
stdout );
exit(1);
} /* usage */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -