diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-09 12:47:23 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-09 12:47:23 -0300 |
commit | cbba835b154ba31e7a07ba1b15a06b8953eb7e72 (patch) | |
tree | 8ea8ad0b67ba6a2f8a789f9e61ea4f80d0c20d35 /dpid | |
parent | d236210c1608952b7910123fbede108317a80444 (diff) |
Refactored FD close calls into a single new dClose() dlib function [p37sitdu]
Diffstat (limited to 'dpid')
-rw-r--r-- | dpid/dpid.c | 4 | ||||
-rw-r--r-- | dpid/dpidc.c | 3 | ||||
-rw-r--r-- | dpid/main.c | 12 | ||||
-rw-r--r-- | dpid/misc_new.c | 14 | ||||
-rw-r--r-- | dpid/misc_new.h | 2 |
5 files changed, 11 insertions, 24 deletions
diff --git a/dpid/dpid.c b/dpid/dpid.c index 28cfabba..ebabb9a2 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -762,7 +762,7 @@ void stop_active_dpis(struct dp *dpi_attr_list, int numdpis) } 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 @@ void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis) 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 --git a/dpid/dpidc.c b/dpid/dpidc.c index 61a91275..58db9c3c 100644 --- 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 @@ int main(int argc, char *argv[]) error("ERROR reading from socket"); printf("%s\n",buffer); */ - close(sockfd); + dClose(sockfd); return 0; } diff --git a/dpid/main.c b/dpid/main.c index 5f512245..6350a2b6 100644 --- 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 @@ static int start_filter_plugin(struct dp dpi_attr) } /* 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 @@ static void start_server_plugin(struct dp dpi_attr) 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 @@ int main(void) /* 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 --git a/dpid/misc_new.c b/dpid/misc_new.c index 8c07a4eb..50867bc3 100644 --- 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 --git a/dpid/misc_new.h b/dpid/misc_new.h index 325451a1..b015a77a 100644 --- 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); |