Re: [PATCH 12/22] perf daemon: Allow only one daemon over base directory

From: Jiri Olsa
Date: Tue Jan 19 2021 - 17:05:54 EST


On Tue, Jan 19, 2021 at 02:37:42PM +0900, Namhyung Kim wrote:

SNIP

> >
> > +static int check_lock(struct daemon *daemon)
> > +{
> > + char path[PATH_MAX];
> > + char buf[20];
> > + int fd, pid;
> > + ssize_t len;
> > +
> > + scnprintf(path, sizeof(path), "%s/lock", daemon->base);
> > +
> > + fd = open(path, O_RDWR|O_CREAT|O_CLOEXEC, 0640);
> > + if (fd < 0)
> > + return -1;
> > +
> > + if (lockf(fd, F_TLOCK, 0) < 0) {
> > + filename__read_int(path, &pid);
> > + fprintf(stderr, "failed: another perf daemon (pid %d) owns %s\n",
> > + pid, daemon->base);
> > + return -1;
> > + }
>
> So the fd is (a kind of) leaked and the lock is released only when
> the daemon is going to die, right?

yes, that's the idea, I'll put it in some comment

thanks,
jirka