From d6c9f0ce591cb6d5302a81d0e02477ced25b06a5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 16:42:02 +0100 Subject: util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected --- util/envload.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/envload.lua b/util/envload.lua index 3c5190df..08adf35e 100644 --- a/util/envload.lua +++ b/util/envload.lua @@ -6,7 +6,8 @@ -- -- luacheck: ignore 113/setfenv -local load, loadstring, loadfile, setfenv = load, loadstring, loadfile, setfenv; +local load, loadstring, setfenv = load, loadstring, setfenv; +local io_open = io.open; local envload; local envloadfile; @@ -18,7 +19,9 @@ if setfenv then end function envloadfile(file, env) - local f, err = loadfile(file); + local fh, err, errno = io_open(file); + if not fh then return fh, err, errno; end + local f, err = load(function () return fh:read(2048); end, "@"..file); if f and env then setfenv(f, env); end return f, err; end @@ -28,7 +31,9 @@ else end function envloadfile(file, env) - return loadfile(file, nil, env); + local fh, err, errno = io_open(file); + if not fh then return fh, err, errno; end + return load(fh:lines(2048), "@"..file, nil, env); end end -- cgit v1.2.3 From fc38b8c4f4fe84d6ed15128a96348f5a256bb9a2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 16:44:59 +0100 Subject: util.datamanager: Ignore ENOENT (no such file) when loading data --- util/datamanager.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index 585bb83d..52d0c0bf 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -39,6 +39,7 @@ local function fallocate(f, offset, len) f:seek("set", offset); return true; end; +local ENOENT = 2; pcall(function() local pposix = require "util.pposix"; raw_mkdir = pposix.mkdir or raw_mkdir; -- Doesn't trample on umask @@ -122,8 +123,12 @@ local function getpath(username, host, datastore, ext, create) end local function load(username, host, datastore) - local data, err = envloadfile(getpath(username, host, datastore), {}); + local data, err, errno = envloadfile(getpath(username, host, datastore), {}); if not data then + if errno == ENOENT then + -- No such file, ok to ignore + return nil; + end local mode = lfs.attributes(getpath(username, host, datastore), "mode"); if not mode then log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); @@ -145,9 +150,9 @@ end local function atomic_store(filename, data) local scratch = filename.."~"; - local f, ok, msg; + local f, ok, msg, errno; - f, msg = io_open(scratch, "w"); + f, msg, errno = io_open(scratch, "w"); if not f then return nil, msg; end @@ -295,8 +300,12 @@ end local function list_load(username, host, datastore) local items = {}; - local data, err = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end}); + local data, err, errno = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end}); if not data then + if errno == ENOENT then + -- No such file, ok to ignore + return nil; + end local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode"); if not mode then log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); -- cgit v1.2.3 From 82755e48e832ca94886d0d4376343ac74cf00bd6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 17:03:48 +0100 Subject: util.pposix: Expose ENOENT constant (usually 2, but you never know) --- util-src/pposix.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util-src/pposix.c b/util-src/pposix.c index 10edbd71..da47cac2 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -835,6 +835,11 @@ int luaopen_util_pposix(lua_State *L) { lua_newtable(L); luaL_setfuncs(L, exports, 0); +#ifdef ENOENT + lua_pushinteger(L, ENOENT); + lua_setfield(L, -2, "ENOENT"); +#endif + lua_pushliteral(L, "pposix"); lua_setfield(L, -2, "_NAME"); -- cgit v1.2.3 From f0c676e8c6e714fcdd898c913af0b705ccde61ee Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 17:04:48 +0100 Subject: util.datamanager: Import value of ENOENT from util.pposix (if available) --- util/datamanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/datamanager.lua b/util/datamanager.lua index 52d0c0bf..8ef3c050 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -44,6 +44,7 @@ pcall(function() local pposix = require "util.pposix"; raw_mkdir = pposix.mkdir or raw_mkdir; -- Doesn't trample on umask fallocate = pposix.fallocate or fallocate; + ENOENT = pposix.ENOENT or ENOENT; end); local _ENV = nil; -- cgit v1.2.3 From c3aae40b197b00014765a5dcc2874e4483a5d6dc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 17:15:56 +0100 Subject: util.datamanager: Use atomic store function when writing the first entry of a list --- util/datamanager.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index 8ef3c050..d36865d7 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -228,11 +228,8 @@ local function append(username, host, datastore, ext, data) local ok; local f, msg = io_open(filename, "r+"); if not f then + return atomic_store(filename, data); -- File did probably not exist, let's create it - f, msg = io_open(filename, "w"); - if not f then - return nil, msg, "open"; - end end local pos = f:seek("end"); -- cgit v1.2.3 From cb0953029e238d93ab44fce8a545e2ac9e56c190 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 17:37:29 +0100 Subject: util.datamanager: Expose atomic_store as store_raw --- util/datamanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/datamanager.lua b/util/datamanager.lua index d36865d7..2b47c3c4 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -415,6 +415,7 @@ return { load = load; store = store; append_raw = append; + store_raw = atomic_store; list_append = list_append; list_store = list_store; list_load = list_load; -- cgit v1.2.3 From f637fde31f2a8c06819001b6d2b1766a51dd8cb2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 17:48:15 +0100 Subject: util.envload: Close file handle after reading data --- util/envload.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/envload.lua b/util/envload.lua index 08adf35e..926f20c0 100644 --- a/util/envload.lua +++ b/util/envload.lua @@ -22,6 +22,7 @@ if setfenv then local fh, err, errno = io_open(file); if not fh then return fh, err, errno; end local f, err = load(function () return fh:read(2048); end, "@"..file); + fh:close(); if f and env then setfenv(f, env); end return f, err; end @@ -33,7 +34,9 @@ else function envloadfile(file, env) local fh, err, errno = io_open(file); if not fh then return fh, err, errno; end - return load(fh:lines(2048), "@"..file, nil, env); + local f, err = load(fh:lines(2048), "@"..file, nil, env); + fh:close(); + return f, err; end end -- cgit v1.2.3 From d205c783278eea95143aa95443803c16882c3f5b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 22:27:11 +0100 Subject: util.pposix, configure: Move _GNU_SOURCE macro into source files --- configure | 6 +++--- util-src/crand.c | 2 ++ util-src/net.c | 1 + util-src/pposix.c | 24 ++++++++++++------------ util-src/signal.c | 2 ++ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 974823c3..126fee3d 100755 --- a/configure +++ b/configure @@ -113,7 +113,7 @@ do RUNWITH="lua$LUA_SUFFIX" LUA_INCDIR="/usr/include/lua$LUA_SUFFIX" LUA_INCDIR_SET=yes - CFLAGS="$CFLAGS -ggdb -D_GNU_SOURCE" + CFLAGS="$CFLAGS -ggdb" fi if [ "$OSTYPE" = "macosx" ]; then LUA_INCDIR=/usr/local/include; @@ -128,7 +128,7 @@ do LUA_INCDIR_SET=yes LUA_LIBDIR=/usr/local/lib LUA_LIBDIR_SET=yes - CFLAGS="$CFLAGS -ggdb -D_GNU_SOURCE" + CFLAGS="$CFLAGS -ggdb" fi if [ "$OSTYPE" = "freebsd" -o "$OSTYPE" = "openbsd" ]; then LUA_INCDIR="/usr/local/include/lua51" @@ -167,7 +167,7 @@ do LUA_INCDIR="$LUA_CF" LUA_INCDIR_SET=yes fi - CFLAGS="$CFLAGS -D_GNU_SOURCE" + CFLAGS="$CFLAGS" fi ;; --libdir=*) diff --git a/util-src/crand.c b/util-src/crand.c index f3fa00ea..8ac89a1f 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -19,6 +19,8 @@ * */ +#define _DEFAULT_SOURCE + #include "lualib.h" #include "lauxlib.h" diff --git a/util-src/net.c b/util-src/net.c index 32f69025..35f2c362 100644 --- a/util-src/net.c +++ b/util-src/net.c @@ -9,6 +9,7 @@ -- */ +#define _GNU_SOURCE #include #include #include diff --git a/util-src/pposix.c b/util-src/pposix.c index da47cac2..f9c07e54 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -15,6 +15,14 @@ #define MODULE_VERSION "0.3.6" + +#if defined(__linux__) +#define _GNU_SOURCE +#else +#define _DEFAULT_SOURCE +#endif +#define _POSIX_C_SOURCE 200809L + #include #include #include @@ -40,11 +48,11 @@ #endif #include -#if defined(__linux__) && defined(_GNU_SOURCE) +#if defined(__linux__) #include #endif -#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO)) +#if !defined(WITHOUT_MALLINFO) #include #define WITH_MALLINFO #endif @@ -663,7 +671,7 @@ int lc_uname(lua_State *L) { lua_setfield(L, -2, "version"); lua_pushstring(L, uname_info.machine); lua_setfield(L, -2, "machine"); -#ifdef _GNU_SOURCE +#ifdef __USE_GNU lua_pushstring(L, uname_info.domainname); lua_setfield(L, -2, "domainname"); #endif @@ -726,7 +734,6 @@ int lc_meminfo(lua_State *L) { * https://github.com/rrthomas/luaposix/blob/master/lposix.c#L631 * */ -#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE) int lc_fallocate(lua_State *L) { int ret; off_t offset, len; @@ -739,7 +746,7 @@ int lc_fallocate(lua_State *L) { offset = luaL_checkinteger(L, 2); len = luaL_checkinteger(L, 3); -#if defined(__linux__) && defined(_GNU_SOURCE) +#if defined(__linux__) errno = 0; ret = fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len); @@ -759,10 +766,6 @@ int lc_fallocate(lua_State *L) { return 2; } -#else -#warning Only using posix_fallocate() fallback. -#warning Linux fallocate() is strongly recommended if available: recompile with -D_GNU_SOURCE -#warning Note that posix_fallocate() will still be used on filesystems that dont support fallocate() #endif ret = posix_fallocate(fileno(f), offset, len); @@ -784,7 +787,6 @@ int lc_fallocate(lua_State *L) { return 2; } } -#endif /* Register functions */ @@ -825,9 +827,7 @@ int luaopen_util_pposix(lua_State *L) { { "meminfo", lc_meminfo }, #endif -#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE) { "fallocate", lc_fallocate }, -#endif { NULL, NULL } }; diff --git a/util-src/signal.c b/util-src/signal.c index a083df54..2cf68800 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -26,6 +26,8 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#define _POSIX_C_SOURCE 200809L + #include #include -- cgit v1.2.3 From dfb72918f3fa150c6f6bae95cf2c945d17200fd4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Mar 2017 22:39:01 +0100 Subject: util.crand: Move comment block --- util-src/crand.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util-src/crand.c b/util-src/crand.c index 8ac89a1f..95362589 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -36,10 +36,6 @@ #error getrandom() requires Linux 3.17 or later #endif -/* - * This acts like a read from /dev/urandom with the exception that it - * *does* block if the entropy pool is not yet initialized. - */ int getrandom(void *buf, size_t len, int flags) { return syscall(SYS_getrandom, buf, len, flags); } @@ -58,6 +54,10 @@ int Lrandom(lua_State *L) { void *buf = lua_newuserdata(L, len); #if defined(WITH_GETRANDOM) + /* + * This acts like a read from /dev/urandom with the exception that it + * *does* block if the entropy pool is not yet initialized. + */ ret = getrandom(buf, len, 0); if(ret < 0) { -- cgit v1.2.3 From 7dba99875fa4a3539cc7778efa7486bdcefea898 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 00:15:04 +0100 Subject: util.crand: Change argumen names to match some man page --- util-src/crand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-src/crand.c b/util-src/crand.c index 95362589..353b153c 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -36,8 +36,8 @@ #error getrandom() requires Linux 3.17 or later #endif -int getrandom(void *buf, size_t len, int flags) { - return syscall(SYS_getrandom, buf, len, flags); +int getrandom(void *buf, size_t buflen, unsigned int flags) { + return syscall(SYS_getrandom, buf, buflen, flags); } #elif defined(WITH_ARC4RANDOM) -- cgit v1.2.3 From 956c50882b749f8b3cc007aaec8c0a5c2c6725ee Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 00:17:34 +0100 Subject: util.crand: Only include getrandom shiv with glibc older than 2.25 --- util-src/crand.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util-src/crand.c b/util-src/crand.c index 353b153c..ef9da4d2 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -28,17 +28,22 @@ #include #if defined(WITH_GETRANDOM) + +#if ! __GLIBC_PREREQ(2,25) #include #include -#include #ifndef SYS_getrandom #error getrandom() requires Linux 3.17 or later #endif +/* This wasn't present before glibc 2.25 */ int getrandom(void *buf, size_t buflen, unsigned int flags) { return syscall(SYS_getrandom, buf, buflen, flags); } +#else +#include +#endif #elif defined(WITH_ARC4RANDOM) #include -- cgit v1.2.3 From cd37249852e745b72cf56f7e7e404764d9a457a6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 00:27:46 +0100 Subject: configure: Set C standard to C99 --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 126fee3d..6fc612b5 100755 --- a/configure +++ b/configure @@ -21,7 +21,7 @@ EXCERTS="yes" PRNG= PRNGLIBS= -CFLAGS="-fPIC -Wall -pedantic -std=c89" +CFLAGS="-fPIC -Wall -pedantic -std=c99" LDFLAGS="-shared" IDN_LIBRARY="idn" -- cgit v1.2.3 From 3bf3935e78e682642593f783762bc648a65f4d72 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 00:46:32 +0100 Subject: Backed out changeset a3a4ed0d34f4 C99 is ok --- util-src/table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util-src/table.c b/util-src/table.c index 0e547858..f1cd9e12 100644 --- a/util-src/table.c +++ b/util-src/table.c @@ -7,12 +7,11 @@ static int Lcreate_table(lua_State *L) { } static int Lpack(lua_State *L) { - int arg; unsigned int n_args = lua_gettop(L); lua_createtable(L, n_args, 1); lua_insert(L, 1); - for(arg = n_args; arg >= 1; arg--) { + for(int arg = n_args; arg >= 1; arg--) { lua_rawseti(L, 1, arg); } -- cgit v1.2.3 From f6e6bc0bd98cd80284856cca780442361c6f1f88 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 03:03:04 +0100 Subject: mod_websocket: Include xml:lang attribute on stream (fixes #840) --- plugins/mod_websocket.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua index 47d170a1..01f2fa5b 100644 --- a/plugins/mod_websocket.lua +++ b/plugins/mod_websocket.lua @@ -54,6 +54,7 @@ local c2s_listener = portmanager.get_service("c2s").listener; local function session_open_stream(session) local attr = { xmlns = xmlns_framing, + ["xml:lang"] = "en", version = "1.0", id = session.streamid or "", from = session.host -- cgit v1.2.3 From fd19cd42b0d97ead99d7af196d98d2ffdd51dcec Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 03:03:25 +0100 Subject: mod_websocket: Make open_stream method behave like the one from util.xmppstream --- plugins/mod_websocket.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua index 01f2fa5b..3c96f780 100644 --- a/plugins/mod_websocket.lua +++ b/plugins/mod_websocket.lua @@ -51,14 +51,17 @@ local sessions = module:shared("c2s/sessions"); local c2s_listener = portmanager.get_service("c2s").listener; --- Session methods -local function session_open_stream(session) +local function session_open_stream(session, from, to) local attr = { xmlns = xmlns_framing, ["xml:lang"] = "en", version = "1.0", id = session.streamid or "", - from = session.host + from = from or session.host, to = to, }; + if session.stream_attrs then + session:stream_attrs(from, to, attr) + end session.send(st.stanza("open", attr)); end -- cgit v1.2.3 From d471c7b124575cb2657c0e80711e8803f797b25f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 15:17:32 +0100 Subject: mod_saslauth: Log SASL failure reason --- plugins/mod_saslauth.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index c5d3dc91..d374633e 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -96,8 +96,19 @@ end) module:hook_stanza(xmlns_sasl, "failure", function (session, stanza) if session.type ~= "s2sout_unauthed" or session.external_auth ~= "attempting" then return; end - module:log("info", "SASL EXTERNAL with %s failed", session.to_host) - -- TODO: Log the failure reason + local text = stanza:get_child_text("text"); + local condition = "unknown-condition"; + for child in stanza:childtags() do + if child.name ~= "text" then + condition = child.name; + break; + end + end + if text and condition then + condition = connection .. ": " .. text; + end + module:log("info", "SASL EXTERNAL with %s failed: %s", session.to_host, condition); + session.external_auth = "failed" end, 500) -- cgit v1.2.3 From 2246bd21b50f12862cb99c92edfaa79c97f4d47b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 19:22:07 +0100 Subject: util.ringbuffer: Change types of length related variables to size_t [-Wsign-compare] --- util-src/ringbuffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-src/ringbuffer.c b/util-src/ringbuffer.c index 831b1fe2..2a13903c 100644 --- a/util-src/ringbuffer.c +++ b/util-src/ringbuffer.c @@ -31,7 +31,7 @@ void modpos(ringbuffer *b) { b->wpos = b->wpos % b->alen; } -int find(ringbuffer *b, const char *s, int l) { +int find(ringbuffer *b, const char *s, size_t l) { size_t i, j; int m; @@ -74,7 +74,7 @@ int rb_find(lua_State *L) { int rb_read(lua_State *L) { ringbuffer *b = luaL_checkudata(L, 1, "ringbuffer_mt"); - int r = luaL_checkinteger(L, 2); + size_t r = luaL_checkinteger(L, 2); int peek = lua_toboolean(L, 3); if(r > b->blen) { -- cgit v1.2.3 From 33a4138411663af5fb65389e41218993c8d7bc2b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 22:58:34 +0100 Subject: configure: Merge with configure from LuaRocks (which it was originally based on apparently) --- configure | 362 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 266 insertions(+), 96 deletions(-) diff --git a/configure b/configure index 6fc612b5..bd4462ed 100755 --- a/configure +++ b/configure @@ -42,10 +42,15 @@ Configure Prosody prior to building. Default is \$PREFIX/lib --datadir=DIR Location where the server data should be stored. Default is \$PREFIX/var/lib/prosody +--lua-version=VERSION Use specific Lua version: 5.1, 5.2, or 5.3 + Default is auto-detected. --lua-suffix=SUFFIX Versioning suffix to use in Lua filenames. Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...) --with-lua=PREFIX Use Lua from given prefix. - Default is $LUA_DIR + Default is auto-detected (the parent directory of \$LUA_BINDIR). +--with-lua-bin=DIR You can also specify Lua's bin dir. + Default is the directory of the auto-detected Lua interpreter, + or \$LUA_DIR/bin if --with-lua is used. --runwith=BINARY What Lua binary to set as runtime environment. Default is $RUNWITH --with-lua-include=DIR You can also specify Lua's includes dir. @@ -78,31 +83,86 @@ Configure Prosody prior to building. EOF } +# Helper functions -while [ "$1" ] +find_program() { + prog=`command -v "$1" 2>/dev/null` + if [ -n "$prog" ] + then + dirname "$prog" + fi +} + +die() { + echo "$*" + echo + echo "configure failed." + echo + exit 1 +} + +find_helper() { + explanation="$1" + shift + tried="$*" + while [ -n "$1" ] +do + found=`find_program "$1"` + if [ -n "$found" ] + then + echo "$1 found at $found" + HELPER=$1 + return + fi + shift + done + echo "Could not find $explanation. Tried: $tried." + die "Make sure one of them is installed and available in your PATH." +} + +case `echo -n x` in +-n*) echo_n_flag='';; +*) echo_n_flag='-n';; +esac + +echo_n() { + echo $echo_n_flag "$*" +} + +# ---------------------------------------------------------------------------- +# MAIN PROGRAM +# ---------------------------------------------------------------------------- + +# Parse options + +while [ -n "$1" ] do - value="$(echo "$1" | sed 's/[^=]*=\(.*\)/\1/')" - if echo "$value" | grep -q "~" + value="`echo $1 | sed 's/[^=]*.\(.*\)/\1/'`" + key="`echo $1 | sed 's/=.*//'`" + if `echo "$value" | grep "~" >/dev/null 2>/dev/null` then echo echo '*WARNING*: the "~" sign is not expanded in flags.' echo 'If you mean the home directory, use $HOME instead.' echo fi - case "$1" in + case "$key" in --help) show_help exit 0 ;; - --prefix=*) + --prefix) + [ -n "$value" ] || die "Missing value in flag $key." PREFIX="$value" PREFIX_SET=yes ;; - --sysconfdir=*) + --sysconfdir) + [ -n "$value" ] || die "Missing value in flag $key." SYSCONFDIR="$value" SYSCONFDIR_SET=yes ;; - --ostype=*) + --ostype) + # TODO make this a switch? OSTYPE="$value" OSTYPE_SET=yes if [ "$OSTYPE" = "debian" ]; then @@ -170,76 +230,94 @@ do CFLAGS="$CFLAGS" fi ;; - --libdir=*) + --libdir) LIBDIR="$value" LIBDIR_SET=yes ;; - --datadir=*) + --datadir) DATADIR="$value" DATADIR_SET=yes ;; --require-config) REQUIRE_CONFIG=yes ;; - --lua-suffix=*) + --lua-suffix) + [ -n "$value" ] || die "Missing value in flag $key." LUA_SUFFIX="$value" LUA_SUFFIX_SET=yes ;; - --with-lua=*) + --lua-version|--with-lua-version) + [ -n "$value" ] || die "Missing value in flag $key." + LUA_VERSION="$value" + [ "$LUA_VERSION" = "5.1" -o "$LUA_VERSION" = "5.2" -o "$LUA_VERSION" = "5.3" ] || die "Invalid Lua version in flag $key." + LUA_VERSION_SET=yes + ;; + --with-lua) + [ -n "$value" ] || die "Missing value in flag $key." LUA_DIR="$value" LUA_DIR_SET=yes ;; - --with-lua-include=*) + --with-lua-bin) + [ -n "$value" ] || die "Missing value in flag $key." + LUA_BINDIR="$value" + LUA_BINDIR_SET=yes + ;; + --with-lua-include) + [ -n "$value" ] || die "Missing value in flag $key." LUA_INCDIR="$value" LUA_INCDIR_SET=yes ;; - --with-lua-lib=*) - LUA_LIBDIR="$value" LUA_LIBDIR_SET=yes + --with-lua-lib) + [ -n "$value" ] || die "Missing value in flag $key." + LUA_LIBDIR="$value" + LUA_LIBDIR_SET=yes ;; - --with-idn=*) + --with-idn) IDN_LIB="$value" ;; - --idn-library=*) + --idn-library) IDN_LIBRARY="$value" ;; - --with-ssl=*) + --with-ssl) OPENSSL_LIB="$value" ;; - --with-random=getrandom) - PRNG=GETRANDOM - ;; - --with-random=openssl) - PRNG=OPENSSL - PRNGLIBS=-lcrypto + --with-random) + case "$value" in + getrandom) + PRNG=GETRANDOM + ;; + openssl) + PRNG=OPENSSL + ;; + arc4random) + PRNG=ARC4RANDOM + ;; + esac ;; - --with-random=arc4random) - PRNG=ARC4RANDOM - ;; - --cflags=*) + --cflags) CFLAGS="$value" ;; - --ldflags=*) + --ldflags) LDFLAGS="$value" ;; - --c-compiler=*) + --c-compiler) CC="$value" ;; - --linker=*) + --linker) LD="$value" ;; - --runwith=*) + --runwith) RUNWITH="$value" ;; --no-example-certs) EXCERTS= ;; - --compiler-wrapper=*) + --compiler-wrapper) CC="$value $CC" LD="$value $LD" ;; *) - echo "Error: Unknown flag: $1" - exit 1 + die "Error: Unknown flag: $1" ;; esac shift @@ -261,72 +339,103 @@ then fi fi -if [ "$PREFIX_SET" = "yes" -a ! "$LIBDIR_SET" = "yes" ] -then - LIBDIR=$PREFIX/lib -fi - -find_program() { - path="$PATH" - item="$(echo "$path" | sed 's/\([^:]*\):.*/\1/')" - path="$(echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p')" - found="no" - while [ "$item" ] - do - if [ -f "$item/$1" ] +detect_lua_version() { + detected_lua=`$1 -e 'print(_VERSION:match(" (5%.[123])$"))' 2> /dev/null` + if [ "$detected_lua" != "nil" ] + then + if [ "$LUA_VERSION_SET" != "yes" ] then - found="yes" - break + echo "Lua version detected: $detected_lua" + LUA_VERSION=$detected_lua + return 0 + elif [ "$LUA_VERSION" = "$detected_lua" ] + then + return 0 fi - item="$(echo "$path" | sed 's/\([^:]*\):.*/\1/')" - path="$(echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p')" - done - if [ "$found" = "yes" ] - then - echo "$item" - else - echo "" fi + return 1 } -if [ "$LUA_SUFFIX_SET" != "yes" ] -then - for suffix in "5.1" "51" "" - do - LUA_SUFFIX="$suffix" - if [ "$LUA_DIR_SET" = "yes" ] +search_interpreter() { + suffix="$1" + if [ "$LUA_BINDIR_SET" = "yes" ] then - if [ -f "$LUA_DIR/bin/lua$suffix" ] - then - find_lua="$LUA_DIR" - fi - else - find_lua="$(find_program lua$suffix)" + find_lua="$LUA_BINDIR" + elif [ "$LUA_DIR_SET" = "yes" ] + then + LUA_BINDIR="$LUA_DIR/bin" + if [ -f "$LUA_BINDIR/lua$suffix" ] + then + find_lua="$LUA_BINDIR" fi - if [ "$find_lua" ] + else + find_lua=`find_program lua$suffix` + fi + if [ -n "$find_lua" -a -x "$find_lua/lua$suffix" ] + then + if detect_lua_version "$find_lua/lua$suffix" then echo "Lua interpreter found: $find_lua/lua$suffix..." - break + if [ "$LUA_BINDIR_SET" != "yes" ] + then + LUA_BINDIR="$find_lua" + fi + if [ "$LUA_DIR_SET" != "yes" ] + then + LUA_DIR=`dirname "$find_lua"` + fi + LUA_SUFFIX="$suffix" + return 0 fi - done -fi + fi + return 1 +} -if [ "$LUA_DIR_SET" != "yes" ] +lua_interp_found=no +if [ "$LUA_SUFFIX_SET" != "yes" ] then - echo -n "Looking for Lua... " - if [ ! "$find_lua" ] + if [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.1" ] + then + suffixes="5.1 51 -5.1 -51" + elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.2" ] then - find_lua="$(find_program lua$LUA_SUFFIX)" - echo "lua$LUA_SUFFIX found in \$PATH: $find_lua" + suffixes="5.2 52 -5.2 -52" + elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.3" ] + then + suffixes="5.3 53 -5.3 -53" + else + suffixes="5.1 51 -5.1 -51 5.2 52 -5.2 -52 5.3 53 -5.3 -53" fi - if [ "$find_lua" ] + for suffix in "" `echo $suffixes` + do + search_interpreter "$suffix" && { + lua_interp_found=yes + break + } +done +else + search_interpreter "$LUA_SUFFIX" && { + lua_interp_found=yes +} +fi + +if [ "$lua_interp_found" != "yes" ] +then + [ "$LUA_VERSION_SET" ] && { interp="Lua $LUA_VERSION" ;} || { interp="Lua" ;} + [ "$LUA_DIR_SET" -o "$LUA_BINDIR_SET" ] && { where="$LUA_BINDIR" ;} || { interp="\$PATH" ;} + echo "$interp interpreter not found in $where" + die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." +fi + +if [ "$LUA_VERSION_SET" = "yes" ] +then + echo_n "Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... " + if detect_lua_version "$LUA_BINDIR/lua$LUA_SUFFIX" then - LUA_DIR="$(dirname $find_lua)" - LUA_BINDIR="$find_lua" + echo "yes" else - echo "lua$LUA_SUFFIX not found in \$PATH." - echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help." - exit 1 + echo "no" + die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." fi fi @@ -340,9 +449,69 @@ then LUA_LIBDIR="$LUA_DIR/lib" fi -if [ "$LUA_DIR_SET" = "yes" ] +echo_n "Checking Lua includes... " +lua_h="$LUA_INCDIR/lua.h" +if [ -f "$lua_h" ] then - LUA_BINDIR="$LUA_DIR/bin" + echo "lua.h found in $lua_h" +else + v_dir="$LUA_INCDIR/lua/$LUA_VERSION" + lua_h="$v_dir/lua.h" + if [ -f "$lua_h" ] + then + echo "lua.h found in $lua_h" + LUA_INCDIR="$v_dir" + else + d_dir="$LUA_INCDIR/lua$LUA_VERSION" + lua_h="$d_dir/lua.h" + if [ -f "$lua_h" ] + then + echo "lua.h found in $lua_h (Debian/Ubuntu)" + LUA_INCDIR="$d_dir" + else + echo "lua.h not found (looked in $LUA_INCDIR, $v_dir, $d_dir)" + die "You may want to use the flag --with-lua or --with-lua-include. See --help." + fi + fi +fi + +echo_n "Checking if Lua header version matches that of the interpreter... " +header_version=$(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h") +if [ "$header_version" = "$LUA_VERSION" ] +then + echo "yes" +else + echo "no" + echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)." + die "You may want to use the flag --with-lua or --with-lua-include. See --help." +fi + +echo_n "Configuring for system... " +if uname -s +then + UNAME_S=`uname -s` +else + die "Could not determine operating system. 'uname -s' failed." +fi +echo_n "Configuring for architecture... " +if uname -m +then + UNAME_M=`uname -m` +else + die "Could not determine processor architecture. 'uname -m' failed." +fi + +if [ "$UNAME_S" = Linux ] +then + GCC_ARCH=`gcc -print-multiarch 2>/dev/null` + if [ -n "$GCC_ARCH" -a -d "/usr/lib/$GCC_ARCH" ] + then + MULTIARCH_SUBDIR="lib/$GCC_ARCH" + elif [ -d "/usr/lib64" ] + then + # Useful for Fedora systems + MULTIARCH_SUBDIR="lib64" + fi fi if [ "$IDN_LIBRARY" = "icu" ] @@ -355,17 +524,14 @@ then IDNA_LIBS="-l$IDN_LIB" fi +if [ -f config.unix ]; then + rm -f config.unix +fi + OPENSSL_LIBS="-l$OPENSSL_LIB" -echo -n "Checking Lua includes... " -lua_h="$LUA_INCDIR/lua.h" -if [ -f "$lua_h" ] -then - echo "lua.h found in $lua_h" -else - echo "lua.h not found (looked in $lua_h)" - echo "You may want to use the flag --with-lua-include. See --help." - exit 1 +if [ "$PRNG" = "OPENSSL" ]; then + PRNGLIBS=$OPENSSL_LIBS fi # Write config @@ -373,19 +539,23 @@ fi echo "Writing configuration..." echo +rm -f built cat < config.unix # This file was automatically generated by the configure script. # Run "./configure --help" for details. +LUA_VERSION=$LUA_VERSION PREFIX=$PREFIX SYSCONFDIR=$SYSCONFDIR LIBDIR=$LIBDIR DATADIR=$DATADIR LUA_SUFFIX=$LUA_SUFFIX LUA_DIR=$LUA_DIR +LUA_DIR_SET=$LUA_DIR_SET LUA_INCDIR=$LUA_INCDIR LUA_LIBDIR=$LUA_LIBDIR LUA_BINDIR=$LUA_BINDIR +MULTIARCH_SUBDIR=$MULTIARCH_SUBDIR REQUIRE_CONFIG=$REQUIRE_CONFIG IDN_LIB=$IDN_LIB IDNA_LIBS=$IDNA_LIBS -- cgit v1.2.3 From c0937dcdb42f9ac2fc928aa91f1474607b735590 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 23:01:12 +0100 Subject: configure: Set RUNWITH to lua + lua-suffix unless --runwith is given (fixes #721, #777) --- configure | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/configure b/configure index bd4462ed..c416709d 100755 --- a/configure +++ b/configure @@ -170,7 +170,6 @@ do LUA_SUFFIX="5.1"; LUA_SUFFIX_SET=yes fi - RUNWITH="lua$LUA_SUFFIX" LUA_INCDIR="/usr/include/lua$LUA_SUFFIX" LUA_INCDIR_SET=yes CFLAGS="$CFLAGS -ggdb" @@ -207,7 +206,6 @@ do LUA_INCDIR_SET="yes" fi if [ "$OSTYPE" = "netbsd" ]; then - RUNWITH="lua5.1" LUA_INCDIR="/usr/pkg/include/lua-5.1" LUA_INCDIR_SET=yes LUA_LIBDIR="/usr/pkg/lib/lua/5.1" @@ -308,6 +306,7 @@ do ;; --runwith) RUNWITH="$value" + RUNWITH_SET=yes ;; --no-example-certs) EXCERTS= @@ -528,6 +527,10 @@ if [ -f config.unix ]; then rm -f config.unix fi +if [ "$RUNWITH_SET" != yes ]; then + RUNWITH="lua$LUA_SUFFIX" +fi + OPENSSL_LIBS="-l$OPENSSL_LIB" if [ "$PRNG" = "OPENSSL" ]; then -- cgit v1.2.3