From 684aa3187fc5d2a759bd98459d829cf3ed7f04df Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 31 Jan 2016 17:27:15 +0100 Subject: util.random: Restore friendlier error from 0.9/util.uuid --- util/random.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/random.lua b/util/random.lua index 05f36aba..e4b4a700 100644 --- a/util/random.lua +++ b/util/random.lua @@ -6,7 +6,7 @@ -- COPYING file in the source package for more information. -- -local urandom = assert(io.open("/dev/urandom", "r")); +local urandom, urandom_err = io.open("/dev/urandom", "r"); local function seed() end @@ -15,6 +15,12 @@ local function bytes(n) return urandom:read(n); end +if not urandom then + function bytes() + error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")"); + end +end + return { seed = seed; bytes = bytes; -- cgit v1.2.3 From d0c5e1571fcd0d0242815c1076d56ecf917eec13 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Feb 2016 21:26:15 +0000 Subject: modulemanager, util.pluginloader: Move logic for locating some module libraries to pluginloader, to fix problems with non-filesystem errors being masked by the second load_code call --- core/moduleapi.lua | 5 +---- util/pluginloader.lua | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 5817894f..c439ba6f 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -135,10 +135,7 @@ function api:wrap_global(event, handler) end function api:require(lib) - local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); - if not f then - f, n = pluginloader.load_code(lib, lib..".lib.lua", self.environment); - end + local f, n = pluginloader.load_code_ext(self.name, lib, "lib.lua", self.environment); if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message return f(); end diff --git a/util/pluginloader.lua b/util/pluginloader.lua index 0d7eafa7..004855f0 100644 --- a/util/pluginloader.lua +++ b/util/pluginloader.lua @@ -55,8 +55,23 @@ local function load_code(plugin, resource, env) return f, path; end +local function load_code_ext(plugin, resource, extension, env) + local content, err = load_resource(plugin, resource.."."..extension); + if not content then + content, err = load_resource(resource, resource.."."..extension); + if not content then + return content, err; + end + end + local path = err; + local f, err = envload(content, "@"..path, env); + if not f then return f, err; end + return f, path; +end + return { load_file = load_file; load_resource = load_resource; load_code = load_code; + load_code_ext = load_code_ext; }; -- cgit v1.2.3