qemu-cr16/qga
Michael Tokarev bba249a256 qga: use access(2) to check for command existance instead of questionable stat(2)
The code checks existance of a command (halt/poweroff/reboot) by using
stat(2) and immediately checking for S_ISLNK() on the returned stat
struct.  This check will never be true, because stat(2) always follows
symbolic links and hence will either return ENOENT (in case of dangling
symlink) or the properties for the final target file.  It is lstat(2)
which might return information about the symlink itself.  However, even
there, we want to check the final file properties, not the first symlink.

This check - S_ISLNK - is harmful but useless in this case.  However, it
is confusing and it helps the wrong usage of stat(2) to spread, so it is
better to remove it.

Additionally, the code would better to check for the executable bits
of the final file, not check if it's a regular file - it's sort of
dubious to have anything but regular files in /sbin/.

But a POSIX system provides another command which suits the purpose
perfectly: it is access(2).  And it is so simple that it's not
necessary to create a separate function when usin it.

Replace stat(2) with access(X_OK) to check for file existance in
qga/commands-posix.c

Fixes: c5b4afd4d5 "qga: Support guest shutdown of BusyBox-based systems"
Reviewed-by: Rodrigo Dias Correa <r@drigo.nl>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2025-11-21 15:47:58 +03:00
..
installer qga/installer: Remove QGA VSS if QGA installation failed 2025-09-01 14:02:18 +03:00
vss-win32 qga-vss: Write hex value of error in log 2025-09-01 14:02:18 +03:00
channel-posix.c util: drop qemu_socket_set_nonblock() 2025-09-19 12:46:07 +01:00
channel-win32.c qga: Add spaces around operator 2021-03-16 20:20:37 -05:00
channel.h qga: add systemd socket activation support 2017-03-06 00:54:18 -06:00
commands-bsd.c error: Drop superfluous #include "qapi/qmp/qerror.h" 2024-10-18 15:03:35 +02:00
commands-common-ssh.c qga: Refactor common SSH functions 2024-05-01 10:35:45 +03:00
commands-common-ssh.h qga: Refactor common SSH functions 2024-05-01 10:35:45 +03:00
commands-common.h qga: move CONFIG_FSFREEZE/TRIM to be meson defined options 2024-07-19 11:50:35 +03:00
commands-linux.c qga: Fix ubsan warning 2025-09-01 14:02:18 +03:00
commands-posix-ssh.c Remove glib compatibility code that is not required anymore 2024-05-14 12:46:39 +02:00
commands-posix.c qga: use access(2) to check for command existance instead of questionable stat(2) 2025-11-21 15:47:58 +03:00
commands-win32.c qga: Improve Windows filesystem space info retrieval logic 2025-10-30 14:52:17 +02:00
commands-windows-ssh.c qga: fix -Wsometimes-uninitialized windows warning 2024-11-04 14:16:14 +02:00
commands-windows-ssh.h qga: Implement SSH commands for Windows 2024-05-01 10:35:45 +03:00
commands.c qga: Fix truncated output handling in guest-exec status reporting 2025-09-01 14:02:18 +03:00
cutils.c qga: Clean up includes 2023-02-08 07:16:23 +01:00
cutils.h qga: Clean up includes 2023-02-08 07:16:23 +01:00
guest-agent-command-state.c qga: use local path for local headers 2018-06-01 19:20:38 +03:00
guest-agent-core.h qga-win: implement a 'guest-get-load' command 2025-06-12 17:02:05 +03:00
main.c qga: ignore channel_init() fail if 'retry_path' is set 2025-09-01 14:02:18 +03:00
meson.build qga-win: implement a 'guest-get-load' command 2025-06-12 17:02:05 +03:00
messages-win32.mc qga-win: add logging to Windows event log 2022-12-20 15:54:41 +02:00
qapi-schema.json qga/qapi-schema: Clean up whitespace between definitions 2025-11-04 13:34:42 +01:00
service-win32.c qga: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
service-win32.h qga-win: changing --retry-path option behavior 2018-10-31 09:04:20 -05:00
vss-win32.c qga: fix potentially not initialized nr_volumes in qga_vss_fsfreeze() 2025-09-01 14:02:18 +03:00
vss-win32.h qga-win: add support for qmp_guest_fsfreeze_freeze_list 2018-10-30 16:48:49 -05:00