lkml.org 
[lkml]   [2021]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 12/22] perf daemon: Allow only one daemon over base directory
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

\
 
 \ /
  Last update: 2021-01-19 23:07    [W:0.157 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site