Add a -q <quit-time> flag to abort a transfer if it has stalled for <quit-time>
seconds. Ok'd by luke.
This commit is contained in:
parent
18e50dcd89
commit
8bb1db1740
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: ftp.1,v 1.85 2002/07/07 10:40:31 lukem Exp $
|
||||
.\" $NetBSD: ftp.1,v 1.86 2002/08/27 13:11:02 christos Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
|
@ -88,6 +88,9 @@ Internet file transfer program
|
|||
.Op Fl P Ar port
|
||||
.Ek
|
||||
.Bk -words
|
||||
.Op Fl q Ar quittime
|
||||
.Ek
|
||||
.Bk -words
|
||||
.Op Fl r Ar retry
|
||||
.Ek
|
||||
.Bk -words
|
||||
|
@ -275,6 +278,10 @@ Sets the port number to
|
|||
Retry the connection attempt if it failed, pausing for
|
||||
.Ar wait
|
||||
seconds.
|
||||
.It Fl q Ar quittime
|
||||
Quit if the connection has stalled for
|
||||
.Ar quittime
|
||||
seconds.
|
||||
.It Fl R
|
||||
Restart all non-proxied auto-fetches.
|
||||
.It Fl t
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ftp_var.h,v 1.62 2001/12/26 09:40:16 lukem Exp $ */
|
||||
/* $NetBSD: ftp_var.h,v 1.63 2002/08/27 13:11:02 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2001 The NetBSD Foundation, Inc.
|
||||
|
@ -255,6 +255,7 @@ GLOBAL int bytesize; /* local byte size in binary */
|
|||
GLOBAL int anonftp; /* automatic anonymous login */
|
||||
GLOBAL int dirchange; /* remote directory changed by cd command */
|
||||
GLOBAL int flushcache; /* set HTTP cache flush headers with request */
|
||||
GLOBAL int quit_time; /* maximum time to wait if stalled */
|
||||
GLOBAL int rate_get; /* maximum get xfer rate */
|
||||
GLOBAL int rate_get_incr; /* increment for get xfer rate */
|
||||
GLOBAL int rate_put; /* maximum put xfer rate */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.82 2002/06/05 13:51:54 lukem Exp $ */
|
||||
/* $NetBSD: main.c,v 1.83 2002/08/27 13:11:02 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
||||
|
@ -108,7 +108,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.82 2002/06/05 13:51:54 lukem Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.83 2002/08/27 13:11:02 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -281,7 +281,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
while ((ch = getopt(argc, argv, "46AadefginN:o:pP:r:RtT:u:vV")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:RtT:u:vV")) != -1) {
|
||||
switch (ch) {
|
||||
case '4':
|
||||
family = AF_INET;
|
||||
|
@ -353,6 +353,12 @@ main(int argc, char *argv[])
|
|||
ftpport = optarg;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
quit_time = strtol(optarg, &ep, 10);
|
||||
if (quit_time < 1 || *ep != '\0')
|
||||
errx(1, "bad quit value: %s", optarg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
retry_connect = strtol(optarg, &ep, 10);
|
||||
if (retry_connect < 1 || *ep != '\0')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: util.c,v 1.108 2002/06/08 14:44:07 yamt Exp $ */
|
||||
/* $NetBSD: util.c,v 1.109 2002/08/27 13:11:02 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
|
||||
|
@ -75,7 +75,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: util.c,v 1.108 2002/06/08 14:44:07 yamt Exp $");
|
||||
__RCSID("$NetBSD: util.c,v 1.109 2002/08/27 13:11:02 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -858,9 +858,11 @@ void
|
|||
progressmeter(int flag)
|
||||
{
|
||||
static off_t lastsize;
|
||||
off_t cursize;
|
||||
struct timeval now, wait;
|
||||
#ifndef NO_PROGRESS
|
||||
struct timeval now, td, wait;
|
||||
off_t cursize, abbrevsize, bytespersec;
|
||||
struct timeval td;
|
||||
off_t abbrevsize, bytespersec;
|
||||
double elapsed;
|
||||
int ratio, barlength, i, len, remaining;
|
||||
|
||||
|
@ -890,6 +892,37 @@ progressmeter(int flag)
|
|||
lastupdate = start;
|
||||
lastsize = restart_point;
|
||||
}
|
||||
|
||||
(void)gettimeofday(&now, NULL);
|
||||
cursize = bytes + restart_point;
|
||||
timersub(&now, &lastupdate, &wait);
|
||||
if (cursize > lastsize) {
|
||||
lastupdate = now;
|
||||
lastsize = cursize;
|
||||
wait.tv_sec = 0;
|
||||
} else {
|
||||
if (quit_time > 0 && wait.tv_sec > quit_time) {
|
||||
len = snprintf(buf, sizeof(buf), "\r\n%s: "
|
||||
"transfer aborted because stalled for %lu sec.\r\n",
|
||||
getprogname(), (unsigned long)wait.tv_sec);
|
||||
(void)write(fileno(ttyout), buf, len);
|
||||
(void)xsignal(SIGALRM, SIG_DFL);
|
||||
alarmtimer(0);
|
||||
siglongjmp(toplevel, 1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Always set the handler even if we are not the foreground process.
|
||||
*/
|
||||
if (quit_time > 0 || progress) {
|
||||
if (flag == -1) {
|
||||
(void)xsignal_restart(SIGALRM, updateprogressmeter, 1);
|
||||
alarmtimer(1); /* set alarm timer for 1 Hz */
|
||||
} else if (flag == 1) {
|
||||
(void)xsignal(SIGALRM, SIG_DFL);
|
||||
alarmtimer(0);
|
||||
}
|
||||
}
|
||||
#ifndef NO_PROGRESS
|
||||
if (!progress)
|
||||
return;
|
||||
|
@ -901,14 +934,6 @@ progressmeter(int flag)
|
|||
if (! foregroundproc())
|
||||
return;
|
||||
|
||||
(void)gettimeofday(&now, NULL);
|
||||
cursize = bytes + restart_point;
|
||||
timersub(&now, &lastupdate, &wait);
|
||||
if (cursize > lastsize) {
|
||||
lastupdate = now;
|
||||
lastsize = cursize;
|
||||
wait.tv_sec = 0;
|
||||
}
|
||||
|
||||
len += snprintf(buf + len, BUFLEFT, "\r");
|
||||
if (filesize > 0) {
|
||||
|
@ -993,13 +1018,6 @@ progressmeter(int flag)
|
|||
len += snprintf(buf + len, BUFLEFT, "\n");
|
||||
(void)write(fileno(ttyout), buf, len);
|
||||
|
||||
if (flag == -1) {
|
||||
(void)xsignal_restart(SIGALRM, updateprogressmeter, 1);
|
||||
alarmtimer(1); /* set alarm timer for 1 Hz */
|
||||
} else if (flag == 1) {
|
||||
(void)xsignal(SIGALRM, SIG_DFL);
|
||||
alarmtimer(0);
|
||||
}
|
||||
#endif /* !NO_PROGRESS */
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue