[PATCH] qga: fix uname() return value check in guest-get-osinfo

Brad Smith posted 1 patch 3 weeks, 2 days ago
Maintainers: Michael Roth <michael.roth@amd.com>, Kostiantyn Kostiuk <kkostiuk@redhat.com>
qga/commands-posix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] qga: fix uname() return value check in guest-get-osinfo
Posted by Brad Smith 3 weeks, 2 days ago
qga: fix uname() return value check in guest-get-osinfo

POSIX only specifies that uname() returns a non-negative value on
success. Solaris returns 1, so guest-get-osinfo treated every
successful call as a failure and reported a stale errno.

Check for a negative return value instead, as linux-user/uname.c
already does.

Signed-off-by: Brad Smith <brad@comstyle.com>
---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index dcc683f6c9..23abaf1956 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 
     info = g_new0(GuestOSInfo, 1);
 
-    if (uname(&kinfo) != 0) {
+    if (uname(&kinfo) < 0) {
         error_setg_errno(errp, errno, "uname failed");
     } else {
         info->kernel_version = g_strdup(kinfo.version);
-- 
2.56.0
Re: [PATCH] qga: fix uname() return value check in guest-get-osinfo
Posted by Philippe Mathieu-Daudé 6 days, 5 hours ago
On 31/10/26 00:07, Brad Smith wrote:
> qga: fix uname() return value check in guest-get-osinfo
> 
> POSIX only specifies that uname() returns a non-negative value on
> success. Solaris returns 1, so guest-get-osinfo treated every
> successful call as a failure and reported a stale errno.
> 
> Check for a negative return value instead, as linux-user/uname.c
> already does.
> 
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
>   qga/commands-posix.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

Re: [PATCH] qga: fix uname() return value check in guest-get-osinfo
Posted by Brad Smith 1 week, 3 days ago
On 2026-10-30 7:07 p.m., Brad Smith wrote:
> qga: fix uname() return value check in guest-get-osinfo
>
> POSIX only specifies that uname() returns a non-negative value on
> success. Solaris returns 1, so guest-get-osinfo treated every
> successful call as a failure and reported a stale errno.
>
> Check for a negative return value instead, as linux-user/uname.c
> already does.

ping. It would be good to get this into 11.2.

> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
>   qga/commands-posix.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index dcc683f6c9..23abaf1956 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
>   
>       info = g_new0(GuestOSInfo, 1);
>   
> -    if (uname(&kinfo) != 0) {
> +    if (uname(&kinfo) < 0) {
>           error_setg_errno(errp, errno, "uname failed");
>       } else {
>           info->kernel_version = g_strdup(kinfo.version);
Re: [PATCH] qga: fix uname() return value check in guest-get-osinfo
Posted by Roman Bogorodskiy 3 weeks, 1 day ago
  Brad Smith wrote:

> qga: fix uname() return value check in guest-get-osinfo
> 
> POSIX only specifies that uname() returns a non-negative value on
> success. Solaris returns 1, so guest-get-osinfo treated every
> successful call as a failure and reported a stale errno.
> 
> Check for a negative return value instead, as linux-user/uname.c
> already does.
> 
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
>  qga/commands-posix.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index dcc683f6c9..23abaf1956 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
>  
>      info = g_new0(GuestOSInfo, 1);
>  
> -    if (uname(&kinfo) != 0) {
> +    if (uname(&kinfo) < 0) {
>          error_setg_errno(errp, errno, "uname failed");
>      } else {
>          info->kernel_version = g_strdup(kinfo.version);
> -- 
> 2.56.0
> 
> 

Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>