xref: /original-bsd/usr.bin/uucp/uupoll/uupoll.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1986, 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1986, 1991, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)uupoll.c	8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17 
18 /*
19  * Poll named system(s).
20  *
21  * The poll occurs even if recent attempts have failed,
22  * but not if L.sys prohibits the call (e.g. wrong time of day).
23  *
24  * Original Author: Tom Truscott (rti!trt)
25  */
26 
27 #include "uucp.h"
28 
29 int TransferSucceeded = 1;
30 struct timeb Now;
31 
32 main(argc, argv)
33 int argc;
34 char **argv;
35 {
36 	char wrkpre[MAXFULLNAME];
37 	char file[MAXFULLNAME];
38 	char grade = 'A';
39 	int nocall = 0;
40 	int c;
41 	char *sysname;
42 	extern char *optarg;
43 	extern int optind;
44 
45 	if (argc < 2) {
46 		fprintf(stderr, "usage: uupoll [-gX] [-n] system ...\n");
47 		cleanup(1);
48 	}
49 
50 	if (chdir(Spool) < 0) {
51 		syslog(LOG_WARNING, "chdir(%s) failed: %m", Spool);
52 		cleanup(1);
53 	}
54 	strcpy(Progname, "uupoll");
55 	uucpname(Myname);
56 
57 	while ((c = getopt(argc, argv, "g:n")) != EOF)
58 		switch(c) {
59 			case 'g':
60 				grade = *optarg;
61 				break;
62 			case 'n':
63 				nocall++;
64 				break;
65 			case '?':
66 			default:
67 				fprintf(stderr, "unknown option %s\n",
68 					argv[optind-1]);
69 		}
70 
71 	while(optind < argc) {
72 		sysname = argv[optind++];
73 		if (strcmp(sysname, Myname) == SAME) {
74 			fprintf(stderr, "This *is* %s!\n", Myname);
75 			continue;
76 		}
77 
78 		if (versys(&sysname)) {
79 			fprintf(stderr, "%s: unknown system.\n", sysname);
80 			continue;
81 		}
82 		/* Remove any STST file that might stop the poll */
83 		sprintf(wrkpre, "%s/LCK..%.*s", LOCKDIR, MAXBASENAME, sysname);
84 		if (access(wrkpre, 0) < 0)
85 			rmstat(sysname);
86 		sprintf(wrkpre, "%c.%.*s", CMDPRE, SYSNSIZE, sysname);
87 		if (!iswrk(file, "chk", Spool, wrkpre)) {
88 			sprintf(file, "%s/%c.%.*s%cPOLL", subdir(Spool, CMDPRE),
89 				CMDPRE, SYSNSIZE, sysname, grade);
90 			close(creat(file, 0666));
91 		}
92 		/* Attempt the call */
93 		if (!nocall)
94 			xuucico(sysname);
95 	}
96 	cleanup(0);
97 }
98 
99 cleanup(code)
100 int code;
101 {
102 	exit(code);
103 }
104