On Mon, Mar 15, 2021 at 10:12:13PM +0100, Klemens Nanni wrote:
> On Mon, Mar 15, 2021 at 09:08:27PM +0100, Klemens Nanni wrote:
> > On Mon, Mar 15, 2021 at 07:43:44PM +0100, Sebastien Marie wrote:
> > > On program exit, I have the following:
> > > 
> > >  40924 apmd     CALL  lstat(0xfb8715af2f0,0x7f7ffffc01d0)
> > >  40924 apmd     NAMI  "/var/run/apmdev"
> > >  40924 apmd     RET   lstat -1 errno 2 No such file or directory
> > > 
> > > apmd is trying to remove the socket on exit:
> > > - via atexit(sockunlink), registered in bind_socket() function
> > > - via signal catch (see sigexit() function)
> > > 
> > > but the socket isn't unveiled.
> > Thanks, I should've have seen seen this.
> > 
> > As for other daemons like relayd, we can skip unlinking the socket upon
> > exit and leave everything to the next apmd starting up which takes care
> > of removal and owner/mode in bind_socket().
> > 
> > Feedback? OK?
> socketname[] is now unused, so remove that as well (thanks mestre).

ok semarie@

I wonder if more "modernization" could be done here (in a different commit):
- use fchmod/fchown instead of chmod/chown
- use unlink(2) directly instead of remove(3) (we know we are removing a file 
and not a directory)
- maybe remove signal(3) calls to sigexit (as it is only _exit(1) now - but it 
slightly modifies the exit code)

Thanks.

> Index: apmd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
> retrieving revision 1.100
> diff -u -p -r1.100 apmd.c
> --- apmd.c    11 Mar 2021 18:12:41 -0000      1.100
> +++ apmd.c    15 Mar 2021 21:01:28 -0000
> @@ -72,7 +72,6 @@ void resumed(int ctl_fd);
>  void setperfpolicy(char *policy);
>  void sigexit(int signo);
>  void do_etc_file(const char *file);
> -void sockunlink(void);
>  void error(const char *fmt, const char *arg);
>  void set_driver_messages(int fd, int mode);
>  
> @@ -80,7 +79,6 @@ void set_driver_messages(int fd, int mod
>  void
>  sigexit(int signo)
>  {
> -     sockunlink();
>       _exit(1);
>  }
>  
> @@ -204,15 +202,6 @@ power_status(int fd, int force, struct a
>       return acon;
>  }
>  
> -char socketname[PATH_MAX];
> -
> -void
> -sockunlink(void)
> -{
> -     if (socketname[0])
> -             remove(socketname);
> -}
> -
>  int
>  bind_socket(const char *sockname)
>  {
> @@ -238,8 +227,6 @@ bind_socket(const char *sockname)
>               error("cannot set socket mode/owner/group to 660/0/0", NULL);
>  
>       listen(sock, 1);
> -     strlcpy(socketname, sockname, sizeof socketname);
> -     atexit(sockunlink);
>  
>       return sock;
>  }

-- 
Sebastien Marie

Reply via email to