📄 uuxqt.c
字号:
else
hostp = checkreal( sysname );
if (hostp == BADHOST) {
printmsg(0, "Unknown host \"%s\".", sysname );
exit(1);
}
} else
hostp = nexthost( TRUE );
/*--------------------------------------------------------------------*/
/* Define mask for execution directory */
/*--------------------------------------------------------------------*/
if (( E_xqtRootDir == NULL ) || equali( E_xqtRootDir, E_spooldir ))
sprintf( executeDirectory, "%s/%%s/XQT", E_spooldir );
// Nice parallel construction
else
sprintf( executeDirectory, "%s/XQT/%%s", E_xqtRootDir);
// Fewer directories than if we
// use the spool version
pattern = newstr( executeDirectory ); // Save pattern for posterity
/*--------------------------------------------------------------------*/
/* Outer loop for processing different hosts */
/*--------------------------------------------------------------------*/
while (hostp != BADHOST)
{
char fname[FILENAME_MAX];
boolean locked = FALSE;
/*--------------------------------------------------------------------*/
/* Initialize security for this remote */
/*--------------------------------------------------------------------*/
if ( !equal(sysname, E_nodename) &&
(securep = GetSecurity( hostp )) == NULL )
printmsg(0,"No security defined for \"%s\","
" cannot process X.* files",
hostp->hostname );
else {
/*--------------------------------------------------------------------*/
/* Set up environment for the machine name */
/*--------------------------------------------------------------------*/
sprintf(hostenv,"%s%.25s", uu_machine, hostp->hostname);
if (putenv( hostenv ))
{
printmsg(0,"Unable to set environment \"%s\"",hostenv);
panic();
}
sprintf(executeDirectory , pattern, hostp->hostname );
printmsg(5,"Execute directory is %s", executeDirectory );
/*--------------------------------------------------------------------*/
/* Inner loop for processing files from one host */
/*--------------------------------------------------------------------*/
while (readnext(fname, hostp->hostname, "X", NULL, NULL, NULL) )
{
if ( locked || LockSystem( hostp->hostname , B_UUXQT ))
{
process( fname , hostp->hostname, executeDirectory );
locked = TRUE;
}
else
break; // We didn't get the lock
} /* while */
if ( locked )
UnlockSystem();
} /* else if */
/*--------------------------------------------------------------------*/
/* Restore environment */
/*--------------------------------------------------------------------*/
putenv( uu_machine ); // Reset to empty string
/*--------------------------------------------------------------------*/
/* If processing all hosts, step to the next host in the queue */
/*--------------------------------------------------------------------*/
if( equal(sysname,"all") )
hostp = nexthost( FALSE );
else
hostp = BADHOST;
} /*while nexthost*/
return FALSE;
} /* do_uuxqt */
/*--------------------------------------------------------------------*/
/* p r o c e s s */
/* */
/* Process a single execute file */
/*--------------------------------------------------------------------*/
static void process( const char *fname,
const char *remote,
const char *executeDirectory)
{
char *command = NULL,
*input = NULL,
*output = NULL,
*job_id = NULL,
*token = NULL,
line[BUFSIZ];
char hostfile[FILENAME_MAX];
boolean skip = FALSE;
boolean reject = FALSE;
FILE *fxqt;
int status;
char *outnode = NULL;
char *outname = NULL;
char *user = NULL;
char *requestor = NULL;
char *statfil = NULL;
char *machine = NULL;
char **envp;
boolean xflag[UU_LAST - 1] = { 0 };
time_t jtime = time(NULL);
/*--------------------------------------------------------------------*/
/* Open the X.* file */
/*--------------------------------------------------------------------*/
if ( (fxqt = FOPEN(fname, "r", BINARY_MODE)) == NULL)
{
printerr(fname);
return;
}
else
printmsg(2, "processing %s", fname);
/*--------------------------------------------------------------------*/
/* Begin loop to read the X.* file */
/*--------------------------------------------------------------------*/
while (!skip & (fgets(line, BUFSIZ, fxqt) != NULL))
{
char *cp;
if ( (cp = strchr(line, '\n')) != NULL )
*cp = '\0';
printmsg(5, "Input read: %s", line);
/*--------------------------------------------------------------------*/
/* Process the input line according to its type */
/*--------------------------------------------------------------------*/
switch (line[0])
{
case '#':
break;
/*--------------------------------------------------------------------*/
/* User which submitted the command */
/*--------------------------------------------------------------------*/
case 'U':
if ( (cp = strtok(line + 1,WHITESPACE)) == NULL )
{
printmsg(0,"No user on U line in file \"%s\"", fname );
reject = TRUE;
break;
}
else {
user = strdup(cp);
checkref(user);
};
// Get the system name
if ( (cp = strtok(NULL,WHITESPACE)) == NULL)
{ // Did we get a string?
printmsg(2,"No node on U line in file \"%s\"", fname );
cp = (char *) remote;
}
else if (!equal(cp,remote))
{
printmsg(2,"Node on U line in file \"%s\" doesn't match remote",
fname );
cp = (char * ) remote;
};
machine = newstr(cp);
break;
/*--------------------------------------------------------------------*/
/* Input file for command */
/*--------------------------------------------------------------------*/
case 'I':
cp = strtok( line + 1, WHITESPACE );
if ( cp == NULL )
{
printmsg(0,"No input file name on I line");
reject = TRUE;
}
else {
input = strdup( cp );
checkref(input);
if (!equal(remote, E_nodename) &&
!(equaln(input,"D.",2) || ValidateFile( input, ALLOW_READ)))
{
reject = TRUE;
xflag[S_NOREAD] = TRUE;
}
} /* else */
break;
/*--------------------------------------------------------------------*/
/* Output file for command */
/*--------------------------------------------------------------------*/
case 'O':
if ( (cp = strtok(line + 1, WHITESPACE)) != NULL )
{
outname = strdup(cp);
checkref(outname);
xflag[X_OUTPUT] = TRUE; // return output to "outnode"
if ( (cp = strtok(NULL,WHITESPACE)) != NULL)
{ // Did we get a string?
outnode = strdup(cp);
checkref(outnode);
checkreal(outnode);
}
else if (!equal(remote, E_nodename))
{
if (!(equaln(outname,"D.",2) || ValidateFile( outname, ALLOW_WRITE)))
{
reject = TRUE;
xflag[S_NOWRITE] = TRUE;
} /* if */
} /* else if (!equal(remote, E_nodename)) */
} /* if ( (cp = strtok(NULL,WHITESPACE)) != NULL ) */
break;
/*--------------------------------------------------------------------*/
/* Command to execute */
/*--------------------------------------------------------------------*/
case 'C':
cp = strtok( line + 2, "\r\n" );
if ( cp == NULL )
{
printmsg(0,"No command name on C line");
reject = TRUE;
}
else {
command = strdup( cp );
checkref(command);
}
break;
/*--------------------------------------------------------------------*/
/* Job Id for status reporting */
/*--------------------------------------------------------------------*/
case 'J':
if ( (cp = strtok(line + 1, WHITESPACE)) == NULL )
{
printmsg(0,"No job id on J line in file \"%s\"", fname );
reject = TRUE;
}
else {
job_id = strdup( cp );
checkref( job_id );
} /* else */
break;
/*--------------------------------------------------------------------*/
/* Check that a required file exists */
/*--------------------------------------------------------------------*/
case 'F':
token = strtok(line + 1, WHITESPACE);
importpath(hostfile, token, remote);
if ( access( hostfile, 0 )) // Does the host file exist?
{ // No --> Skip the file
printmsg(0,"Missing file %s (%s) for %s, command skipped",
token, hostfile, fname);
skip = TRUE;
}
break;
/*--------------------------------------------------------------------*/
/* Requestor name (overrides user name, above) */
/*--------------------------------------------------------------------*/
case 'R':
if ( (cp = strtok(line + 1,WHITESPACE)) == NULL )
{
printmsg(0,"No requestor on R line in file \"%s\"", fname );
reject = TRUE;
}
else {
requestor = strdup(cp);
checkref(requestor);
}
break;
/*--------------------------------------------------------------------*/
/* Status file name to return info to on remote node */
/*--------------------------------------------------------------------*/
case 'M':
if ( (cp = strtok(line + 1, WHITESPACE)) == NULL )
printmsg(0,"No file name on M line in file \"%s\"", fname);
else {
statfil = strdup(cp);
checkref(statfil);
xflag[X_STATFIL] = TRUE; // return status to remote file
}
break;
/*--------------------------------------------------------------------*/
/* Flag fields */
/*--------------------------------------------------------------------*/
case 'Z': xflag[X_FAILED] = TRUE; // send status if command failed
break;
case 'N': xflag[X_FAILED] = FALSE; // send NO status if command failed
break;
case 'n': xflag[X_SUCCESS] = TRUE; // send status if command succeeded
break;
case 'z': xflag[X_SUCCESS] = FALSE; // NO status if command succeeded
break;
case 'B': xflag[X_INPUT] = TRUE; // return command input on error
break;
case 'e': xflag[X_USEEXEC] = FALSE; // process command using sh(1)
break;
case 'E': xflag[X_USEEXEC] = TRUE; // process command using exec(2)
break;
/*--------------------------------------------------------------------*/
/* Quietly ignore unknown fields */
/*--------------------------------------------------------------------*/
default :
break;
} /* switch */
} /* while (!skip & (fgets(line, BUFSIZ, fxqt) != NULL)) */
if ( fxqt != NULL )
fclose(fxqt);
if ((command == NULL) && !skip)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -