Commit | Line | Data |
---|---|---|
29e83471 RC |
1 | #ifndef lint |
2 | static char *sccsid = "@(#)main.c 4.1 (Berkeley) 83/09/07"; | |
3 | #endif | |
4 | ||
5 | #include "defs.h" | |
6 | ||
7 | /* | |
8 | * Remote distribution program. | |
9 | */ | |
10 | ||
11 | char *distfile = "distfile"; | |
12 | char *tmpfile = "/tmp/rdistXXXXXX"; | |
13 | ||
14 | int debug; /* debugging flag */ | |
15 | int nflag; /* NOP flag, just print commands without executing */ | |
16 | int qflag; /* Quiet. Don't print messages */ | |
17 | int vflag; /* verify only */ | |
18 | int yflag; /* update iff remote younger than master */ | |
19 | int iamremote; /* act as remote server for transfering files */ | |
20 | ||
21 | int filec; /* number of files to update */ | |
22 | char **filev; /* list of files/directories to update */ | |
23 | FILE *fin = NULL; /* input file pointer */ | |
24 | int rem = 0; /* file descriptor to remote source/sink process */ | |
25 | char host[32]; /* host name */ | |
26 | int errs; /* number of errors while sending/receiving */ | |
27 | char user[10]; /* user's name */ | |
28 | char homedir[128]; /* user's home directory */ | |
29 | int userid; /* user's user ID */ | |
30 | int usergid; /* user's group ID */ | |
31 | ||
32 | int cleanup(); | |
33 | int lostconn(); | |
34 | ||
35 | main(argc, argv) | |
36 | int argc; | |
37 | char *argv[]; | |
38 | { | |
39 | register char *arg; | |
40 | register struct passwd *pw; | |
41 | ||
42 | setpwent(); | |
43 | pw = getpwuid(userid = getuid()); | |
44 | endpwent(); | |
45 | if (pw == NULL) { | |
46 | fprintf(stderr, "rdist: Who are you?\n"); | |
47 | exit(1); | |
48 | } | |
49 | strcpy(user, pw->pw_name); | |
50 | strcpy(homedir, pw->pw_dir); | |
51 | usergid = pw->pw_gid; | |
52 | gethostname(host, sizeof(host)); | |
53 | ||
54 | while (--argc > 0) { | |
55 | if ((arg = *++argv)[0] != '-') | |
56 | break; | |
57 | if (!strcmp(arg, "-Server")) | |
58 | iamremote++; | |
59 | else while (*++arg) | |
60 | switch (*arg) { | |
61 | case 'f': | |
62 | if (--argc <= 0) | |
63 | usage(); | |
64 | distfile = *++argv; | |
65 | if (distfile[0] == '-' && distfile[1] == '\0') | |
66 | fin = stdin; | |
67 | break; | |
68 | ||
69 | case 'd': | |
70 | debug++; | |
71 | break; | |
72 | ||
73 | case 'n': | |
74 | nflag++; | |
75 | break; | |
76 | ||
77 | case 'q': | |
78 | qflag++; | |
79 | break; | |
80 | ||
81 | case 'v': | |
82 | vflag++; | |
83 | break; | |
84 | ||
85 | case 'y': | |
86 | yflag++; | |
87 | break; | |
88 | ||
89 | default: | |
90 | usage(); | |
91 | } | |
92 | } | |
93 | signal(SIGPIPE, lostconn); | |
94 | if (iamremote) { | |
95 | server(); | |
96 | exit(errs); | |
97 | } | |
98 | filec = argc; | |
99 | filev = argv; | |
100 | ||
101 | if (fin == NULL && (fin = fopen(distfile, "r")) == NULL) { | |
102 | perror(distfile); | |
103 | exit(1); | |
104 | } | |
105 | mktemp(tmpfile); | |
106 | signal(SIGHUP, cleanup); | |
107 | signal(SIGINT, cleanup); | |
108 | signal(SIGQUIT, cleanup); | |
109 | signal(SIGTERM, cleanup); | |
110 | ||
111 | yyparse(); | |
112 | exit(errs); | |
113 | } | |
114 | ||
115 | usage() | |
116 | { | |
117 | printf("Usage: rdist [-f distfile] [-n] [-q] [-y] [-d] [file ...]\n"); | |
118 | exit(1); | |
119 | } | |
120 | ||
121 | /* | |
122 | * Remove temporary files and do any cleanup operations before exiting. | |
123 | */ | |
124 | cleanup() | |
125 | { | |
126 | (void) unlink(tmpfile); | |
127 | exit(1); | |
128 | } | |
129 | ||
130 | /* | |
131 | * Print a list of NAME blocks (mostly for debugging). | |
132 | */ | |
133 | prnames(bp) | |
134 | register struct block *bp; | |
135 | { | |
136 | printf("( "); | |
137 | while (bp != NULL) { | |
138 | printf("%s ", bp->b_name); | |
139 | bp = bp->b_next; | |
140 | } | |
141 | printf(")\n"); | |
142 | } | |
143 | ||
144 | /*VARARGS*/ | |
145 | warn(fmt, a1, a2,a3) | |
146 | char *fmt; | |
147 | { | |
148 | extern int yylineno; | |
149 | ||
150 | fprintf(stderr, "rdist: line %d: Warning: ", yylineno); | |
151 | fprintf(stderr, fmt, a1, a2, a3); | |
152 | fputc('\n', stderr); | |
153 | } |