[PATCH 3/3] util: Standardize macro usage to check socket family

Julio Faracco posted 3 patches 1 month ago
[PATCH 3/3] util: Standardize macro usage to check socket family
Posted by Julio Faracco 1 month ago
Replace direct socket family comparison with the standard
VIR_SOCKET_ADDR_IS_FAMILY() macro for consistency.

The codebase uses VIR_SOCKET_ADDR_IS_FAMILY() as the standard way
to check socket address families. This patch updates one remaining
instance that was using direct field access
(addr->data.sa.sa_family == AF_UNIX) to use the macro instead.

This improves code consistency and makes the code more maintainable
by centralizing the family checking logic.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/util/virsocketaddr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 80ee3b4c51..c5ac1b360a 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -479,7 +479,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
 
     /* Short-circuit since getnameinfo doesn't work
      * nicely for UNIX sockets */
-    if (addr->data.sa.sa_family == AF_UNIX) {
+    if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_UNIX)) {
         if (withService) {
             addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0",
                                       separator ? separator : ":");
-- 
2.52.0
Re: [PATCH 3/3] util: Standardize macro usage to check socket family
Posted by Ján Tomko via Devel 3 weeks, 2 days ago
On a Monday in 2026, Julio Faracco wrote:
>Replace direct socket family comparison with the standard
>VIR_SOCKET_ADDR_IS_FAMILY() macro for consistency.
>
>The codebase uses VIR_SOCKET_ADDR_IS_FAMILY() as the standard way
>to check socket address families. This patch updates one remaining

There are many more uses left.

>instance that was using direct field access
>(addr->data.sa.sa_family == AF_UNIX) to use the macro instead.
>

>This improves code consistency and makes the code more maintainable
>by centralizing the family checking logic.

This paragraph seems unnecessarily verbose.

Jano

>
>Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
>---
> src/util/virsocketaddr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
>index 80ee3b4c51..c5ac1b360a 100644
>--- a/src/util/virsocketaddr.c
>+++ b/src/util/virsocketaddr.c
>@@ -479,7 +479,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
>
>     /* Short-circuit since getnameinfo doesn't work
>      * nicely for UNIX sockets */
>-    if (addr->data.sa.sa_family == AF_UNIX) {
>+    if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_UNIX)) {
>         if (withService) {
>             addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0",
>                                       separator ? separator : ":");
>-- 
>2.52.0
>
Re: [PATCH 3/3] util: Standardize macro usage to check socket family
Posted by Julio Faracco 3 weeks, 2 days ago
Em sex., 16 de jan. de 2026 às 14:02, Ján Tomko <jtomko@redhat.com> escreveu:
>
> On a Monday in 2026, Julio Faracco wrote:
> >Replace direct socket family comparison with the standard
> >VIR_SOCKET_ADDR_IS_FAMILY() macro for consistency.
> >
> >The codebase uses VIR_SOCKET_ADDR_IS_FAMILY() as the standard way
> >to check socket address families. This patch updates one remaining
>
> There are many more uses left.

Let me fix the text. Maybe I can submit a single patch since the
purpose of this change is just a code clean up in
virSocketAddrFormatWithPrefix.

>
> >instance that was using direct field access
> >(addr->data.sa.sa_family == AF_UNIX) to use the macro instead.
> >
>
> >This improves code consistency and makes the code more maintainable
> >by centralizing the family checking logic.
>
> This paragraph seems unnecessarily verbose.
>
> Jano
>
> >
> >Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> >---
> > src/util/virsocketaddr.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
> >index 80ee3b4c51..c5ac1b360a 100644
> >--- a/src/util/virsocketaddr.c
> >+++ b/src/util/virsocketaddr.c
> >@@ -479,7 +479,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
> >
> >     /* Short-circuit since getnameinfo doesn't work
> >      * nicely for UNIX sockets */
> >-    if (addr->data.sa.sa_family == AF_UNIX) {
> >+    if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_UNIX)) {
> >         if (withService) {
> >             addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0",
> >                                       separator ? separator : ":");
> >--
> >2.52.0
> >