]> git.e2factory.org Git - e2factory.git/commitdiff
On glibc, strerror_r does not do what you think it does...
authorTobias Ulmer <tu@emlix.com>
Fri, 1 Mar 2013 14:18:52 +0000 (15:18 +0100)
committerTobias Ulmer <tu@emlix.com>
Fri, 1 Mar 2013 14:18:52 +0000 (15:18 +0100)
Fixes empty error messages in various places.

glibc will use the GNU version of strerror_r by default, which does not
fill the buffer but rather uses it as a temporary storage space. It
returns a pointer to the error string, which was never used.

Since e2 is not multithreaded, replace it with the simpler strerror()
and remove pointless casts.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2util.c

index 08bd2b88852bff485943cdd2732a0a88bc9a3d07..576389476fadeed81c795619397967ead61021b5 100644 (file)
@@ -66,7 +66,7 @@ lua_fork(lua_State *lua)
 
        if(rc < 0) {
                lua_pushnil(lua);
-               lua_pushstring(lua, (char *)strerror(errno));
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }
 
@@ -164,10 +164,8 @@ get_file_statistics(lua_State *lua)
        }
 
        if (s < 0) {
-               char buf[256];
-               strerror_r(errno, buf, sizeof(buf));
                lua_pushnil(lua);
-               lua_pushstring(lua, buf);
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }
 
@@ -339,10 +337,8 @@ change_directory(lua_State *lua)
        const char *ptr = luaL_checkstring(lua, 1);
        rc = chdir(ptr);
        if (rc < 0) {
-               char buf[256];
-               strerror_r(errno, buf, sizeof(buf));
                lua_pushboolean(lua, 0);
-               lua_pushstring(lua, buf);
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }
        lua_pushboolean(lua, 1);
@@ -455,7 +451,7 @@ run_pipe(lua_State *lua)
 
 fail:
        lua_pushnil(lua);
-       lua_pushstring(lua, (char *)strerror(errno));
+       lua_pushstring(lua, strerror(errno));
        return 2;
 }
 
@@ -474,7 +470,7 @@ process_wait(lua_State *lua)
        rc = waitpid(pid, &status, 0);
        if (rc < 0) {
                lua_pushnil(lua);
-               lua_pushstring(lua, (char *)strerror(errno));
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }
        lua_pushnumber(lua, WEXITSTATUS(status));
@@ -503,7 +499,7 @@ read_fd(lua_State *lua)
 
        if (m < 0) {
                lua_pushnil(lua);
-               lua_pushstring(lua, (char *)strerror(errno));
+               lua_pushstring(lua, strerror(errno));
                free(buf);
                return 2;
        }
@@ -534,7 +530,7 @@ write_fd(lua_State *lua)
 
        if (m < 0) {
                lua_pushnil(lua);
-               lua_pushstring(lua, (char *)strerror(errno));
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }
 
@@ -557,7 +553,7 @@ close_fd(lua_State *lua)
 
        if (close(fd) < 0) {
                lua_pushnil(lua);
-               lua_pushstring(lua, (char *)strerror(errno));
+               lua_pushstring(lua, strerror(errno));
                return 2;
        }