mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
lib, lua: Fix usage of strerror_r
$ ./run guestfish -vx add-drive foo "readonly:true" libguestfs: trace: set_pgroup true libguestfs: trace: set_pgroup = 0 libguestfs: trace: add_drive "foo" "readonly:true" libguestfs: error: foo: libguestfs: trace: add_drive = -1 (error) libguestfs: trace: close libguestfs: closing guestfs handle 0x55c0bacf12a0 (state 0) Fix the usage of strerror_r by using the new wrapper defined in libguestfs-common. A similar fix is made in the Lua bindings. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2030396 Reported-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
2
common
2
common
Submodule common updated: a405dc599e...9ec7cd8e23
@@ -164,10 +164,9 @@ guestfs_int_lua_create (lua_State *L)
|
||||
return luaL_error (L, \"Guestfs.create: too many arguments\");
|
||||
|
||||
g = guestfs_create_flags (flags);
|
||||
if (!g) {
|
||||
ignore_value (strerror_r (errno, err, sizeof err));
|
||||
return luaL_error (L, \"Guestfs.create: cannot create handle: %%s\", err);
|
||||
}
|
||||
if (!g)
|
||||
return luaL_error (L, \"Guestfs.create: cannot create handle: %%s\",
|
||||
guestfs_int_strerror (errno, err, sizeof err));
|
||||
|
||||
guestfs_set_error_handler (g, NULL, NULL);
|
||||
|
||||
@@ -243,10 +242,9 @@ error__tostring (lua_State *L)
|
||||
lua_gettable (L, 1);
|
||||
msg = luaL_checkstring (L, -1);
|
||||
|
||||
if (code) {
|
||||
ignore_value (strerror_r (code, err, sizeof err));
|
||||
lua_pushfstring (L, \"%%s: %%s\", msg, err);
|
||||
}
|
||||
if (code)
|
||||
lua_pushfstring (L, \"%%s: %%s\", msg,
|
||||
guestfs_int_strerror (code, err, sizeof err));
|
||||
else
|
||||
lua_pushstring (L, msg);
|
||||
|
||||
@@ -655,8 +653,8 @@ get_string_list (lua_State *L, int index)
|
||||
|
||||
strs = malloc ((len+1) * sizeof (char *));
|
||||
if (strs == NULL) {
|
||||
ignore_value (strerror_r (errno, err, sizeof err));
|
||||
luaL_error (L, \"get_string_list: malloc failed: %%s\", err);
|
||||
luaL_error (L, \"get_string_list: malloc failed: %%s\",
|
||||
guestfs_int_strerror (errno, err, sizeof err));
|
||||
/*NOTREACHED*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -322,6 +322,7 @@ guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
|
||||
const int errnum = errno;
|
||||
int err;
|
||||
char buf[256];
|
||||
const char *errstr;
|
||||
struct error_data *error_data = get_error_data (g);
|
||||
|
||||
va_start (args, fs);
|
||||
@@ -330,11 +331,11 @@ guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
|
||||
|
||||
if (err < 0) return;
|
||||
|
||||
ignore_value (strerror_r (errnum, buf, sizeof buf));
|
||||
errstr = guestfs_int_strerror (errnum, buf, sizeof buf);
|
||||
|
||||
msg = safe_realloc (g, msg, strlen (msg) + 2 + strlen (buf) + 1);
|
||||
msg = safe_realloc (g, msg, strlen (msg) + 2 + strlen (errstr) + 1);
|
||||
strcat (msg, ": ");
|
||||
strcat (msg, buf);
|
||||
strcat (msg, errstr);
|
||||
|
||||
/* set_last_error first so that the callback can access the error
|
||||
* message and errno through the handle if it wishes.
|
||||
|
||||
Reference in New Issue
Block a user