Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3108040pxb; Tue, 19 Jan 2021 14:07:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2X4+Y3cE5dxQE4AX7wZ+PKV1Jt1lpQz8S8KXkhtS5jUIOg+5rbBk9ltbQdMdXiqloFiHc X-Received: by 2002:a17:906:653:: with SMTP id t19mr4288674ejb.44.1611094053862; Tue, 19 Jan 2021 14:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611094053; cv=none; d=google.com; s=arc-20160816; b=XT7t9lqrOrc6riX0kA2BL77csxKoaQ0H46bBvcfCjgWJc4S9JDbPQWTU94yKxd5EkN LUlI48KaypTu+TrTxZ6CnbUKAPThNh//2E1sw6NjfnXJFcAxeQlQrx7tkbViksli40TI BxklxFLfbvH51hw1AG4yPIhTTi66w5WmKzfeaiNRwNwVByE1TaZHz8UeIhAuG3dBwvtf 2ezlw4dYeIGXEkotsi9q6ge2ZDsYcSXH/KbNO8XLAnikXmxmTfO6YQkBQRtpmKFNFElc s9sVKiTVOuJFCTDD4Yrf1aTRzdra9AIVY6lTjiCVzZ1piwaqqLBHtjJYTZEdVpDPlhXV 4T+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oTjNMHeboundc5h9sRP2B5BdgMsx/d+tmyfkTkd8wsU=; b=rNnRQ+uDF6VTSKs3v8iivL5c6zTtGR0w4He2dJCSNqVLgUPD/hIs7xTnOWpEugC4Qx gGxeOaPJjHdOxCQ+XCIrtMYn8YCGDLRmPFOaYqEvCV3UDfOLN64W0WaRz54EJlStDE3M 0HCCa9TJr8avfKE5GtHuAr/RRX/LHI4E1rnwfPub9R/et220r+IG0vplA5pKNoUlvmzK X7HetwuL1Qp0phr6+1SGKv2DMD3PXeQkXhhjXxYw2Z5uOMPG2PhBGSBcctjd+rwXCLt5 OPX9PkirSI8D0Z/CpmBL8ehdsFx79CBt6OBfwZVWoRn6k4LPqlyQDB1qy7BGg4rwoEvw mILg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=exfatGQ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si7934ejh.685.2021.01.19.14.07.07; Tue, 19 Jan 2021 14:07:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=exfatGQ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728438AbhASWF0 (ORCPT + 99 others); Tue, 19 Jan 2021 17:05:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56424 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389055AbhASRqe (ORCPT ); Tue, 19 Jan 2021 12:46:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611078281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oTjNMHeboundc5h9sRP2B5BdgMsx/d+tmyfkTkd8wsU=; b=exfatGQ7XvfeE28IeVjuie48ot+X6omSQzq3HkbL+RO9sSMA/DUwyxaKW5MIFbseclq5Mf XWMS02Adi4aPIpCUnyy68AH8K0dugAdxyOuRUCaPkLPggZsQRFalWaVLE7hrdOUqVCog6x DIFkK3N8MM5l+7vpiRBold34ZLqxzCw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-tX1BP-R4NNOvL8narF7lng-1; Tue, 19 Jan 2021 12:44:37 -0500 X-MC-Unique: tX1BP-R4NNOvL8narF7lng-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B042801817; Tue, 19 Jan 2021 17:44:35 +0000 (UTC) Received: from krava (unknown [10.40.195.212]) by smtp.corp.redhat.com (Postfix) with SMTP id F02065C8A7; Tue, 19 Jan 2021 17:44:32 +0000 (UTC) Date: Tue, 19 Jan 2021 18:44:32 +0100 From: Jiri Olsa To: Namhyung Kim Cc: Jiri Olsa , Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: Re: [PATCH 12/22] perf daemon: Allow only one daemon over base directory Message-ID: <20210119174432.GC1717058@krava> References: <20210102220441.794923-1-jolsa@kernel.org> <20210102220441.794923-13-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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