Handle SIGPIPE in a couple of crucial places.
This commit is contained in:
parent
8e3eb39d32
commit
0d5105c09c
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: ftp.c,v 1.16 1996/04/28 20:53:56 jkh Exp $
|
||||
* $Id: ftp.c,v 1.17 1996/07/08 10:08:00 jkh Exp $
|
||||
*
|
||||
* Return values have been sanitized:
|
||||
* -1 error, but you (still) have a session.
|
||||
@ -20,10 +20,9 @@
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include "ftp.h"
|
||||
@ -41,6 +40,14 @@ int FtpPort;
|
||||
#include "sysinstall.h"
|
||||
#endif /*STANDALONE_FTP*/
|
||||
|
||||
static int sigpipe_caught = 0;
|
||||
|
||||
static void
|
||||
catch_pipe(int sig)
|
||||
{
|
||||
sigpipe_caught = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
debug(FTP_t ftp, const char *fmt, ...)
|
||||
{
|
||||
@ -64,8 +71,14 @@ static int
|
||||
writes(int fd, char *s)
|
||||
{
|
||||
int i = strlen(s);
|
||||
if (i != write(fd, s, i))
|
||||
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
if (i != write(fd, s, i) || sigpipe_caught) {
|
||||
if (sigpipe_caught)
|
||||
msgDebug("sigpipe caught during write - connection invalid\n");
|
||||
sigpipe_caught = FALSE;
|
||||
return IO_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -75,10 +88,15 @@ get_a_line(FTP_t ftp)
|
||||
static char buf[BUFSIZ];
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<BUFSIZ;) {
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
for(i = 0; i < BUFSIZ;) {
|
||||
j = read(ftp->fd_ctrl, buf+i, 1);
|
||||
if (j != 1)
|
||||
if (j != 1 || sigpipe_caught) {
|
||||
if (sigpipe_caught)
|
||||
msgDebug("sigpipe caught during read - connection invalid\n");
|
||||
sigpipe_caught = FALSE;
|
||||
return 0;
|
||||
}
|
||||
if (buf[i] == '\r' || buf[i] == '\n') {
|
||||
if (!i)
|
||||
continue;
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: package.c,v 1.42 1996/07/09 14:28:20 jkh Exp $
|
||||
* $Id: package.c,v 1.43 1996/07/10 11:38:28 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@ -119,8 +119,8 @@ package_extract(Device *dev, char *name, Boolean depended)
|
||||
int i, tot, pfd[2];
|
||||
pid_t pid;
|
||||
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
pipe(pfd);
|
||||
pid = fork();
|
||||
if (!pid) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: ftp.c,v 1.16 1996/04/28 20:53:56 jkh Exp $
|
||||
* $Id: ftp.c,v 1.17 1996/07/08 10:08:00 jkh Exp $
|
||||
*
|
||||
* Return values have been sanitized:
|
||||
* -1 error, but you (still) have a session.
|
||||
@ -20,10 +20,9 @@
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include "ftp.h"
|
||||
@ -41,6 +40,14 @@ int FtpPort;
|
||||
#include "sysinstall.h"
|
||||
#endif /*STANDALONE_FTP*/
|
||||
|
||||
static int sigpipe_caught = 0;
|
||||
|
||||
static void
|
||||
catch_pipe(int sig)
|
||||
{
|
||||
sigpipe_caught = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
debug(FTP_t ftp, const char *fmt, ...)
|
||||
{
|
||||
@ -64,8 +71,14 @@ static int
|
||||
writes(int fd, char *s)
|
||||
{
|
||||
int i = strlen(s);
|
||||
if (i != write(fd, s, i))
|
||||
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
if (i != write(fd, s, i) || sigpipe_caught) {
|
||||
if (sigpipe_caught)
|
||||
msgDebug("sigpipe caught during write - connection invalid\n");
|
||||
sigpipe_caught = FALSE;
|
||||
return IO_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -75,10 +88,15 @@ get_a_line(FTP_t ftp)
|
||||
static char buf[BUFSIZ];
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<BUFSIZ;) {
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
for(i = 0; i < BUFSIZ;) {
|
||||
j = read(ftp->fd_ctrl, buf+i, 1);
|
||||
if (j != 1)
|
||||
if (j != 1 || sigpipe_caught) {
|
||||
if (sigpipe_caught)
|
||||
msgDebug("sigpipe caught during read - connection invalid\n");
|
||||
sigpipe_caught = FALSE;
|
||||
return 0;
|
||||
}
|
||||
if (buf[i] == '\r' || buf[i] == '\n') {
|
||||
if (!i)
|
||||
continue;
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: package.c,v 1.42 1996/07/09 14:28:20 jkh Exp $
|
||||
* $Id: package.c,v 1.43 1996/07/10 11:38:28 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@ -119,8 +119,8 @@ package_extract(Device *dev, char *name, Boolean depended)
|
||||
int i, tot, pfd[2];
|
||||
pid_t pid;
|
||||
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
|
||||
signal(SIGPIPE, catch_pipe);
|
||||
pipe(pfd);
|
||||
pid = fork();
|
||||
if (!pid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user