Laszlo Ersek
2023-Feb-15 14:11 UTC
[Libguestfs] [libnbd PATCH v3 03/29] socket activation: rename sa_(tmpdir|sockpath) to sact_(tmpdir|sockpath)
<signal.h> in POSIX reserves the "sa_" prefix: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02 Let's use "sact_" instead. Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- lib/internal.h | 4 ++-- generator/states-connect-socket-activation.c | 16 ++++++++-------- lib/handle.c | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index c5827f4f0037..0b5f793011b8 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -278,8 +278,8 @@ struct nbd_handle { /* When using systemd socket activation, this directory and socket * must be deleted, and the pid above must be killed. */ - char *sa_tmpdir; - char *sa_sockpath; + char *sact_tmpdir; + char *sact_sockpath; /* When connecting to TCP ports, these fields are used. */ char *hostname, *port; diff --git a/generator/states-connect-socket-activation.c b/generator/states-connect-socket-activation.c index 9a83834915db..7138e7638e30 100644 --- a/generator/states-connect-socket-activation.c +++ b/generator/states-connect-socket-activation.c @@ -111,22 +111,22 @@ CONNECT_SA.START: * short enough to store in the sockaddr_un. On some platforms this * may cause problems so we may need to revisit it. XXX */ - h->sa_tmpdir = strdup ("/tmp/libnbdXXXXXX"); - if (h->sa_tmpdir == NULL) { + h->sact_tmpdir = strdup ("/tmp/libnbdXXXXXX"); + if (h->sact_tmpdir == NULL) { SET_NEXT_STATE (%.DEAD); set_error (errno, "strdup"); return 0; } - if (mkdtemp (h->sa_tmpdir) == NULL) { + if (mkdtemp (h->sact_tmpdir) == NULL) { SET_NEXT_STATE (%.DEAD); set_error (errno, "mkdtemp"); /* Avoid cleanup in nbd_close. */ - free (h->sa_tmpdir); - h->sa_tmpdir = NULL; + free (h->sact_tmpdir); + h->sact_tmpdir = NULL; return 0; } - if (asprintf (&h->sa_sockpath, "%s/sock", h->sa_tmpdir) == -1) { + if (asprintf (&h->sact_sockpath, "%s/sock", h->sact_tmpdir) == -1) { SET_NEXT_STATE (%.DEAD); set_error (errno, "strdup"); return 0; @@ -140,10 +140,10 @@ CONNECT_SA.START: } addr.sun_family = AF_UNIX; - memcpy (addr.sun_path, h->sa_sockpath, strlen (h->sa_sockpath) + 1); + memcpy (addr.sun_path, h->sact_sockpath, strlen (h->sact_sockpath) + 1); if (bind (s, (struct sockaddr *) &addr, sizeof addr) == -1) { SET_NEXT_STATE (%.DEAD); - set_error (errno, "bind: %s", h->sa_sockpath); + set_error (errno, "bind: %s", h->sact_sockpath); close (s); return 0; } diff --git a/lib/handle.c b/lib/handle.c index 4a186f8fa946..dfd8c2e5cdb9 100644 --- a/lib/handle.c +++ b/lib/handle.c @@ -141,15 +141,15 @@ nbd_close (struct nbd_handle *h) free_cmd_list (h->cmds_done); string_vector_iter (&h->argv, (void *) free); free (h->argv.ptr); - if (h->sa_sockpath) { + if (h->sact_sockpath) { if (h->pid > 0) kill (h->pid, SIGTERM); - unlink (h->sa_sockpath); - free (h->sa_sockpath); + unlink (h->sact_sockpath); + free (h->sact_sockpath); } - if (h->sa_tmpdir) { - rmdir (h->sa_tmpdir); - free (h->sa_tmpdir); + if (h->sact_tmpdir) { + rmdir (h->sact_tmpdir); + free (h->sact_tmpdir); } free (h->hostname); free (h->port);
Eric Blake
2023-Feb-15 20:00 UTC
[Libguestfs] [libnbd PATCH v3 03/29] socket activation: rename sa_(tmpdir|sockpath) to sact_(tmpdir|sockpath)
On Wed, Feb 15, 2023 at 03:11:32PM +0100, Laszlo Ersek wrote:> <signal.h> in POSIX reserves the "sa_" prefix: > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02 > > Let's use "sact_" instead. > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > lib/internal.h | 4 ++-- > generator/states-connect-socket-activation.c | 16 ++++++++-------- > lib/handle.c | 12 ++++++------ > 3 files changed, 16 insertions(+), 16 deletions(-)Reviewed-by: Eric Blake <eblake at redhat.com> Stepping on reserved names is something that you can often get away with (if you don't conflict now, how likely is it that libc will actually introduce a future symbol that will conflict later?), so this is change is more on the theoretical side. But I have no objections, and as you proved, it's a very easy mechanical fix once we even bother to identify that reserved name clashes could be a potential porting issue. I've probably spent more time writing this email than you did in creating the patch proper (if you exclude the subsequent time testing that it builds and passes 'make check-valgrind'...) Reviewed-by: Eric Blake <eblake at redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Laszlo Ersek
2023-Feb-22 12:24 UTC
[Libguestfs] [libnbd PATCH v3 03/29] socket activation: rename sa_(tmpdir|sockpath) to sact_(tmpdir|sockpath)
On 2/15/23 15:11, Laszlo Ersek wrote:> <signal.h> in POSIX reserves the "sa_" prefix: > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02 > > Let's use "sact_" instead. > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > lib/internal.h | 4 ++-- > generator/states-connect-socket-activation.c | 16 ++++++++-------- > lib/handle.c | 12 ++++++------ > 3 files changed, 16 insertions(+), 16 deletions(-)Commit 86c8056dcab3 ("socket activation: rename sa_(tmpdir|sockpath) to sact_(tmpdir|sockpath)", 2023-02-22).