Deleted Added
full compact
yppush_main.c (90297) yppush_main.c (90298)
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#ifndef lint
34static const char rcsid[] =
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#ifndef lint
34static const char rcsid[] =
35 "$FreeBSD: head/usr.sbin/yppush/yppush_main.c 90297 2002-02-06 13:30:31Z des $";
35 "$FreeBSD: head/usr.sbin/yppush/yppush_main.c 90298 2002-02-06 15:26:07Z des $";
36#endif /* not lint */
37
38#include <errno.h>
39#include <signal.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <time.h>

--- 39 unchanged lines hidden (view full) ---

83 struct jobs *next;
84};
85
86struct jobs *yppush_joblist; /* Linked list of running jobs. */
87
88/*
89 * Local error messages.
90 */
36#endif /* not lint */
37
38#include <errno.h>
39#include <signal.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <time.h>

--- 39 unchanged lines hidden (view full) ---

83 struct jobs *next;
84};
85
86struct jobs *yppush_joblist; /* Linked list of running jobs. */
87
88/*
89 * Local error messages.
90 */
91static char *yppusherr_string(err)
92 int err;
91static char *
92yppusherr_string(int err)
93{
94 switch (err) {
95 case YPPUSH_TIMEDOUT: return("transfer or callback timed out");
96 case YPPUSH_YPSERV: return("failed to contact ypserv");
97 case YPPUSH_NOHOST: return("no such host");
98 case YPPUSH_PMAP: return("portmapper failure");
99 default: return("unknown error code");
100 }
101}
102
103/*
104 * Report state of a job.
105 */
93{
94 switch (err) {
95 case YPPUSH_TIMEDOUT: return("transfer or callback timed out");
96 case YPPUSH_YPSERV: return("failed to contact ypserv");
97 case YPPUSH_NOHOST: return("no such host");
98 case YPPUSH_PMAP: return("portmapper failure");
99 default: return("unknown error code");
100 }
101}
102
103/*
104 * Report state of a job.
105 */
106static int yppush_show_status(status, tid)
107 ypxfrstat status;
108 unsigned long tid;
106static int
107yppush_show_status(ypxfrstat status, unsigned long tid)
109{
110 struct jobs *job;
111
112 job = yppush_joblist;
113
114 while (job) {
115 if (job->tid == tid)
116 break;

--- 20 unchanged lines hidden (view full) ---

137
138 svc_unregister(job->prognum, 1);
139
140 yppush_running_jobs--;
141 return(0);
142}
143
144/* Exit routine. */
108{
109 struct jobs *job;
110
111 job = yppush_joblist;
112
113 while (job) {
114 if (job->tid == tid)
115 break;

--- 20 unchanged lines hidden (view full) ---

136
137 svc_unregister(job->prognum, 1);
138
139 yppush_running_jobs--;
140 return(0);
141}
142
143/* Exit routine. */
145static void yppush_exit(now)
146 int now;
144static void
145yppush_exit(int now)
147{
148 struct jobs *jptr;
149 int still_pending = 1;
150
151 /* Let all the information trickle in. */
152 while (!now && still_pending) {
153 jptr = yppush_joblist;
154 still_pending = 0;

--- 43 unchanged lines hidden (view full) ---

198
199 exit(0);
200}
201
202/*
203 * Handler for 'normal' signals.
204 */
205
146{
147 struct jobs *jptr;
148 int still_pending = 1;
149
150 /* Let all the information trickle in. */
151 while (!now && still_pending) {
152 jptr = yppush_joblist;
153 still_pending = 0;

--- 43 unchanged lines hidden (view full) ---

197
198 exit(0);
199}
200
201/*
202 * Handler for 'normal' signals.
203 */
204
206static void handler(sig)
207 int sig;
205static void
206handler(int sig)
208{
209 if (sig == SIGTERM || sig == SIGINT || sig == SIGABRT) {
210 yppush_jobs = 0;
211 yppush_exit(1);
212 }
213
214 if (sig == SIGALRM) {
215 alarm(0);
216 yppush_alarm_tripped++;
217 }
218
219 return;
220}
221
222/*
223 * Dispatch loop for callback RPC services.
224 */
207{
208 if (sig == SIGTERM || sig == SIGINT || sig == SIGABRT) {
209 yppush_jobs = 0;
210 yppush_exit(1);
211 }
212
213 if (sig == SIGALRM) {
214 alarm(0);
215 yppush_alarm_tripped++;
216 }
217
218 return;
219}
220
221/*
222 * Dispatch loop for callback RPC services.
223 */
225static void yppush_svc_run()
224static void
225yppush_svc_run(void)
226{
227#ifdef FD_SETSIZE
228 fd_set readfds;
229#else
230 int readfds;
231#endif /* def FD_SETSIZE */
232 struct timeval timeout;
233

--- 23 unchanged lines hidden (view full) ---

257}
258
259/*
260 * Special handler for asynchronous socket I/O. We mark the
261 * sockets of the callback handlers as O_ASYNC and handle SIGIO
262 * events here, which will occur when the callback handler has
263 * something interesting to tell us.
264 */
226{
227#ifdef FD_SETSIZE
228 fd_set readfds;
229#else
230 int readfds;
231#endif /* def FD_SETSIZE */
232 struct timeval timeout;
233

--- 23 unchanged lines hidden (view full) ---

257}
258
259/*
260 * Special handler for asynchronous socket I/O. We mark the
261 * sockets of the callback handlers as O_ASYNC and handle SIGIO
262 * events here, which will occur when the callback handler has
263 * something interesting to tell us.
264 */
265static void async_handler(sig)
266 int sig;
265static void
266async_handler(int sig)
267{
268 yppush_svc_run();
269
270 /* reset any pending alarms. */
271 alarm(0);
272 yppush_alarm_tripped++;
273 kill(getpid(), SIGALRM);
274 return;

--- 16 unchanged lines hidden (view full) ---

291 static char * result;
292 yppush_show_status(argp->status, argp->transid);
293 return((void *) &result);
294}
295
296/*
297 * Transmit a YPPROC_XFR request to ypserv.
298 */
267{
268 yppush_svc_run();
269
270 /* reset any pending alarms. */
271 alarm(0);
272 yppush_alarm_tripped++;
273 kill(getpid(), SIGALRM);
274 return;

--- 16 unchanged lines hidden (view full) ---

291 static char * result;
292 yppush_show_status(argp->status, argp->transid);
293 return((void *) &result);
294}
295
296/*
297 * Transmit a YPPROC_XFR request to ypserv.
298 */
299static int yppush_send_xfr(job)
300 struct jobs *job;
299static int
300yppush_send_xfr(struct jobs *job)
301{
302 ypreq_xfr req;
303/* ypresp_xfr *resp; */
304 DBT key, data;
305 CLIENT *clnt;
306 struct rpc_err err;
307 struct timeval timeout;
308

--- 70 unchanged lines hidden (view full) ---

379 return(0);
380}
381
382/*
383 * Main driver function. Register the callback service, add the transfer
384 * request to the internal list, send the YPPROC_XFR request to ypserv
385 * do other magic things.
386 */
301{
302 ypreq_xfr req;
303/* ypresp_xfr *resp; */
304 DBT key, data;
305 CLIENT *clnt;
306 struct rpc_err err;
307 struct timeval timeout;
308

--- 70 unchanged lines hidden (view full) ---

379 return(0);
380}
381
382/*
383 * Main driver function. Register the callback service, add the transfer
384 * request to the internal list, send the YPPROC_XFR request to ypserv
385 * do other magic things.
386 */
387int yp_push(server, map, tid)
388 char *server;
389 char *map;
390 unsigned long tid;
387int
388yp_push(char *server, char *map, unsigned long tid)
391{
392 unsigned long prognum;
393 int sock = RPC_ANYSOCK;
394 SVCXPRT *xprt;
395 struct jobs *job;
396
397 /*
398 * Register the callback service on the first free

--- 66 unchanged lines hidden (view full) ---

465
466 return(0);
467}
468
469/*
470 * Called for each entry in the ypservers map from yp_get_map(), which
471 * is our private yp_all() routine.
472 */
389{
390 unsigned long prognum;
391 int sock = RPC_ANYSOCK;
392 SVCXPRT *xprt;
393 struct jobs *job;
394
395 /*
396 * Register the callback service on the first free

--- 66 unchanged lines hidden (view full) ---

463
464 return(0);
465}
466
467/*
468 * Called for each entry in the ypservers map from yp_get_map(), which
469 * is our private yp_all() routine.
470 */
473int yppush_foreach(status, key, keylen, val, vallen, data)
474 int status;
475 char *key;
476 int keylen;
477 char *val;
478 int vallen;
479 char *data;
471int
472yppush_foreach(int status, char *key, int keylen, char *val, int vallen,
473 char *data)
480{
481 char server[YPMAXRECORD + 2];
482
483 if (status != YP_TRUE)
484 return (status);
485
486 snprintf(server, sizeof(server), "%.*s", vallen, val);
487

--- 37 unchanged lines hidden (view full) ---

525 " [-p path] mapname");
526 exit(1);
527}
528
529/*
530 * Entry point. (About time!)
531 */
532int
474{
475 char server[YPMAXRECORD + 2];
476
477 if (status != YP_TRUE)
478 return (status);
479
480 snprintf(server, sizeof(server), "%.*s", vallen, val);
481

--- 37 unchanged lines hidden (view full) ---

519 " [-p path] mapname");
520 exit(1);
521}
522
523/*
524 * Entry point. (About time!)
525 */
526int
533main(argc,argv)
534 int argc;
535 char *argv[];
527main(int argc, char *argv[])
536{
537 int ch;
538 DBT key, data;
539 char myname[MAXHOSTNAMELEN];
540 struct hostlist {
541 char *name;
542 struct hostlist *next;
543 };

--- 117 unchanged lines hidden (view full) ---

661 if (yppush_hostlist) {
662 /*
663 * Host list was specified on the command line:
664 * kick off the transfers by hand.
665 */
666 tmp = yppush_hostlist;
667 while (tmp) {
668 yppush_foreach(YP_TRUE, NULL, 0, tmp->name,
528{
529 int ch;
530 DBT key, data;
531 char myname[MAXHOSTNAMELEN];
532 struct hostlist {
533 char *name;
534 struct hostlist *next;
535 };

--- 117 unchanged lines hidden (view full) ---

653 if (yppush_hostlist) {
654 /*
655 * Host list was specified on the command line:
656 * kick off the transfers by hand.
657 */
658 tmp = yppush_hostlist;
659 while (tmp) {
660 yppush_foreach(YP_TRUE, NULL, 0, tmp->name,
669 strlen(tmp->name));
661 strlen(tmp->name), NULL);
670 tmp = tmp->next;
671 }
672 } else {
673 /*
674 * Do a yp_all() on the ypservers map and initiate a ypxfr
675 * for each one.
676 */
677 ypxfr_get_map("ypservers", yppush_domain,

--- 12 unchanged lines hidden ---
662 tmp = tmp->next;
663 }
664 } else {
665 /*
666 * Do a yp_all() on the ypservers map and initiate a ypxfr
667 * for each one.
668 */
669 ypxfr_get_map("ypservers", yppush_domain,

--- 12 unchanged lines hidden ---