1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Move close_all_non_term_fd() shared by SMB and FSP to protocol/common

Stick a note near the OBJS sorting that it is there also to filter out
duplicates, which are now occuring with SMB and FSP compiled in.
This commit is contained in:
Jonas Fonseca 2006-01-16 23:32:27 +01:00 committed by Jonas Fonseca
parent cbd22ecaca
commit af67388201
5 changed files with 50 additions and 47 deletions

View File

@ -13,6 +13,8 @@ SUBDIRS-$(CONFIG_URI_REWRITE) += rewrite
SUBDIRS = auth file http SUBDIRS = auth file http
OBJS-$(CONFIG_DATA) += data.o OBJS-$(CONFIG_DATA) += data.o
OBJS-$(CONFIG_FSP) += common.o
OBJS-$(CONFIG_SMB) += common.o
OBJS = about.o date.o header.o protocol.o proxy.o uri.o user.o OBJS = about.o date.o header.o protocol.o proxy.o uri.o user.o

37
src/protocol/common.c Normal file
View File

@ -0,0 +1,37 @@
/* Shared protocol functions */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* FreeBSD needs this before resource.h */
#endif
#include <sys/types.h> /* FreeBSD needs this before resource.h */
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "elinks.h"
#include "protocol/common.h"
/* Close all non-terminal file descriptors. */
void
close_all_non_term_fd(void)
{
int n;
int max = 1024;
#ifdef RLIMIT_NOFILE
struct rlimit lim;
if (!getrlimit(RLIMIT_NOFILE, &lim))
max = lim.rlim_max;
#endif
for (n = 3; n < max; n++)
close(n);
}

7
src/protocol/common.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef EL__PROTOCOL_COMMON_H
#define EL__PROTOCOL_COMMON_H
/* Close all non-terminal file descriptors. */
void close_all_non_term_fd(void);
#endif

View File

@ -13,13 +13,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* FreeBSD needs this before resource.h */
#endif
#include <sys/types.h> /* FreeBSD needs this before resource.h */
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
#include <fcntl.h> /* OS/2 needs this after sys/types.h */ #include <fcntl.h> /* OS/2 needs this after sys/types.h */
#endif #endif
@ -37,6 +30,7 @@
#include "network/connection.h" #include "network/connection.h"
#include "network/socket.h" #include "network/socket.h"
#include "osdep/osdep.h" #include "osdep/osdep.h"
#include "protocol/common.h"
#include "protocol/protocol.h" #include "protocol/protocol.h"
#include "protocol/fsp/fsp.h" #include "protocol/fsp/fsp.h"
#include "protocol/uri.h" #include "protocol/uri.h"
@ -265,22 +259,6 @@ fsp_got_data(struct socket *socket, struct read_buffer *rb)
#undef READ_SIZE #undef READ_SIZE
/* Close all non-terminal file descriptors. */
static void
close_all_non_term_fd(void)
{
int n;
int max = 1024;
#ifdef RLIMIT_NOFILE
struct rlimit lim;
if (!getrlimit(RLIMIT_NOFILE, &lim))
max = lim.rlim_max;
#endif
for (n = 3; n < max; n++)
close(n);
}
void void
fsp_protocol_handler(struct connection *conn) fsp_protocol_handler(struct connection *conn)
{ {
@ -326,7 +304,7 @@ fsp_protocol_handler(struct connection *conn)
close_all_non_term_fd(); close_all_non_term_fd();
do_fsp(conn); do_fsp(conn);
} else { } else {
conn->socket->fd = fsp_pipe[0]; conn->socket->fd = fsp_pipe[0];
close(fsp_pipe[1]); close(fsp_pipe[1]);

View File

@ -12,13 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_SYS_TIME_H #include <sys/types.h>
#include <sys/time.h> /* FreeBSD needs this before resource.h */
#endif
#include <sys/types.h> /* FreeBSD needs this before resource.h */
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
#include <fcntl.h> /* OS/2 needs this after sys/types.h */ #include <fcntl.h> /* OS/2 needs this after sys/types.h */
#endif #endif
@ -36,6 +30,7 @@
#include "network/connection.h" #include "network/connection.h"
#include "network/socket.h" #include "network/socket.h"
#include "osdep/osdep.h" #include "osdep/osdep.h"
#include "protocol/common.h"
#include "protocol/protocol.h" #include "protocol/protocol.h"
#include "protocol/smb/smb.h" #include "protocol/smb/smb.h"
#include "protocol/uri.h" #include "protocol/uri.h"
@ -525,22 +520,6 @@ bye:
} }
/* Close all non-terminal file descriptors. */
static void
close_all_non_term_fd(void)
{
int n;
int max = 1024;
#ifdef RLIMIT_NOFILE
struct rlimit lim;
if (!getrlimit(RLIMIT_NOFILE, &lim))
max = lim.rlim_max;
#endif
for (n = 3; n < max; n++)
close(n);
}
void void
smb_protocol_handler(struct connection *conn) smb_protocol_handler(struct connection *conn)
{ {