From: Christian Grothoff Date: Tue, 26 Feb 2019 08:08:21 +0000 (+0100) Subject: fix /tmp/rps directory creation, fix linkage, DCE X-Git-Tag: v0.11.0~37^2~1 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3495689e26efb8f9690945d3c7f4cd68eaeaaf86;p=oweals%2Fgnunet.git fix /tmp/rps directory creation, fix linkage, DCE --- diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index a356d3dbc..b391eb8ae 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am @@ -60,7 +60,6 @@ gnunet_service_rps_SOURCES = \ gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \ gnunet-service-rps_view.h gnunet-service-rps_view.c \ - rps-test_util.h rps-test_util.c \ gnunet-service-rps.c diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 85829f247..077750329 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -414,44 +414,6 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) return name_buf; } - - -char * -create_file (const char *name) -{ - int size; - size_t name_buf_size; - char *name_buf; - char *prefix; - char *file_name; - - prefix = "/tmp/rps/"; - name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char); - name_buf = GNUNET_malloc (name_buf_size); - - size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s", prefix, name); - if (0 > size) - LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); - - if (GNUNET_YES != GNUNET_DISK_directory_create (prefix)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Could not create directory %s.\n", - prefix); - } - - if (NULL == strstr (name, "sampler_el")) - {/* only append random string to sampler */ - if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) - LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); - - GNUNET_free (name_buf); - return file_name; - } - - return name_buf; -} - #endif /* TO_FILE */ @@ -479,23 +441,23 @@ string_to_auth_key (const char *str) * @return #GNUNET_YES on success * #GNUNET_SYSERR on failure */ -static int ensure_folder_exist (void) +static int +ensure_folder_exist (void) { - if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) - { - GNUNET_DISK_directory_create ("/tmp/rps"); - } - if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) + if (GNUNET_OK != + GNUNET_DISK_directory_create ("/tmp/rps")) { - LOG (GNUNET_ERROR_TYPE_ERROR, "Could not create directory `/tmp/rps'\n"); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Could not create directory `/tmp/rps'\n"); return GNUNET_SYSERR; } return GNUNET_YES; } + char * store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, - const char *prefix) + const char *prefix) { int len_file_name; int out_size; diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 78d1e0a26..ace833034 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h @@ -37,8 +37,6 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); struct GNUNET_CRYPTO_AuthKey string_to_auth_key (const char *str); -char * -create_file (const char *name); /** * @brief Get file handle @@ -64,9 +62,10 @@ close_all_files (); * This function is used to facilitate writing important information to disk */ #ifdef TO_FILE -#define to_file(file_name, ...) do { if (NULL == file_name) { GNUNET_break(0); return;} \ +#define to_file(file_name, ...) do { \ char tmp_buf[512] = "";\ int size;\ + if (NULL == file_name) return; \ size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ if (0 > size)\ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ diff --git a/src/util/disk.c b/src/util/disk.c index de37cba0a..4f78c7747 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -625,7 +625,8 @@ GNUNET_DISK_mktemp (const char *t) * does not exist or stat'ed */ int -GNUNET_DISK_directory_test (const char *fil, int is_readable) +GNUNET_DISK_directory_test (const char *fil, + int is_readable) { struct stat filestat; int ret; @@ -639,7 +640,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable) } if (!S_ISDIR (filestat.st_mode)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, + LOG (GNUNET_ERROR_TYPE_INFO, "A file already exits with the same name %s\n", fil); return GNUNET_NO; } @@ -720,7 +721,10 @@ GNUNET_DISK_directory_create (const char *dir) rdir = GNUNET_STRINGS_filename_expand (dir); if (rdir == NULL) + { + GNUNET_break (0); return GNUNET_SYSERR; + } len = strlen (rdir); #ifndef MINGW @@ -756,6 +760,9 @@ GNUNET_DISK_directory_create (const char *dir) ret = GNUNET_DISK_directory_test (rdir, GNUNET_NO); if (GNUNET_NO == ret) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Creating directory `%s' failed", + rdir); GNUNET_free (rdir); return GNUNET_SYSERR; } @@ -780,6 +787,9 @@ GNUNET_DISK_directory_create (const char *dir) ret = GNUNET_DISK_directory_test (rdir, GNUNET_NO); if (GNUNET_NO == ret) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Creating directory `%s' failed", + rdir); GNUNET_free (rdir); return GNUNET_SYSERR; } @@ -2684,7 +2694,7 @@ purge_cfg_dir (void *cls, { const char *option = cls; char *tmpname; - + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS",