From ce09b670c592b31a5eef64cff785869a26ddc55f Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Fri, 14 Jun 2019 22:40:28 +0200 Subject: [PATCH] - luaserver: use LUAPLUGINDIR_VAR Signed-off-by: Thilo Graf --- src/system/luaserver.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/system/luaserver.cpp b/src/system/luaserver.cpp index 6814ab0fb..cdf47ec71 100644 --- a/src/system/luaserver.cpp +++ b/src/system/luaserver.cpp @@ -235,16 +235,26 @@ bool CLuaServer::luaserver_parse_command(CBasicMessage::Header &rmsg __attribute std::string luascript; if (data[0] == '/') luascript = data; - else { - luascript = LUAPLUGINDIR "/"; - luascript += data; - luascript += ".lua"; + const char * path[2] = { LUAPLUGINDIR_VAR, LUAPLUGINDIR }; + for (unsigned int i = 0; i < 2; i++) + { + std::string filename = path[i]; + filename += "/"; + filename += data; + filename += ".lua"; + if (access(filename, R_OK) == 0) + { + luascript = filename; + break; + } } - if (access(luascript, R_OK)) { - fprintf(stderr, "%s %s %d: %s not found\n", __file__, __func__, __LINE__, luascript.c_str()); + if (access(luascript, R_OK) != 0) + { + fprintf(stderr, "%s %s %d: %s not found\n", __file__, __func__, __LINE__, data); const char *result_code = "-1"; const char *result_string = ""; - std::string error_string = luascript + " not found\n"; + std::string error_string = data; + error_string += " not found\n"; size_t result_code_len = strlen(result_code) + 1; size_t result_string_len = strlen(result_string) + 1; size_t error_string_len = error_string.size() + 1;