Merge 0.10->trunk
[prosody.git] / util-src / pposix.c
index 5288b08cd03217e8c86db35cfa0c16a20027817c..b48465d3a75461bd6a9ee216fbace132d81e647c 100644 (file)
@@ -35,8 +35,8 @@
 #include "lualib.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 #include <fcntl.h>
 #define WITH_MALLINFO
 #endif
 
+#if defined(RFPROC) && defined(EV_SET)
+/*
+ * On *BSD, calling fork() is equivalent to rfork(RFPROC | RFFDG).
+ *
+ * RFFDG being set means that the file descriptor table is copied,
+ * otherwise it's shared. We want the later, otherwise libevent gets
+ * messed up.
+ *
+ * See issue #412
+ */
+#define fork() rfork(RFPROC)
+#endif
+
 /* Daemonization support */
 
 static int lc_daemonize(lua_State* L) {
@@ -642,6 +655,10 @@ 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
+       lua_pushstring(L, uname_info.domainname);
+       lua_setfield(L, -2, "domainname");
+#endif
        return 1;
 }
 
@@ -803,7 +820,7 @@ int luaopen_util_pposix(lua_State* L) {
        };
 
        lua_newtable(L);
-       luaL_register(L, NULL,  exports);
+       luaL_setfuncs(L, exports, 0);
 
        lua_pushliteral(L, "pposix");
        lua_setfield(L, -2, "_NAME");