[vte] all: Replace %m with %s and g_strerror()
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] all: Replace %m with %s and g_strerror()
- Date: Sat, 18 Jul 2020 11:53:58 +0000 (UTC)
commit 79031079146eb82106551f0d92c13dc5d356a1a9
Author: Christian Persch <chpe src gnome org>
Date: Sat Jul 18 13:52:55 2020 +0200
all: Replace %m with %s and g_strerror()
For portability, don't use %m in non-linux code.
Based on a patch by Nia Alarie <nia netbsd org>.
Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/261
src/app/app.cc | 19 ++++++++++-----
src/app/meson.build | 2 +-
src/decoder-cat.cc | 8 +++++--
src/meson.build | 4 ++--
src/parser-cat.cc | 8 +++++--
src/pty.cc | 69 +++++++++++++++++++++++++++++++++++++----------------
src/spawn.cc | 18 ++++++++++----
src/vte.cc | 14 +++++++----
8 files changed, 98 insertions(+), 44 deletions(-)
---
diff --git a/src/app/app.cc b/src/app/app.cc
index 7dcf940f..1ab2dda0 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -267,15 +267,19 @@ private:
if (*end == '=' || fd < 3) {
new_fd = vte::libc::fd_dup_cloexec(fd, 3);
if (new_fd == -1) {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno(errno),
- "Failed to duplicate file descriptor %d: %m", fd);
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno(errsv),
+ "Failed to duplicate file descriptor %d: %s",
+ fd, g_strerror(errsv));
return false;
}
} else {
new_fd = fd;
if (vte::libc::fd_set_cloexec(fd) == -1) {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno(errno),
- "Failed to set cloexec on file descriptor %d: %m", fd);
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno(errsv),
+ "Failed to set cloexec on file descriptor %d: %s",
+ fd, g_strerror(errsv));
return false;
}
}
@@ -1435,9 +1439,12 @@ vteapp_window_fork(VteappWindow* window,
auto pid = fork();
switch (pid) {
- case -1: /* error */
- g_set_error(error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error forking: %m");
+ case -1: { /* error */
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errsv),
+ "Error forking: %s", g_strerror(errsv));
return false;
+ }
case 0: /* child */ {
vte_pty_child_setup(pty);
diff --git a/src/app/meson.build b/src/app/meson.build
index 1bed9160..fcf30aa6 100644
--- a/src/app/meson.build
+++ b/src/app/meson.build
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <https://www.gnu.org/licenses/>.
-app_sources = glib_glue_sources + files(
+app_sources = glib_glue_sources + libc_glue_sources + files(
'app.cc',
)
diff --git a/src/decoder-cat.cc b/src/decoder-cat.cc
index d1d4fc1c..13a6b161 100644
--- a/src/decoder-cat.cc
+++ b/src/decoder-cat.cc
@@ -33,6 +33,7 @@
#include "debug.h"
#include "glib-glue.hh"
+#include "libc-glue.hh"
#include "utf8.hh"
#ifdef WITH_ICU
@@ -422,7 +423,8 @@ private:
for (auto i = 0; i < options.repeat(); ++i) {
if (i > 0 && lseek(fd, 0, SEEK_SET) != 0) {
- g_printerr("Failed to seek: %m\n");
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_printerr("Failed to seek: %s\n", g_strerror(errsv));
return false;
}
@@ -472,7 +474,9 @@ public:
} else {
fd = ::open(filename, O_RDONLY);
if (fd == -1) {
- g_printerr("Error opening file %s: %m\n", filename);
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_printerr("Error opening file %s: %s\n",
+ filename, g_strerror(errsv));
}
}
if (fd != -1) {
diff --git a/src/meson.build b/src/meson.build
index ceba1f68..6162458e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -269,7 +269,7 @@ endif
# decoder cat
-decoder_cat_sources = glib_glue_sources + utf8_sources + debug_sources + files(
+decoder_cat_sources = glib_glue_sources + libc_glue_sources + utf8_sources + debug_sources + files(
'decoder-cat.cc',
)
@@ -288,7 +288,7 @@ decoder_cat = executable(
# parser cat
-parser_cat_sources = glib_glue_sources + parser_sources + utf8_sources + debug_sources + files(
+parser_cat_sources = glib_glue_sources + libc_glue_sources + parser_sources + utf8_sources + debug_sources +
files(
'parser-cat.cc',
)
diff --git a/src/parser-cat.cc b/src/parser-cat.cc
index 083bc58a..5fdb4b7c 100644
--- a/src/parser-cat.cc
+++ b/src/parser-cat.cc
@@ -32,6 +32,7 @@
#include "debug.h"
#include "glib-glue.hh"
+#include "libc-glue.hh"
#include "parser.hh"
#include "parser-glue.hh"
#include "utf8.hh"
@@ -706,7 +707,8 @@ private:
for (auto i = 0; i < repeat; ++i) {
if (i > 0 && lseek(fd, 0, SEEK_SET) != 0) {
- g_printerr("Failed to seek: %m\n");
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_printerr("Failed to seek: %s\n", g_strerror(errsv));
return false;
}
@@ -747,7 +749,9 @@ public:
} else {
fd = open(filename, O_RDONLY);
if (fd == -1) {
- g_printerr("Error opening file %s: %m\n", filename);
+ auto errsv = vte::libc::ErrnoSaver{};
+ g_printerr("Error opening file %s: %s\n",
+ filename, g_strerror(errsv));
}
}
if (fd != -1) {
diff --git a/src/pty.cc b/src/pty.cc
index 7f7958a0..cd33d9f4 100644
--- a/src/pty.cc
+++ b/src/pty.cc
@@ -122,7 +122,9 @@ Pty::get_peer(bool cloexec) const noexcept
if (!peer_fd &&
errno != EINVAL &&
errno != ENOTTY) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ioctl(TIOCGPTPEER)");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "ioctl(TIOCGPTPEER)", g_strerror(errsv));
return -1;
}
@@ -132,7 +134,9 @@ Pty::get_peer(bool cloexec) const noexcept
if (!peer_fd) {
auto const name = ptsname(m_pty_fd.get());
if (name == nullptr) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ptsname");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "ptsname", g_strerror(errsv));
return -1;
}
@@ -142,7 +146,9 @@ Pty::get_peer(bool cloexec) const noexcept
peer_fd = ::open(name, fd_flags);
if (!peer_fd) {
- _vte_debug_print (VTE_DEBUG_PTY, "Failed to open PTY: %m\n");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print (VTE_DEBUG_PTY, "Failed to open PTY: %s\n",
+ g_strerror(errsv));
return -1;
}
}
@@ -180,7 +186,9 @@ Pty::child_setup() const noexcept
sigset_t set;
sigemptyset(&set);
if (pthread_sigmask(SIG_SETMASK, &set, nullptr) == -1) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "pthread_sigmask");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "pthread_sigmask", g_strerror(errsv));
_exit(127);
}
@@ -200,7 +208,9 @@ Pty::child_setup() const noexcept
*/
_vte_debug_print (VTE_DEBUG_PTY, "Starting new session\n");
if (setsid() == -1) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "setsid");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "setsid", g_strerror(errsv));
_exit(127);
}
}
@@ -216,7 +226,9 @@ Pty::child_setup() const noexcept
*/
if (!(m_flags & VTE_PTY_NO_CTTY)) {
if (ioctl(peer_fd, TIOCSCTTY, peer_fd) != 0) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ioctl(TIOCSCTTY)");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "ioctl(TIOCSCTTY)", g_strerror(errsv));
_exit(127);
}
}
@@ -292,7 +304,8 @@ Pty::set_size(int rows,
if (ret != 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "Failed to set size on %d: %m\n", master);
+ "Failed to set size on %d: %s\n",
+ master, g_strerror(errsv));
}
return ret == 0;
@@ -333,7 +346,8 @@ Pty::get_size(int* rows,
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "Failed to read size from fd %d: %m\n", master);
+ "Failed to read size from fd %d: %s\n",
+ master, g_strerror(errsv));
return false;
}
@@ -352,34 +366,39 @@ fd_setup(vte::libc::FD& fd)
{
if (grantpt(fd.get()) != 0) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "grantpt");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "grantpt", g_strerror(errsv));
return -1;
}
if (unlockpt(fd.get()) != 0) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "unlockpt");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "unlockpt", g_strerror(errsv));
return -1;
}
if (vte::libc::fd_set_cloexec(fd.get()) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "Setting CLOEXEC flag", g_strerror(errsv));
+ "%s failed: %s",
+ "Setting CLOEXEC flag", g_strerror(errsv));
return -1;
}
if (vte::libc::fd_set_nonblock(fd.get()) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "Setting O_NONBLOCK flag", g_strerror(errsv));
+ "%s failed: %s",
+ "Setting O_NONBLOCK flag", g_strerror(errsv));
return -1;
}
if (fd_set_cpkt(fd) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "ioctl(TIOCPKT)", g_strerror(errsv));
+ "%s failed: %s",
+ "ioctl(TIOCPKT)", g_strerror(errsv));
return -1;
}
@@ -418,7 +437,8 @@ _vte_pty_open_posix(void)
if (!fd) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "posix_openpt", g_strerror(errsv));
+ "%s failed: %s",
+ "posix_openpt", g_strerror(errsv));
return {};
}
@@ -426,14 +446,16 @@ _vte_pty_open_posix(void)
if (need_cloexec && vte::libc::fd_set_cloexec(fd.get()) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "Setting CLOEXEC flag", g_strerror(errsv));
+ "%s failed: %s",
+ "Setting CLOEXEC flag", g_strerror(errsv));
return {};
}
if (need_nonblocking && vte::libc::fd_set_nonblock(fd.get()) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "Setting NONBLOCK flag", g_strerror(errsv));
+ "%s failed: %s",
+ "Setting NONBLOCK flag", g_strerror(errsv));
return {};
}
#endif /* !linux */
@@ -441,19 +463,22 @@ _vte_pty_open_posix(void)
if (fd_set_cpkt(fd) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
_vte_debug_print(VTE_DEBUG_PTY,
- "%s failed: %s", "ioctl(TIOCPKT)", g_strerror(errsv));
+ "%s failed: %s",
+ "ioctl(TIOCPKT)", g_strerror(errsv));
return {};
}
if (grantpt(fd.get()) != 0) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "grantpt");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "grantpt", g_strerror(errsv));
return {};
}
if (unlockpt(fd.get()) != 0) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "unlockpt");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "unlockpt", g_strerror(errsv));
return {};
}
@@ -494,7 +519,8 @@ Pty::set_utf8(bool utf8) const noexcept
struct termios tio;
if (tcgetattr(fd(), &tio) == -1) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m", "tcgetattr");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s",
+ "tcgetattr", g_strerror(errsv));
return false;
}
@@ -509,7 +535,8 @@ Pty::set_utf8(bool utf8) const noexcept
if (saved_cflag != tio.c_iflag &&
tcsetattr(fd(), TCSANOW, &tio) == -1) {
auto errsv = vte::libc::ErrnoSaver{};
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m", "tcsetattr");
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %d",
+ "tcsetattr", g_strerror(errsv));
return false;
}
#endif
diff --git a/src/spawn.cc b/src/spawn.cc
index 34e7e332..7bc5d8c5 100644
--- a/src/spawn.cc
+++ b/src/spawn.cc
@@ -108,7 +108,8 @@ read_ints(int fd,
if (vte::libc::fd_set_nonblock(fd) < 0) {
auto errsv = vte::libc::ErrnoSaver{};
error.set(G_IO_ERROR, g_io_error_from_errno(errsv),
- _("Failed to set pipe nonblocking: %s"), g_strerror(errsv));
+ _("Failed to set pipe nonblocking: %s"),
+ g_strerror(errsv));
return false;
}
@@ -152,7 +153,8 @@ read_ints(int fd,
if (r < 0) {
auto errsv = vte::libc::ErrnoSaver{};
error.set(G_IO_ERROR, g_io_error_from_errno(errsv),
- _("poll error: %s"), g_strerror(errsv));
+ _("poll error: %s"),
+ g_strerror(errsv));
return false;
}
if (r == 0) {
@@ -326,7 +328,9 @@ SpawnContext::exec(vte::libc::FD& child_report_error_pipe_write,
sigset_t set;
sigemptyset(&set);
if (pthread_sigmask(SIG_SETMASK, &set, nullptr) == -1) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "pthread_sigmask");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "pthread_sigmask", g_strerror(errsv));
return ExecError::SIGMASK;
}
@@ -368,7 +372,9 @@ SpawnContext::exec(vte::libc::FD& child_report_error_pipe_write,
*/
_vte_debug_print(VTE_DEBUG_PTY, "Starting new session\n");
if (setsid() == -1) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "setsid");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "setsid", g_strerror(errsv));
return ExecError::SETSID;
}
}
@@ -384,7 +390,9 @@ SpawnContext::exec(vte::libc::FD& child_report_error_pipe_write,
*/
if (!(pty()->flags() & VTE_PTY_NO_CTTY)) {
if (ioctl(peer_fd, TIOCSCTTY, peer_fd) != 0) {
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ioctl(TIOCSCTTY)");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %s\n",
+ "ioctl(TIOCSCTTY)", g_strerror(errsv));
return ExecError::SCTTY;
}
}
diff --git a/src/vte.cc b/src/vte.cc
index e6545ca7..829e6630 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4045,7 +4045,9 @@ out:
case EBUSY: /* do nothing */
break;
default:
- _vte_debug_print (VTE_DEBUG_IO, "Error reading from child: %m");
+ auto errsv = vte::libc::ErrnoSaver{};
+ _vte_debug_print (VTE_DEBUG_IO, "Error reading from child: %s",
+ g_strerror(errsv));
break;
}
@@ -7570,8 +7572,9 @@ Terminal::set_size(long columns,
if (!pty()->set_size(rows,
columns,
m_cell_height,
- m_cell_width))
- g_warning("Failed to set PTY size: %m\n");
+ m_cell_width)) {
+ // nothing we can do here
+ }
refresh_size();
} else {
m_row_count = rows;
@@ -9958,8 +9961,9 @@ Terminal::set_pty(vte::base::Pty *new_pty)
set_size(m_column_count, m_row_count);
- if (!pty()->set_utf8(data_syntax() == DataSyntax::eECMA48_UTF8))
- g_warning ("Failed to set UTF8 mode: %m\n");
+ if (!pty()->set_utf8(data_syntax() == DataSyntax::eECMA48_UTF8)) {
+ // nothing we can do here
+ }
/* Open channels to listen for input on. */
connect_pty_read();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]