[patch] dClose
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20130109132755.GA16181@darkstar> |
Merged a_Misc_close_fd, Dpi_close_fd and Http_socket_close into dClose and moved it into dlib. Replaced close calls with calls to dClose. _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
dClose.patch
(text/plain, 10.4 KB)
# HG changeset patch
# Parent 07920b2afdd5214c3c51e93f53b2c6bfd5a326dd
diff -r 07920b2afdd5 dlib/dlib.c
--- a/dlib/dlib.c
+++ b/dlib/dlib.c
@@ -931,3 +931,15 @@
return line;
}
+/*
+ * Close a FD handling EINTR.
+ */
+int dClose(int fd)
+{
+ int st;
+
+ do
+ st = close(fd);
+ while (st == -1 && errno == EINTR);
+ return st;
+}
diff -r 07920b2afdd5 dlib/dlib.h
--- a/dlib/dlib.h
+++ b/dlib/dlib.h
@@ -175,10 +175,10 @@
/*
*- Misc utility functions ----------------------------------------------------
*/
-char *dGetcwd ();
-char *dGethomedir ();
-char *dGetline (FILE *stream);
-
+char *dGetcwd();
+char *dGethomedir();
+char *dGetline(FILE *stream);
+int dClose(int fd);
#ifdef __cplusplus
}
diff -r 07920b2afdd5 dpi/downloads.cc
--- a/dpi/downloads.cc
+++ b/dpi/downloads.cc
@@ -441,7 +441,7 @@
void DLItem::abort_dl()
{
if (!log_done()) {
- close(LogPipe[0]);
+ dClose(LogPipe[0]);
Fl::remove_fd(LogPipe[0]);
log_done(1);
// Stop wget
@@ -459,9 +459,9 @@
void DLItem::child_init()
{
- close(0); // stdin
- close(1); // stdout
- close(LogPipe[0]);
+ dClose(0); // stdin
+ dClose(1); // stdout
+ dClose(LogPipe[0]);
dup2(LogPipe[1], 2); // stderr
// set the locale to C for log parsing
setenv("LC_ALL", "C", 1);
@@ -618,7 +618,7 @@
perror("read, ");
break;
} else if (st == 0) {
- close(fd_in);
+ dClose(fd_in);
Fl::remove_fd(fd_in, 1);
dl_item->log_done(1);
break;
@@ -630,7 +630,7 @@
void DLItem::father_init()
{
- close(LogPipe[1]);
+ dClose(LogPipe[1]);
Fl::add_fd(LogPipe[0], 1, read_log_cb, this); // Read
// Start the timer after the child is running.
diff -r 07920b2afdd5 dpi/https.c
--- a/dpi/https.c
+++ b/dpi/https.c
@@ -330,7 +330,7 @@
dFree(check_cert);
if (network_socket != -1){
- close(network_socket);
+ dClose(network_socket);
network_socket = -1;
}
if (ssl_connection != NULL){
@@ -402,7 +402,7 @@
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)&address, sizeof(address)) != 0){
- close(s);
+ dClose(s);
s = -1;
MSG("errno: %i\n", errno);
}
diff -r 07920b2afdd5 dpid/dpid.c
--- a/dpid/dpid.c
+++ b/dpid/dpid.c
@@ -762,7 +762,7 @@
} else if (CKD_WRITE(sock_fd, bye_cmd) == -1) {
ERRMSG("stop_active_dpis", "write", errno);
}
- a_Misc_close_fd(sock_fd);
+ dClose(sock_fd);
}
dFree(auth_cmd);
@@ -782,7 +782,7 @@
for (i = 0; i < numdpis; i++) {
FD_CLR(dpi_attr_list[i].sock_fd, &sock_set);
- a_Misc_close_fd(dpi_attr_list[i].sock_fd);
+ dClose(dpi_attr_list[i].sock_fd);
}
}
diff -r 07920b2afdd5 dpid/dpidc.c
--- a/dpid/dpidc.c
+++ b/dpid/dpidc.c
@@ -9,6 +9,7 @@
#include <netdb.h>
#include <errno.h>
+#include "../dlib/dlib.h"
#include "../dpip/dpip.h"
#define MSG_ERR(...) printf("** ERROR **: " __VA_ARGS__);
@@ -116,6 +117,6 @@
error("ERROR reading from socket");
printf("%s\n",buffer);
*/
- close(sockfd);
+ dClose(sockfd);
return 0;
}
diff -r 07920b2afdd5 dpid/main.c
--- a/dpid/main.c
+++ b/dpid/main.c
@@ -26,6 +26,8 @@
#include "dpi.h"
#include "dpi_socket_dir.h"
#include "misc_new.h"
+
+#include "../dlib/dlib.h"
#include "../dpip/dpip.h"
sigset_t mask_sigchld;
@@ -76,13 +78,13 @@
}
/* Parent, Close sockets fix stdio and return pid */
- if (a_Misc_close_fd(newsock) == -1) {
+ if (dClose(newsock) == -1) {
ERRMSG("start_plugin", "close", errno);
MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path);
exit(1);
}
- a_Misc_close_fd(STDIN_FILENO);
- a_Misc_close_fd(STDOUT_FILENO);
+ dClose(STDIN_FILENO);
+ dClose(STDOUT_FILENO);
dup2(old_stdin, STDIN_FILENO);
dup2(old_stdout, STDOUT_FILENO);
return pid;
@@ -95,7 +97,7 @@
MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path);
exit(1);
}
- if (a_Misc_close_fd(dpi_attr.sock_fd) == -1) {
+ if (dClose(dpi_attr.sock_fd) == -1) {
ERRMSG("start_plugin", "close", errno);
MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path);
exit(1);
@@ -224,7 +226,7 @@
/* close inherited file descriptors */
open_max = get_open_max();
for (i = 3; i < open_max; i++)
- a_Misc_close_fd(i);
+ dClose(i);
/* this sleep used to unmask a race condition */
// sleep(2);
diff -r 07920b2afdd5 dpid/misc_new.c
--- a/dpid/misc_new.c
+++ b/dpid/misc_new.c
@@ -19,20 +19,6 @@
#include "dpid_common.h"
#include "misc_new.h" /* for function prototypes */
-
-/*
- * Close a FD handling EINTR.
- */
-int a_Misc_close_fd(int fd)
-{
- int st;
-
- do {
- st = close(fd);
- } while (st < 0 && errno == EINTR);
- return st;
-}
-
/*! Reads a dpi tag from a socket
* \li Continues after a signal interrupt
* \Return
diff -r 07920b2afdd5 dpid/misc_new.h
--- a/dpid/misc_new.h
+++ b/dpid/misc_new.h
@@ -1,8 +1,6 @@
#ifndef MISC_NEW_H
#define MISC_NEW_H
-
-int a_Misc_close_fd(int fd);
Dstr *a_Misc_rdtag(int socket);
char *a_Misc_readtag(int sock);
char *a_Misc_mkdtemp(char *template);
diff -r 07920b2afdd5 dpip/dpip.c
--- a/dpip/dpip.c
+++ b/dpip/dpip.c
@@ -489,11 +489,11 @@
a_Dpip_dsh_write(dsh, 1, "", 0);
/* close fds */
- while((st = close(dsh->fd_in)) < 0 && errno == EINTR) ;
+ st = dClose(dsh->fd_in);
if (st < 0)
MSG_ERR("[a_Dpip_dsh_close] close: %s\n", dStrerror(errno));
if (dsh->fd_out != dsh->fd_in) {
- while((st = close(dsh->fd_out)) < 0 && errno == EINTR) ;
+ st = dClose(dsh->fd_out);
if (st < 0)
MSG_ERR("[a_Dpip_dsh_close] close: %s\n", dStrerror(errno));
}
diff -r 07920b2afdd5 src/IO/IO.c
--- a/src/IO/IO.c
+++ b/src/IO/IO.c
@@ -125,7 +125,6 @@
*/
static void IO_close_fd(IOData_t *io, int CloseCode)
{
- int st;
int events = 0;
_MSG("====> begin IO_close_fd (%d) Key=%d CloseCode=%d Flags=%d ",
@@ -135,9 +134,7 @@
* closed! (other clients may set 'IOFlag_ForceClose') */
if (((io->Flags & IOFlag_ForceClose) || (CloseCode == IO_StopRdWr)) &&
io->FD != -1) {
- do
- st = close(io->FD);
- while (st < 0 && errno == EINTR);
+ dClose(io->FD);
} else {
_MSG(" NOT CLOSING ");
}
diff -r 07920b2afdd5 src/IO/dpi.c
--- a/src/IO/dpi.c
+++ b/src/IO/dpi.c
@@ -86,19 +86,6 @@
}
/*
- * Close a FD handling EINTR
- */
-static void Dpi_close_fd(int fd)
-{
- int st;
-
- dReturn_if (fd < 0);
- do
- st = close(fd);
- while (st < 0 && errno == EINTR);
-}
-
-/*
* Create a new connection data structure
*/
static dpi_conn_t *Dpi_conn_new(ChainLink *Info)
@@ -362,7 +349,7 @@
if (pid == 0) {
/* This is the child process. Execute the command. */
char *path1 = dStrconcat(dGethomedir(), "/.dillo/dpid", NULL);
- Dpi_close_fd(st_pipe[0]);
+ dClose(st_pipe[0]);
if (execl(path1, "dpid", (char*)NULL) == -1) {
dFree(path1);
path1 = dStrconcat(DILLO_BINDIR, "dpid", NULL);
@@ -373,7 +360,7 @@
if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) {
MSG("Dpi_start_dpid (child): can't write to pipe.\n");
}
- Dpi_close_fd(st_pipe[1]);
+ dClose(st_pipe[1]);
_exit (EXIT_FAILURE);
}
}
@@ -382,19 +369,18 @@
/* The fork failed. Report failure. */
MSG("Dpi_start_dpid: %s\n", dStrerror(errno));
/* close the unused pipe */
- Dpi_close_fd(st_pipe[0]);
- Dpi_close_fd(st_pipe[1]);
-
+ dClose(st_pipe[0]);
+ dClose(st_pipe[1]);
} else {
/* This is the parent process, check our child status... */
- Dpi_close_fd(st_pipe[1]);
+ dClose(st_pipe[1]);
if ((answer = Dpi_blocking_read(st_pipe[0])) != NULL) {
MSG("Dpi_start_dpid: can't start dpid\n");
dFree(answer);
} else {
ret = 0;
}
- Dpi_close_fd(st_pipe[0]);
+ dClose(st_pipe[0]);
}
return ret;
@@ -467,7 +453,7 @@
} else if (connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) {
MSG("Dpi_check_dpid_ids: %s\n", dStrerror(errno));
} else {
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
ret = 1;
}
}
@@ -603,7 +589,7 @@
dFree(cmd);
}
dFree(rply);
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ok ? dpi_port : -1;
}
@@ -648,7 +634,7 @@
}
dFree(cmd);
if (sock_fd != -1 && ret == -1) /* can't send cmd? */
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ret;
}
@@ -797,7 +783,7 @@
} if ((ret = Dpi_blocking_read(sock_fd)) == NULL) {
MSG_ERR("[a_Dpi_send_blocking_cmd] Can't read message.\n");
}
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ret;
}
diff -r 07920b2afdd5 src/IO/http.c
--- a/src/IO/http.c
+++ b/src/IO/http.c
@@ -210,17 +210,6 @@
}
/*
- * Close the socket's FD
- */
-static void Http_socket_close(SocketData_t *S)
-{
- int st;
- do
- st = close(S->SockFD);
- while (st < 0 && errno == EINTR);
-}
-
-/*
* Make the HTTP header's Referer line according to preferences
* (default is "host" i.e. "scheme://hostname/" )
*/
@@ -448,7 +437,7 @@
status = connect(S->SockFD, (struct sockaddr *)&name, socket_len);
if (status == -1 && errno != EINPROGRESS) {
S->Err = errno;
- Http_socket_close(S);
+ dClose(S->SockFD);
MSG("Http_connect_socket ERROR: %s\n", dStrerror(S->Err));
} else {
a_Chain_bcb(OpSend, Info, &S->SockFD, "FD");
diff -r 07920b2afdd5 src/cookies.c
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -90,7 +90,7 @@
filename, dStrerror(errno));
}
}
- close(fd);
+ dClose(fd);
MSG("Cookies: Created file: %s\n", filename);
F_in = fopen(filename, "r");
diff -r 07920b2afdd5 src/dns.c
--- a/src/dns.c
+++ b/src/dns.c
@@ -217,9 +217,7 @@
/* If the IPv6 address family is not available there is no point
wasting time trying to connect to v6 addresses. */
int fd = socket(AF_INET6, SOCK_STREAM, 0);
- if (fd >= 0) {
- close(fd);
- }
+ dClose(fd);
}
#endif
}
@@ -510,8 +508,8 @@
dList_free(dns_cache[i].addr_list);
}
a_IOwatch_remove_fd(dns_notify_pipe[0], DIO_READ);
- close(dns_notify_pipe[0]);
- close(dns_notify_pipe[1]);
+ dClose(dns_notify_pipe[0]);
+ dClose(dns_notify_pipe[1]);
dFree(dns_cache);
}