If an ftp auto-fetch transfer is interrupted by SIGINT (usually ^C),
exit with 130 instead of 1 (or rarely, 0). This allows an ftp auto-fetch in a shell loop to correctly terminate the loop. Should fix PR [pkg/26351], and possibly others.
This commit is contained in:
parent
facc7352d1
commit
1aa9c35970
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: cmds.c,v 1.105 2004/06/06 13:53:28 kleink Exp $ */
|
||||
/* $NetBSD: cmds.c,v 1.106 2004/07/20 10:40:21 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -103,7 +103,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: cmds.c,v 1.105 2004/06/06 13:53:28 kleink Exp $");
|
||||
__RCSID("$NetBSD: cmds.c,v 1.106 2004/07/20 10:40:21 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -1400,7 +1400,7 @@ void
|
|||
shell(int argc, char *argv[])
|
||||
{
|
||||
pid_t pid;
|
||||
sigfunc old1;
|
||||
sigfunc oldintr;
|
||||
char shellnam[MAXPATHLEN], *shell, *namep;
|
||||
int wait_status;
|
||||
|
||||
|
@ -1409,7 +1409,7 @@ shell(int argc, char *argv[])
|
|||
code = -1;
|
||||
return;
|
||||
}
|
||||
old1 = xsignal(SIGINT, SIG_IGN);
|
||||
oldintr = xsignal(SIGINT, SIG_IGN);
|
||||
if ((pid = fork()) == 0) {
|
||||
for (pid = 3; pid < 20; pid++)
|
||||
(void)close(pid);
|
||||
|
@ -1440,7 +1440,7 @@ shell(int argc, char *argv[])
|
|||
if (pid > 0)
|
||||
while (wait(&wait_status) != pid)
|
||||
;
|
||||
(void)xsignal(SIGINT, old1);
|
||||
(void)xsignal(SIGINT, oldintr);
|
||||
if (pid == -1) {
|
||||
warn("Try again later");
|
||||
code = -1;
|
||||
|
@ -1790,6 +1790,7 @@ void
|
|||
proxabort(int notused)
|
||||
{
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
if (!proxy) {
|
||||
pswitch(1);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: fetch.c,v 1.147 2004/06/06 01:37:41 christos Exp $ */
|
||||
/* $NetBSD: fetch.c,v 1.148 2004/07/20 10:40:21 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fetch.c,v 1.147 2004/06/06 01:37:41 christos Exp $");
|
||||
__RCSID("$NetBSD: fetch.c,v 1.148 2004/07/20 10:40:21 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -1278,6 +1278,7 @@ aborthttp(int notused)
|
|||
char msgbuf[100];
|
||||
int len;
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
len = strlcpy(msgbuf, "\nHTTP fetch aborted.\n", sizeof(msgbuf));
|
||||
write(fileno(ttyout), msgbuf, len);
|
||||
|
@ -1686,6 +1687,7 @@ go_fetch(const char *url)
|
|||
* If an ftp path has a trailing "/", the path will be cd-ed into and
|
||||
* the connection remains open, and the function will return -1
|
||||
* (to indicate the connection is alive).
|
||||
* If the transfer was interrupted with SIGINT, the return value is EXIT_SIGINT.
|
||||
* If an error occurs the return value will be the offset+1 in
|
||||
* argv[] of the file that caused a problem (i.e, argv[x]
|
||||
* returns x+1)
|
||||
|
@ -1699,10 +1701,15 @@ auto_fetch(int argc, char *argv[])
|
|||
|
||||
argpos = 0;
|
||||
|
||||
sigint_raised = 0;
|
||||
if (sigsetjmp(toplevel, 1)) {
|
||||
if (connected)
|
||||
disconnect(0, NULL);
|
||||
return (argpos + 1);
|
||||
if (rval > 0)
|
||||
rval = argpos + 1;
|
||||
if (sigint_raised)
|
||||
rval = EXIT_SIGINT;
|
||||
return (rval);
|
||||
}
|
||||
(void)xsignal(SIGINT, intr);
|
||||
(void)xsignal(SIGPIPE, lostpeer);
|
||||
|
@ -1722,6 +1729,8 @@ auto_fetch(int argc, char *argv[])
|
|||
outfile = NULL;
|
||||
if (rval > 0)
|
||||
rval = argpos + 1;
|
||||
if (sigint_raised)
|
||||
rval = EXIT_SIGINT;
|
||||
}
|
||||
|
||||
if (connected && rval != -1)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: ftp.c,v 1.125 2004/04/10 12:21:39 lukem Exp $ */
|
||||
/* $NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -99,7 +99,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: ftp.c,v 1.125 2004/04/10 12:21:39 lukem Exp $");
|
||||
__RCSID("$NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -131,8 +131,9 @@ __RCSID("$NetBSD: ftp.c,v 1.125 2004/04/10 12:21:39 lukem Exp $");
|
|||
|
||||
#include "ftp_var.h"
|
||||
|
||||
volatile int abrtflag = 0;
|
||||
volatile int timeoutflag = 0;
|
||||
volatile sig_atomic_t abrtflag;
|
||||
volatile sig_atomic_t timeoutflag;
|
||||
|
||||
sigjmp_buf ptabort;
|
||||
int ptabflg;
|
||||
int ptflag = 0;
|
||||
|
@ -318,6 +319,7 @@ cmdabort(int notused)
|
|||
{
|
||||
int oerrno = errno;
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
if (fromatty)
|
||||
write(fileno(ttyout), "\n", 1);
|
||||
|
@ -601,6 +603,7 @@ abortxfer(int notused)
|
|||
char msgbuf[100];
|
||||
int len;
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
mflag = 0;
|
||||
abrtflag = 0;
|
||||
|
@ -1742,6 +1745,7 @@ psabort(int notused)
|
|||
{
|
||||
int oerrno = errno;
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
abrtflag++;
|
||||
errno = oerrno;
|
||||
|
@ -1838,6 +1842,7 @@ void
|
|||
abortpt(int notused)
|
||||
{
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
if (fromatty)
|
||||
write(fileno(ttyout), "\n", 1);
|
||||
|
@ -2056,6 +2061,7 @@ abort_squared(int dummy)
|
|||
char msgbuf[100];
|
||||
int len;
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
len = strlcpy(msgbuf, "\nremote abort aborted; closing connection.\n",
|
||||
sizeof(msgbuf));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: ftp_var.h,v 1.66 2004/06/06 01:37:41 christos Exp $ */
|
||||
/* $NetBSD: ftp_var.h,v 1.67 2004/07/20 10:40:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -191,6 +191,8 @@ enum {
|
|||
#define DEFAULTPROMPT "ftp> " /* default prompt if `set prompt' is empty */
|
||||
#define DEFAULTRPROMPT "" /* default rprompt if `set rprompt' is empty */
|
||||
|
||||
#define EXIT_SIGINT 130 /* exit status if ^C (SIGINT) received */
|
||||
|
||||
#define TMPFILE "ftpXXXXXXXXXX"
|
||||
|
||||
|
||||
|
@ -310,6 +312,7 @@ GLOBAL void (*reply_callback)(const char *);
|
|||
* first (`xxx-') and last (`xxx ')
|
||||
*/
|
||||
|
||||
GLOBAL volatile sig_atomic_t sigint_raised;
|
||||
|
||||
GLOBAL FILE *cin;
|
||||
GLOBAL FILE *cout;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: main.c,v 1.88 2004/07/09 12:12:27 wiz Exp $ */
|
||||
/* $NetBSD: main.c,v 1.89 2004/07/20 10:40:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -104,7 +104,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.88 2004/07/09 12:12:27 wiz Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.89 2004/07/20 10:40:22 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -515,8 +515,13 @@ main(int argc, char *argv[])
|
|||
} else {
|
||||
char *xargv[4], *user, *host;
|
||||
|
||||
if (sigsetjmp(toplevel, 1))
|
||||
exit(0);
|
||||
sigint_raised = 0;
|
||||
if (sigsetjmp(toplevel, 1)) {
|
||||
if (sigint_raised)
|
||||
exit(EXIT_SIGINT);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
(void)xsignal(SIGINT, intr);
|
||||
(void)xsignal(SIGPIPE, lostpeer);
|
||||
user = NULL;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: util.c,v 1.115 2004/04/10 12:21:39 lukem Exp $ */
|
||||
/* $NetBSD: util.c,v 1.116 2004/07/20 10:40:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -71,7 +71,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: util.c,v 1.115 2004/04/10 12:21:39 lukem Exp $");
|
||||
__RCSID("$NetBSD: util.c,v 1.116 2004/07/20 10:40:22 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -318,9 +318,10 @@ cleanuppeer(void)
|
|||
* Top-level signal handler for interrupted commands.
|
||||
*/
|
||||
void
|
||||
intr(int dummy)
|
||||
intr(int signo)
|
||||
{
|
||||
|
||||
sigint_raised = 1;
|
||||
alarmtimer(0);
|
||||
if (fromatty)
|
||||
write(fileno(ttyout), "\n", 1);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* $NetBSD: version.h,v 1.36 2004/07/15 08:50:10 lukem Exp $ */
|
||||
/* $NetBSD: version.h,v 1.37 2004/07/20 10:40:24 lukem Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1999-2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999-2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -40,5 +40,5 @@
|
|||
#endif
|
||||
|
||||
#ifndef FTP_VERSION
|
||||
#define FTP_VERSION "20040715"
|
||||
#define FTP_VERSION "20040720"
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue