summaryrefslogtreecommitdiffstats
path: root/usr.sbin/yppush
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1996-01-31 15:15:47 +0000
committerwpaul <wpaul@FreeBSD.org>1996-01-31 15:15:47 +0000
commita683c772417b7b57b2c047d5f633d5e5b6975607 (patch)
tree7f62e741504af3d4d35a3014114ab268b28703ae /usr.sbin/yppush
parent3aff305a53ccab52cc894e1cf20688335b2386f0 (diff)
downloadFreeBSD-src-a683c772417b7b57b2c047d5f633d5e5b6975607.zip
FreeBSD-src-a683c772417b7b57b2c047d5f633d5e5b6975607.tar.gz
Sync with my sources at home:
- Don't do longjmp()s from inside a signal handler. Even though I got things to work the way I wanted, it's bad karma. - Remember to clear the sa_mask with sigemptyset() before masking signals when using sigaction() to set up the SIGIO handler. - Break out of the wait loop in yppush_exit() when the five minute timeout expires instead of looping around for another pass. If ypxfr on the other end fails somehow and never sends a response, we don't want to wait around forever.
Diffstat (limited to 'usr.sbin/yppush')
-rw-r--r--usr.sbin/yppush/yppush_main.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/usr.sbin/yppush/yppush_main.c b/usr.sbin/yppush/yppush_main.c
index 79d2dac..c96bed40 100644
--- a/usr.sbin/yppush/yppush_main.c
+++ b/usr.sbin/yppush/yppush_main.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: yppush_main.c,v 1.24 1996/01/12 06:21:52 wpaul Exp wpaul $
+ * $Id: yppush_main.c,v 1.25 1996/01/27 19:44:48 wpaul Exp $
*/
#include <stdio.h>
@@ -37,7 +37,9 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
+#ifdef LONGJMP
#include <setjmp.h>
+#endif
#include <time.h>
#include <errno.h>
#include <sys/socket.h>
@@ -54,7 +56,7 @@ struct dom_binding {};
#include "yppush_extern.h"
#ifndef lint
-static const char rcsid[] = "$Id: yppush_main.c,v 1.24 1996/01/12 06:21:52 wpaul Exp wpaul $";
+static const char rcsid[] = "$Id: yppush_main.c,v 1.25 1996/01/27 19:44:48 wpaul Exp $";
#endif
char *progname = "yppush";
@@ -70,8 +72,11 @@ unsigned long yppush_transid = 0;
int yppush_timeout = 80; /* Default timeout. */
int yppush_jobs = 0; /* Number of allowed concurrent jobs. */
int yppush_running_jobs = 0; /* Number of currently running jobs. */
+#ifdef LONGJMP
int yppush_pausing = 0; /* Flag set when longjmp()s are allowed. */
jmp_buf env;
+#endif
+int yppush_alarm_tripped = 0;
/* Structure for holding information about a running job. */
struct jobs {
@@ -150,12 +155,14 @@ static void yppush_exit(now)
int now;
{
struct jobs *jptr;
- int still_pending = 1234;
+ int still_pending = 1;
/* Let all the information trickle in. */
while(!now && still_pending) {
+#ifdef LONGJMP
yppush_pausing++;
setjmp(env); /* more magic */
+#endif
jptr = yppush_joblist;
still_pending = 0;
while (jptr) {
@@ -176,10 +183,17 @@ static void yppush_exit(now)
yp_error("%d transfer%sstill pending",
still_pending,
still_pending > 1 ? "s " : " ");
+ yppush_alarm_tripped = 0;
alarm(YPPUSH_RESPONSE_TIMEOUT);
pause();
+#ifdef LONGJMP
yppush_pausing = 0;
+#endif
alarm(0);
+ if (yppush_alarm_tripped == 1) {
+ yp_error("timed out");
+ now = 1;
+ }
} else {
if (verbose)
yp_error("all transfers complete");
@@ -215,6 +229,7 @@ static void handler(sig)
if (sig == SIGALRM) {
alarm(0);
+ yppush_alarm_tripped++;
}
return;
@@ -270,14 +285,17 @@ static void async_handler(sig)
/* reset any pending alarms. */
alarm(0);
+ yppush_alarm_tripped++;
kill(getpid(), SIGALRM);
+#ifdef LONGJMP
if (yppush_pausing)
longjmp(env, 1);
+#endif
return;
}
/*
- * RPC service routines for callback listener process
+ * RPC service routines for callbacks.
*/
void *
yppushproc_null_1_svc(void *argp, struct svc_req *rqstp)
@@ -493,21 +511,37 @@ int yppush_foreach(status, key, keylen, val, vallen, data)
* wait for one of them to finish so we can reuse its slot.
*/
if (yppush_jobs <= 1) {
+#ifdef LONGJMP
yppush_pausing++;
while (!setjmp(env) && yppush_running_jobs) {
+#else
+ yppush_alarm_tripped = 0;
+ while (!yppush_alarm_tripped && yppush_running_jobs) {
+#endif
alarm(yppush_timeout);
+ yppush_alarm_tripped = 0;
pause();
alarm(0);
}
+#ifdef LONGJMP
yppush_pausing = 0;
+#endif
} else {
+#ifdef LONGJMP
yppush_pausing++;
while (!setjmp(env) && yppush_running_jobs >= yppush_jobs) {
+#else
+ yppush_alarm_tripped = 0;
+ while (!yppush_alarm_tripped && yppush_running_jobs >= yppush_jobs) {
+#endif
alarm(yppush_timeout);
+ yppush_alarm_tripped = 0;
pause();
alarm(0);
}
+#ifdef LONGJMP
yppush_pausing = 0;
+#endif
}
/* Cleared for takeoff: set everything in motion. */
@@ -640,6 +674,7 @@ main(argc,argv)
* other signals are blocked while the handler is running so
* select() doesn't get interrupted.
*/
+ sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGIO); /* Goes without saying. */
sigaddset(&sa.sa_mask, SIGPIPE);
sigaddset(&sa.sa_mask, SIGCHLD);
OpenPOWER on IntegriCloud