[PATCH]: unlink legacy unix socket when unit starts

Scott van Kalken scottvankalken at gmail.com
Mon Apr 25 06:38:41 UTC 2022


What if it were a command line option to delete on start? This way you
preserve the existing behaviour while introducing the desired behaviour.
It’s up to the user / admin to decide if they want to “force delete” as an
example.



On Mon, 25 Apr 2022 at 4:33 pm, <shanlei at asiainfo.com> wrote:

> I know the concern, that if we misconfigure the socket file, other file
> may be deleted accidentally.
> But if the program wont delete the file, bind will fail , that means we
> have to delete the file manually before every start. that not a good
> option to maintain a system.
>
> 在 2022-04-24 18:05,Александр Поволоцкий wrote:
> > Unlink socket that can be in use? I think it's not a good idea.
> >
> > On 24.04.2022 12:25, shanlei at asiainfo.com wrote:
> >>
> >> hello,guys,
> >>
> >> We found if we add a unix socket listener, the file was left in disk
> >> when unit got shutdown.
> >> If the unit starts again and load configuration from its state folder,
> >> it would fail with error msg "file exists",
> >> so We think the proper process is to "delete the legacy unix socket
> >> before start", and we present following patch:
> >>
> >>
> >> # HG changeset patch
> >> # User stdanley <shanlei at asiainfo.com>
> >> # Date 1650792235 -28800
> >> #      Sun Apr 24 17:23:55 2022 +0800
> >> # Node ID 29738840c393f12c7d7aa8f3959ed1655b39cd4d
> >> # Parent  8e06a879600e83af11345d023c53c2ca445cf82c
> >> unlink legacy unix socket file before binding.
> >>
> >> diff -r 8e06a879600e -r 29738840c393 src/nxt_main_process.c
> >> --- a/src/nxt_main_process.c    Tue Apr 12 04:16:00 2022 +0100
> >> +++ b/src/nxt_main_process.c    Sun Apr 24 17:23:55 2022 +0800
> >> @@ -1142,6 +1142,15 @@
> >>      }
> >>
> >>  #endif
> >> +#if (NXT_HAVE_UNIX_DOMAIN)
> >> +
> >> +    if (sa->u.sockaddr.sa_family == AF_UNIX
> >> +        && sa->type == SOCK_STREAM
> >> +        && sa->u.sockaddr_un.sun_path[0] != '\0') {
> >> +
> >> +        (void) unlink(sa->u.sockaddr_un.sun_path);
> >> +}
> >> +#endif
> >>
> >>      if (bind(s, &sa->u.sockaddr, sa->socklen) != 0) {
> >>          err = nxt_errno;
> >> _______________________________________________
> >> unit mailing list -- unit at nginx.org
> >> To unsubscribe send an email to unit-leave at nginx.org
> > _______________________________________________
> > unit mailing list -- unit at nginx.org
> > To unsubscribe send an email to unit-leave at nginx.org
> _______________________________________________
> unit mailing list -- unit at nginx.org
> To unsubscribe send an email to unit-leave at nginx.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20220425/bc19655b/attachment.htm>


More information about the unit mailing list