dpid patches
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20121218152637.GA2899@darkstar> |
First patch is for removing expired TODO item, just resending it. Second patch is new, for dpid.c. Function fill_services_list has a bug: on line 463 there is a check *services_list != NULL. If it is true, then -1 is returned, but dpidrc_stream is not closed. Error message on line 456 says "popen failed", should be "fopen failed". fill_services_list checks for availability of user_dpidir and sys_dpidir, but after line 449 these variables are not used. They are just dFreed in the end. Looks like code was just copypasted from register_all. fill_services_list is only called from main.c:248 and dpid.c:807 of dpid.c. register_all is called from main.c:235 and dpid.c:806. So fill_services_list is always called after register_all and doing the same check is useless. On line 503 there is a conversion of services_alpha_comp to type (dCompareFunc). I changed the function services_alpha_comp to the usual style of writing comparison functions so no conversion is required. In the current state it is undefined behaviour. [1] [1] http://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
dpid-expired-todo.patch
(text/plain, 559 B)
# HG changeset patch # Parent 996baa7e8bf9c4ecc129d56586c2e0d5a02d0e23 diff -r 996baa7e8bf9 dpid/TODO --- a/dpid/TODO +++ b/dpid/TODO @@ -1,13 +1,5 @@ Todo List - File dpi_service.c - This module should be removed because its original functions - have been removed or modified. Put these functions in dpid.c - - File dpi_service.h - This module should be removed because its original functions - have been removed or modified. Put these functions in dpid.c - Add other file types, but first we need to add files associated with a dpi to the design.
fill_services_list.patch
(text/plain, 6.5 KB)
# HG changeset patch
# Parent 0ba10aebbb59c96926dec76869907f3914d82229
diff -r 0ba10aebbb59 dpid/dpid.c
--- a/dpid/dpid.c
+++ b/dpid/dpid.c
@@ -18,28 +18,27 @@
/*! \file
* Main functions to set-up dpi information and to initialise sockets
*/
-#include <errno.h>
-#include <stdlib.h> /* for exit */
-#include <fcntl.h> /* for F_SETFD, F_GETFD, FD_CLOEXEC */
-
+#include <netinet/tcp.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
+#include <errno.h>
+#include <fcntl.h> /* for F_SETFD, F_GETFD, FD_CLOEXEC */
+#include <stdlib.h> /* for exit */
#include <unistd.h>
-#include "dpid_common.h"
-#include "dpid.h"
+
+#include "../dpip/dpip.h"
#include "dpi.h"
#include "dpi_socket_dir.h"
+#include "dpid.h"
+#include "dpid_common.h"
#include "misc_new.h"
-#include "../dpip/dpip.h"
-
#define QUEUE 5
volatile sig_atomic_t caught_sigchld = 0;
-char *SharedKey = NULL;
+static char *SharedKey = NULL;
/*! Remove dpid_comm_keys file.
* This avoids that dillo instances connect to a stale port after dpid
@@ -48,6 +47,7 @@
void cleanup()
{
char *fname;
+
fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
unlink(fname);
dFree(fname);
@@ -58,14 +58,11 @@
*/
void free_dpi_attr(struct dp *dpi_attr)
{
- if (dpi_attr->id != NULL) {
- dFree(dpi_attr->id);
- dpi_attr->id = NULL;
- }
- if (dpi_attr->path != NULL) {
- dFree(dpi_attr->path);
- dpi_attr->path = NULL;
- }
+ dFree(dpi_attr->id);
+ dpi_attr->id = NULL;
+
+ dFree(dpi_attr->path);
+ dpi_attr->path = NULL;
}
/*! Free memory used by the plugin list
@@ -89,10 +86,10 @@
*/
void free_services_list(Dlist *s_list)
{
- int i = 0;
+ int i;
struct service *s;
- for (i=0; i < dList_length(s_list) ; i++) {
+ for (i = 0; i < dList_length(s_list); i++) {
s = dList_nth_data(s_list, i);
dFree(s->name);
}
@@ -203,7 +200,7 @@
}
dFree(rcline);
- return (value);
+ return value;
}
/*! Scans a service directory in dpi_dir and fills dpi_attr
@@ -350,6 +347,7 @@
dFree(user_dpidir);
user_dpidir = NULL;
}
+
dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
if (access(dpidrc, F_OK) == -1) {
dFree(dpidrc);
@@ -359,8 +357,8 @@
dpidrc = NULL;
}
}
- if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
- sys_dpidir = NULL;
+
+ sys_dpidir = dpidrc ? get_dpi_dir(dpidrc) : NULL;
dFree(dpidrc);
if (!user_dpidir && !sys_dpidir) {
@@ -400,16 +398,18 @@
/* TODO: do we consider snum == 0 an error?
* (if so, we should return -1 ) */
- return (snum);
+ return snum;
}
/*
* Compare two struct service pointers
* This function is used for sorting services
*/
-static int services_alpha_comp(const struct service *s1,
- const struct service *s2)
+static int services_alpha_comp(const void *v1, const void *v2)
{
+ const struct service *s1 = v1;
+ const struct service *s2 = v2;
+
return -strcmp(s1->name, s2->name);
}
@@ -422,18 +422,13 @@
*/
int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
{
+ char *dpidrc, *p, *line, *service, *path;
FILE *dpidrc_stream;
- char *p, *line = NULL, *service, *path;
- int i, st;
+ int i, st, ret;
struct service *s;
- char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL;
- user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
- if (access(user_dpidir, F_OK) == -1) {
- /* no dpis in user's space */
- dFree(user_dpidir);
- user_dpidir = NULL;
- }
+ ret = -1;
+
dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
if (access(dpidrc, F_OK) == -1) {
dFree(dpidrc);
@@ -443,26 +438,16 @@
dpidrc = NULL;
}
}
- if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
- sys_dpidir = NULL;
- if (!user_dpidir && !sys_dpidir) {
- ERRMSG("fill_services_list", "Fatal error ", 0);
- MSG_ERR("\n - Can't find the directory for dpis.\n");
- exit(1);
- }
-
- if ((dpidrc_stream = fopen(dpidrc, "r")) == NULL) {
- ERRMSG("fill_services_list", "popen failed", errno);
- dFree(dpidrc);
- dFree(sys_dpidir);
- dFree(user_dpidir);
- return (-1);
+ dpidrc_stream = fopen(dpidrc, "r");
+ if (dpidrc_stream == NULL) {
+ ERRMSG("fill_services_list", "fopen failed", errno);
+ goto end;
}
if (*services_list != NULL) {
ERRMSG("fill_services_list", "services_list parameter is not NULL", 0);
- return -1;
+ goto end;
}
*services_list = dList_new(8);
@@ -473,9 +458,8 @@
MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n",
dpidrc, service, path);
continue;
- } else if (st != 0) {
+ } else if (st != 0)
continue;
- }
_MSG("dpid: service=%s, path=%s\n", service, path);
@@ -498,15 +482,16 @@
if (i < numdpis)
s->dp_index = i;
}
- fclose(dpidrc_stream);
- dList_sort(*services_list, (dCompareFunc)services_alpha_comp);
+ dList_sort(*services_list, services_alpha_comp);
+ ret = dList_length(*services_list);
+end:
+ if (dpidrc_stream != NULL)
+ fclose(dpidrc_stream);
dFree(dpidrc);
- dFree(sys_dpidir);
- dFree(user_dpidir);
- return (dList_length(*services_list));
+ return ret;
}
/*
@@ -542,13 +527,13 @@
struct sockaddr_in sin;
int ok = 0, last_port = base_port + 50;
- if ((sock_fd = make_socket_fd()) == -1) {
- return (-1); /* avoids nested ifs */
- }
+ sock_fd = make_socket_fd();
+ if (sock_fd == -1)
+ return -1;
+
/* Set the socket FD to close on exec */
fcntl(sock_fd, F_SETFD, FD_CLOEXEC | fcntl(sock_fd, F_GETFD));
-
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -806,7 +791,7 @@
numdpis = register_all(&dpi_attr_list);
fill_services_list(dpi_attr_list, numdpis, &services_list);
numsocks = init_all_dpi_sockets(dpi_attr_list);
- return (numdpis);
+ return numdpis;
}
/*!
@@ -826,7 +811,7 @@
(void) CKD_WRITE(sock_fd, d_cmd);
dFree(d_cmd);
}
- return (msg);
+ return msg;
}
/*
@@ -844,7 +829,7 @@
if (A->name[A_len - 1] == '*')
len = A_len - 1;
- return(dStrnAsciiCasecmp(A->name, B, len));
+ return dStrnAsciiCasecmp(A->name, B, len);
}
/*!