Changeset

8012:e898c8fda986

util.pposix: Remove fallocate
author Kim Alvefur <zash@zash.se>
date Tue, 28 Feb 2017 13:26:05 +0100
parents 8011:f8ba814fe029
children 8013:72cfbe377326
files plugins/mod_posix.lua prosodyctl util-src/pposix.c
diffstat 3 files changed, 3 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_posix.lua	Tue Feb 28 11:33:43 2017 +0100
+++ b/plugins/mod_posix.lua	Tue Feb 28 13:26:05 2017 +0100
@@ -7,7 +7,7 @@
 --
 
 
-local want_pposix_version = "0.3.7";
+local want_pposix_version = "0.4.0";
 
 local pposix = assert(require "util.pposix");
 if pposix._VERSION ~= want_pposix_version then
--- a/prosodyctl	Tue Feb 28 11:33:43 2017 +0100
+++ b/prosodyctl	Tue Feb 28 13:26:05 2017 +0100
@@ -135,7 +135,7 @@
 -- Switch away from root and into the prosody user --
 local switched_user, current_uid;
 
-local want_pposix_version = "0.3.7";
+local want_pposix_version = "0.4.0";
 local ok, pposix = pcall(require, "util.pposix");
 
 if ok and pposix then
--- a/util-src/pposix.c	Tue Feb 28 11:33:43 2017 +0100
+++ b/util-src/pposix.c	Tue Feb 28 13:26:05 2017 +0100
@@ -13,7 +13,7 @@
 * POSIX support functions for Lua
 */
 
-#define MODULE_VERSION "0.3.7"
+#define MODULE_VERSION "0.4.0"
 
 
 #if defined(__linux__)
@@ -730,64 +730,6 @@
 }
 #endif
 
-/* File handle extraction blatantly stolen from
- * https://github.com/rrthomas/luaposix/blob/master/lposix.c#L631
- * */
-
-int lc_fallocate(lua_State *L) {
-	int ret;
-	off_t offset, len;
-	FILE *f = *(FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE);
-
-	if(f == NULL) {
-		return luaL_error(L, "attempt to use a closed file");
-	}
-
-	offset = luaL_checkinteger(L, 2);
-	len = luaL_checkinteger(L, 3);
-
-#if defined(__linux__)
-	errno = 0;
-	ret = fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len);
-
-	if(ret == 0) {
-		lua_pushboolean(L, 1);
-		return 1;
-	}
-
-	/* Some old versions of Linux apparently use the return value instead of errno */
-	if(errno == 0) {
-		errno = ret;
-	}
-
-	if(errno != ENOSYS && errno != EOPNOTSUPP) {
-		lua_pushnil(L);
-		lua_pushstring(L, strerror(errno));
-		return 2;
-	}
-
-#endif
-
-	ret = posix_fallocate(fileno(f), offset, len);
-
-	if(ret == 0) {
-		lua_pushboolean(L, 1);
-		return 1;
-	} else {
-		lua_pushnil(L);
-		lua_pushstring(L, strerror(ret));
-
-		/* posix_fallocate() can leave a bunch of NULs at the end, so we cut that
-		 * this assumes that offset == length of the file */
-		if(ftruncate(fileno(f), offset) != 0) {
-			lua_pushstring(L, strerror(errno));
-			return 3;
-		}
-
-		return 2;
-	}
-}
-
 /*
  * Append some data to a file handle
  * Attempt to allocate space first
@@ -889,7 +831,6 @@
 		{ "meminfo", lc_meminfo },
 #endif
 
-		{ "fallocate", lc_fallocate },
 		{ "atomic_append", lc_atomic_append },
 
 		{ NULL, NULL }