home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- *
- * Program Name:jsubmit - Generic Job Server Front-End
- *
- * Filename:jsubmit.c
- *
- * Date Created: November 21, 1988
- *
- * Version: 1.0
- *
- * Programmers:Greg Peto
- *
- * Files used:..\genjob.obj
- *
- * Date Modified: Jan. 28, 1989
- *
- * Comments:
- *
- * This command line utility works in conjucntion with the generic job
- * server utilities JSUPER, and JSERVER. It is designed to let the
- * user submit a dos command line to the job queue for remote
- * execution on a job server machine.
- * See the function of badUsage for summary of possible command line arguments
- * to this utility. All command line arguments are expected in the
- * form:
- * /<command keyword>=<command argument>
- * To locate where global variables are initialized or set, look at
- * ComAndInit for command line settings or for the variables as
- * output variables passed to a function call.
- ****************************************************************************/
-
- /* functions in this file:
- */
- #include"..\genjob.h"
- #include<sys\types.h>
- #include<sys\stat.h>
-
- /* constants definitions */
- #defineVERB_TEST1 /* want verbose test messages */
-
-
- /* global variables and data types */
- COMMAND_ARGS command_args[] =
- /* token, keyword num sig,req. string,req. int */
- {
- # defineCOM_ACKNOWLEDGE1
- {COM_ACKNOWLEDGE,"ACKNOWLEDGE",2, FALSE, FALSE},
-
- # defineCOM_SERVER COM_ACKNOWLEDGE + 1
- {COM_SERVER,"SERVER", 1, TRUE, FALSE},
-
- # defineCOM_NACKNOWLEDGECOM_SERVER + 1
- {COM_NACKNOWLEDGE,"NACKNOWLEDGE",3,FALSE,FALSE}
- };
-
- JOBFILE jobFile; /* buffer of job file */
- CLIENT_REC_AREAjobClientArea;/* buffer of job client record area */
- JobStruct job; /* QMS job struct to be used in calls */
- WORD jobType; /* job type numer */
- BOOLEAN wantServiceRestart= TRUE;
- BOOLEAN doAckMess = TRUE;/* send message when job done */
-
- /* module specific varables and data types */
- /* macro definitions */
-
- /*****************************************************************************/
-
-
- main(argc,argv,envp)
- /* Descrip:
- This program supports the generic job server. This utility
- allow the user ot submit DOS command lines to be executed
- remotely.
- Algorithm://
- Parse and handle command line arguments, initialize defaults
- Get environment info for remote execution
- Put job in queue
- */
- /* Input: */
- int argc;
- char *argv[];
- char *envp[];
-
- { /* main // */
- /*--------------------------------------------------main body */
- if (argc == 1)
- BadUsage(NULL);/* missing command line arguments */
-
- ComAndInit(--argc,++argv);/* skip past program name */
- GetJobEnviron(envp,&jobFile);
- PutJob();
- } /* of main */
-
- /********************************************************************/
-
- BadUsage(message)
- /* Descrip:
- This function is called when a fatal error is detected in the
- command line. It displays the command format and options
- and then exits the program.
- */
- /* Input: */
- char*message;/* optional explanatory message */
-
- { /* BadUsage // */
- /*--------------------------------------------------main body */
- if (message)
- printf("Error: %s\n\n",message);
- printf("usage: jsubmit [<command parameters>] <command line>\n\n");
- printf(" /ACknowledge\n");
- printf(" /NACknowledge\n");
- printf(" /Server=<target server with job queue>\n");
- printf(" <command line> - DOS command line to be executed remotely\n");
-
- exit(1);
- } /* end of BadUsage */
-
- /********************************************************************/
-
- ComAndInit(argc,argv)
- /* Descrip:
- This function parses command line input and sets default values.
- Several global variables may be changed from their default values
- by command line arguments.
- Algorithm://
- Scans command line arguments, overiding defaults as needed.
- See top of this file for notes on expected form of command
- line option and badUsage for specific form of commands.
- Saves remote execution command line in jobClientArea.
- Find server of target queue and save in global variable.
- BUGS:
- Not all command line options implemented yet.
- */
- /* Input: */
- int argc;
- char *argv[];
-
- { /* ComAndInit // */
- /* name of server with job queue */
- char queueServerName[MAX_FSERVER_NAME];
- char argString[MAX_ARG_VAR];/* command parameter variable buffer */
- long argInt; /* numeric parameter variable */
- JOB_TIMEargTime; /* time parameter */
- JOB_DATEargDate; /* date parameter */
- /*--------------------------------------------------main body */
- queueServerName[0] = '\0';
-
- for (;argc; --argc, ++argv)
- {
- if (*argv[0] NOT= '/')
- break;/* no more command line options, quit for loop */
- switch (ScanArg((*argv) + 1,command_args,
- sizeof(command_args)/sizeof(COMMAND_ARGS),
- argString,&argInt,&argTime,&argDate))
- {
- caseCOM_ACKNOWLEDGE:
- doAckMess= TRUE;
- break;
- caseCOM_SERVER:
- if (strlen(argString) > (MAX_FSERVER_NAME - 1))
- {
- printf("Server name length must be less than %d, aborting\n",
- MAX_FSERVER_NAME - 1);
- exit(1);
- }
- strcpy(queueServerName,argString);
- break;
- caseCOM_NACKNOWLEDGE:
- doAckMess= FALSE;
- break;
- default:
- printf("Internal error: ComAndInit");
- exit(1);
- } /* end of switch on ScanArg */
-
- } /* end of for argc loop */
-
- GetCopyCommand(argc,argv);
-
- FindJobServer(queueServerName,TRUE);
- if (jobQueueID == NULL)
- {
- printf("Could not find any server with job queue.\n");
- exit(1);
- }
-
- # if VERB_TEST
- printf("Found server %s, connection ID %x\n",
- queueServerName ? "(default)" : queueServerName,
- jobServerConID);
- # endif
- } /* end of ComAndInit */
-
- /********************************************************************/
-
- GetCopyCommand(argc,argv)
- /* Descrip:
- This function copies the rest of the command line arguments
- into the buffer for the client record area.
- */
- /* Input: */
- intargc;
- char*argv[];
-
- { /* GetCopyCommand // */
- /*--------------------------------------------------main body */
- for (;argc; --argc, ++argv)
- {
- strncat((char *) jobClientArea.jobCommand,*argv);
- strncat(jobClientArea.jobCommand," ");
- }
- # if VERB_TEST
- printf("Remote execute command line: %s\n",jobClientArea.jobCommand);
- # endif
- } /* end of GetCopyCommand */
-
- /********************************************************************/
-
- PutJob()
- /* Descrip:
- This function attempts to put the job in the job queue.
- Algorithm://
- Fill job structure with appropriate values.
- Create job in queue on server.
- Write associated file.
- Close job and file in queue, leave ready for processing.
- */
-
- { /* PutJob // */
- int i;
- int assocFile; /* DOS C handle to job associated file */
- int ccode;
- /*--------------------------------------------------main body */
- SetPreferredConnectionID(jobServerConID);
- /* Set queue job default values */
- if (wantServiceRestart)
- /* automatic requeue if server of job loses connection */
- job.jobControlFlags = QF_SERVICE_RESTART;
-
- job.targetServerIDNumber= -1;/* any server */
- for (i = 0;i < TARGET_TIME_BYTES; i++)
- job.targetExecutionTime[i]= -1;/* soonest time */
-
- job.jobType = jobType;
- strcpy((char *) job.textJobDescription,"Command line job server");
- jobClientArea.v = 'v';
- jobClientArea.period = '.';
- jobClientArea.versionNumber= '0' + JOB_REC_V_NUMBER;
- memcpy(job.clientRecordArea,&jobClientArea,sizeof(jobClientArea));
-
- if (ccode = CreateQueueJobAndFile(jobQueueID,&job,&assocFile))
- {
- switch(ccode)
- {
- case NO_Q_RIGHTS:
- case INVALID_BINDERY_SECURITY:
- case NO_PROPERTY_CREATE_PRIVILEGE:
- printf("Insufficient rights to add a job to queue.\n");
- break;
- case Q_FULL:
- printf("Queue is full, unable add job to queue.\n");
- break;
- case SERVER_BINDERY_LOCKED:
- printf("Bindery locked, unable to add job to queue.\n");
- break;
- case BINDERY_FAILURE:
- printf("Bindery failure, unable to add job to queue.\n");
- break;
- default:
- printf("Unable to create job in queue.\n");
- } /* end of switch */
- exit(1);
- }
-
-
- if (doAckMess)
- on_flag(jobFile.flags,DO_ACK_MESS);
- if (write(assocFile,&jobFile,sizeof(jobFile)) == -1)
- {
- printf("Unable to write to job associated file.\n");
- exit(1);
- }
-
- if (CloseFileAndStartQueueJob(jobQueueID,job.jobNumber,assocFile))
- {
- printf("Unable to finish job entry in queue, submit failed.\n");
- exit(1);
- }
- } /* end of PutJob */
-
- /********************************************************************/
-