diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2025-01-17 20:55:26 +0100 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2025-01-17 21:00:15 +0100 |
commit | 2370663e4ce34f52aa2f89d7d3a979b08c0a54bb (patch) | |
tree | 7cd05ae11ab1898755b6ca6e4a71bb81bb363ae1 /dpid | |
parent | f10a7800efa7c3a8017878e6e998ecf7b32d8e86 (diff) |
Print error if dpi_dir cannot be opened
On cases where the system directory cannot be opened, dpid will not load
the builtin plugins causing Dillo to fail to work properly with file: or
data: URLs. Reporting a failure to open the directory allows users to
determine the cause of the problem.
See: https://github.com/dillo-browser/dillo/issues/337
Diffstat (limited to 'dpid')
-rw-r--r-- | dpid/dpid.c | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/dpid/dpid.c b/dpid/dpid.c index 9bf28f46..49ee4dc8 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -1,5 +1,6 @@ /* Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au> + Copyright (C) 2025 Rodrigo Arias Mallo <rodarima@gmail.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -346,7 +347,6 @@ int register_service(struct dp *dpi_attr, char *service) */ int register_all(struct dp **attlist) { - DIR *user_dir_stream, *sys_dir_stream; char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL; struct dirent *user_dirent, *sys_dirent; int st; @@ -385,28 +385,43 @@ int register_all(struct dp **attlist) /* Get list of services in user's .dillo/dpi directory */ snum = 0; - if (user_dpidir && (user_dir_stream = opendir(user_dpidir)) != NULL) { - while ((user_dirent = readdir(user_dir_stream)) != NULL) { - if (user_dirent->d_name[0] == '.') - continue; - *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); - st=get_dpi_attr(user_dpidir, user_dirent->d_name, &(*attlist)[snum]); - if (st == 0) - snum++; + if (user_dpidir) { + DIR *user_dir_stream = opendir(user_dpidir); + /* Only complain if error is other than not found as the user may not have + * any DPIs installed. */ + if (user_dir_stream == NULL && errno != ENOENT) { + MSG_ERR("cannot open user dpi directory '%s': %s\n", + user_dpidir, strerror(errno)); + } else { + while ((user_dirent = readdir(user_dir_stream)) != NULL) { + if (user_dirent->d_name[0] == '.') + continue; + *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); + st=get_dpi_attr(user_dpidir, user_dirent->d_name, &(*attlist)[snum]); + if (st == 0) + snum++; + } + closedir(user_dir_stream); } - closedir(user_dir_stream); - } - if (sys_dpidir && (sys_dir_stream = opendir(sys_dpidir)) != NULL) { - /* if system service is not in user list then add it */ - while ((sys_dirent = readdir(sys_dir_stream)) != NULL) { - if (sys_dirent->d_name[0] == '.') - continue; - *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); - st=get_dpi_attr(sys_dpidir, sys_dirent->d_name, &(*attlist)[snum]); - if (st == 0) - snum++; + } + if (sys_dpidir) { + DIR *sys_dir_stream = opendir(sys_dpidir); + /* For system DPIs always complain. */ + if (sys_dir_stream == NULL) { + MSG_ERR("cannot open system dpi directory '%s': %s\n", + sys_dpidir, strerror(errno)); + } else { + /* if system service is not in user list then add it */ + while ((sys_dirent = readdir(sys_dir_stream)) != NULL) { + if (sys_dirent->d_name[0] == '.') + continue; + *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); + st=get_dpi_attr(sys_dpidir, sys_dirent->d_name, &(*attlist)[snum]); + if (st == 0) + snum++; + } + closedir(sys_dir_stream); } - closedir(sys_dir_stream); } dFree(sys_dpidir); |