xref: /csrg-svn/usr.bin/uucp/vms/startuucp.c (revision 62413)
1*48682Sbostic /*
2*48682Sbostic  * A program to start a uucp batch job (uucico, uuxqt) if it is not
3*48682Sbostic  * already running and pass it the command line.
4*48682Sbostic  *
5*48682Sbostic  * Requires WORLD privilege.
6*48682Sbostic  */
7*48682Sbostic #include <stdio.h>
8*48682Sbostic 
9*48682Sbostic #define	WORKDIR	"/usr/lib/uucp"		/* where id files are kept */
10*48682Sbostic /* primitive error logging - will have to do for now */
11*48682Sbostic #define	LOGFILE	"/usr/lib/uucp/startuucp.err"
12*48682Sbostic #define	JOBID_LINE_FORMAT	"  Job %d entered on queue %s"
13*48682Sbostic #define	FMASK		0111
14*48682Sbostic 
15*48682Sbostic #define	SMR$K_ALTER	0xD	/* Alter Job Attributes SYMBIONT msg */
16*48682Sbostic #define	SMO$K_RLSTIM	0x20	/* Release-time option		    */
17*48682Sbostic 
18*48682Sbostic struct	SYMBIONT_MESSAGE {		/* Message for SYMBIONT Manager */
19*48682Sbostic 	unsigned short int Request;		/* Request number */
20*48682Sbostic 	unsigned char      Queue[16];		/* Queue Name     */
21*48682Sbostic 	unsigned short int JobID;		/* JOB ID number  */
22*48682Sbostic 	unsigned char	   Option;		/* RLSTIM Option  */
23*48682Sbostic 	unsigned char      Time[8];		/* RLSTIM Value   */
24*48682Sbostic 	unsigned char	   End_Options;		/* End of Options */
25*48682Sbostic } Symbiont_Message;
26*48682Sbostic 
main(argc,argv)27*48682Sbostic main(argc,argv)
28*48682Sbostic char *argv[];
29*48682Sbostic {
30*48682Sbostic 	FILE *f;
31*48682Sbostic 	struct {int Size; struct SYMBIONT_MESSAGE *Ptr;} Message_Descr;
32*48682Sbostic 	int i, fd;
33*48682Sbostic 	int JobID;
34*48682Sbostic 	char Queue[64];
35*48682Sbostic 	char jidfile[64];
36*48682Sbostic 	char cmdfile[64];
37*48682Sbostic 
38*48682Sbostic 	if (argc < 2) {
39*48682Sbostic 		fprintf(stderr, "Usage: %s batch-command [args]\n", argv[0]);
40*48682Sbostic 		exit(1);
41*48682Sbostic 	}
42*48682Sbostic 	sprintf(jidfile, "%s/%s.jid", WORKDIR, argv[1]);
43*48682Sbostic 	sprintf(cmdfile, "%s/%s.dat", WORKDIR, argv[1]);
44*48682Sbostic 	umask(FMASK);
45*48682Sbostic 	/*
46*48682Sbostic 	 * Open the command file and write the command line to it.
47*48682Sbostic 	 */
48*48682Sbostic 	if (argc > 2) {
49*48682Sbostic 		if ((fd = creat(cmdfile, 0777, "txt")) > 0) {
50*48682Sbostic 			write(fd, argv[2], strlen(argv[2]));
51*48682Sbostic 			for (i = 3; i < argc; i++) {
52*48682Sbostic 				write(fd, " ", 1);
53*48682Sbostic 				write(fd, argv[i], strlen(argv[i]));
54*48682Sbostic 			}
55*48682Sbostic 			write(fd, "\n", 1);
56*48682Sbostic 			close(fd);
57*48682Sbostic 		} else
58*48682Sbostic 			logerr("%s: can not create\n", cmdfile);
59*48682Sbostic 	}
60*48682Sbostic 	/*
61*48682Sbostic 	 * Open the JOB ID file and extract the Job and QUEUE
62*48682Sbostic 	 */
63*48682Sbostic 	f = fopen(jidfile, "r");
64*48682Sbostic 	if (f == NULL)
65*48682Sbostic 		exit(0);		/* No file, UUCICO running or dead */
66*48682Sbostic 	i = fscanf(f, JOBID_LINE_FORMAT, &JobID, Queue);
67*48682Sbostic 	fclose(f);
68*48682Sbostic 	if (i != 2) {
69*48682Sbostic 		logerr("%s: bad format\n", jidfile);
70*48682Sbostic 		exit(1);		/* No Job, PUNT! */
71*48682Sbostic 	}
72*48682Sbostic 	/*
73*48682Sbostic 	 * Construct the SYMBIONT MANAGER message
74*48682Sbostic 	 */
75*48682Sbostic 	Symbiont_Message.Request = SMR$K_ALTER;	/* Alter Job Attrs. */
76*48682Sbostic 	Symbiont_Message.Queue[0] = strlen(Queue);
77*48682Sbostic 	strcpy(&Symbiont_Message.Queue[1],Queue);	/* In this Queue    */
78*48682Sbostic 	Symbiont_Message.JobID = JobID;		/* This Job	    */
79*48682Sbostic 	Symbiont_Message.Option = SMO$K_RLSTIM;	/* Mod Release Time */
80*48682Sbostic 	sys$gettim(Symbiont_Message.Time);		/*     to NOW	    */
81*48682Sbostic 	Symbiont_Message.End_Options = 0;
82*48682Sbostic 	/*
83*48682Sbostic 	 * Send message to Symbiont Manager
84*48682Sbostic 	 */
85*48682Sbostic 	Message_Descr.Size = sizeof(Symbiont_Message);
86*48682Sbostic 	Message_Descr.Ptr  = &Symbiont_Message;
87*48682Sbostic 	i = sys$sndsmb(&Message_Descr,0);
88*48682Sbostic 	if (!(i & 1)) {
89*48682Sbostic 		logerr("Symbiont error 0x%x Jobid %d Queue %s\n", i, JobID,
90*48682Sbostic 			Queue);
91*48682Sbostic 		exit(1);
92*48682Sbostic 	}
93*48682Sbostic 	/*
94*48682Sbostic 	 * DONE:
95*48682Sbostic 	 */
96*48682Sbostic 	exit(0);
97*48682Sbostic }
98*48682Sbostic 
logerr(fmt,a,b,c,d)99*48682Sbostic logerr(fmt, a, b, c, d)
100*48682Sbostic 	char *fmt;
101*48682Sbostic {
102*48682Sbostic 	long t;
103*48682Sbostic 	char *p, *ctime();
104*48682Sbostic 	FILE *f;
105*48682Sbostic 
106*48682Sbostic 	fprintf(stderr, fmt, a, b, c, d);
107*48682Sbostic 	if ((f = fopen(LOGFILE, "a")) == NULL)
108*48682Sbostic 		return;
109*48682Sbostic 	time(&t);
110*48682Sbostic 	p = ctime(&t);
111*48682Sbostic 	p[24] = '\0';
112*48682Sbostic 	fputs(&p[4], f);
113*48682Sbostic 	fprintf(f, fmt, a, b, c, d);
114*48682Sbostic 	fclose(f);
115*48682Sbostic }
116