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