diff --git a/awesome.c b/awesome.c index 16d94f77..373306c0 100644 --- a/awesome.c +++ b/awesome.c @@ -333,6 +333,7 @@ main(int argc, char **argv) xcolor_init_request_t colors_reqs[2]; xcb_get_modifier_mapping_cookie_t xmapping_cookie; ssize_t cmdlen = 1; + xdgHandle xdg; static struct option long_options[] = { { "help", 0, NULL, 'h' }, @@ -370,8 +371,11 @@ main(int argc, char **argv) /* Text won't be printed correctly otherwise */ setlocale(LC_CTYPE, ""); + /* Get XDG basedir data */ + xdg = xdgAllocHandle(); + /* init lua */ - luaA_init(); + luaA_init(xdg); /* check args */ while((opt = getopt_long(argc, argv, "vhkc:", @@ -385,7 +389,7 @@ main(int argc, char **argv) exit_help(EXIT_SUCCESS); break; case 'k': - if(!luaA_parserc(confpath, false)) + if(!luaA_parserc(xdg, confpath, false)) { fprintf(stderr, "✘ Configuration file syntax error.\n"); return EXIT_FAILURE; @@ -522,7 +526,9 @@ main(int argc, char **argv) } /* Parse and run configuration file */ - luaA_parserc(confpath, true); + luaA_parserc(xdg, confpath, true); + + xdgFreeHandle(xdg); /* scan existing windows */ scan(); diff --git a/luaa.c b/luaa.c index 3b9a9746..2e8870cf 100644 --- a/luaa.c +++ b/luaa.c @@ -723,9 +723,10 @@ luaA_awesome_newindex(lua_State *L) } /** Initialize the Lua VM + * \param xdg An xdg handle to use to get XDG basedir. */ void -luaA_init(void) +luaA_init(xdgHandle xdg) { lua_State *L; static const struct luaL_reg awesome_lib[] = @@ -822,8 +823,6 @@ luaA_init(void) globalconf.hooks.dbus = LUA_REFNIL; #endif - xdgHandle xdg = xdgAllocHandle(); - /* add Lua lib path (/usr/share/awesome/lib by default) */ luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?.lua\""); luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?/init.lua\""); @@ -838,8 +837,6 @@ luaA_init(void) luaA_dostring(L, buf); p_delete(&buf); } - - xdgFreeHandle(xdg); } static bool @@ -868,16 +865,16 @@ luaA_loadrc(const char *confpath, bool run) } /** Load a configuration file. + * \param xdg An xdg handle to use to get XDG basedir. * \param confpatharg The configuration file to load. * \param run Run the configuration file. */ bool -luaA_parserc(const char *confpatharg, bool run) +luaA_parserc(xdgHandle xdg, const char *confpatharg, bool run) { int screen; char *confpath = NULL; bool ret = false; - xdgHandle xdg = NULL; /* try to load, return if it's ok */ if(confpatharg) @@ -891,8 +888,6 @@ luaA_parserc(const char *confpatharg, bool run) goto bailout; } - xdg = xdgAllocHandle(); - confpath = xdgConfigFind("awesome/rc.lua", xdg); char *tmp = confpath; @@ -914,9 +909,6 @@ bailout: p_delete(&confpath); - if(xdg) - xdgFreeHandle(xdg); - /* Assure there's at least one tag */ for(screen = 0; screen < globalconf.nscreen; screen++) if(!globalconf.screens[screen].tags.len) diff --git a/luaa.h b/luaa.h index e4ddd125..1b3dfd60 100644 --- a/luaa.h +++ b/luaa.h @@ -27,6 +27,8 @@ #include #include +#include + #include #include "draw.h" @@ -381,8 +383,8 @@ luaA_pushpadding(lua_State *L, padding_t *padding) return 1; } -void luaA_init(void); -bool luaA_parserc(const char *, bool); +void luaA_init(xdgHandle); +bool luaA_parserc(xdgHandle, const char *, bool); void luaA_cs_init(void); void luaA_cs_cleanup(void); void luaA_on_timer(EV_P_ ev_timer *, int);