Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp176755pxt; Wed, 11 Aug 2021 17:58:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZtJbmF+90Gyu2jtyZZeH2jKGJfRlRdIsXHn+aWKlzMSk0VIjCKdoGng5dAy5zZgymCRv3 X-Received: by 2002:a05:6e02:13d3:: with SMTP id v19mr900843ilj.167.1628729905562; Wed, 11 Aug 2021 17:58:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628729905; cv=none; d=google.com; s=arc-20160816; b=B4YKj/xCn/wg8ieojNaGf1F1ADGSEMwXSs4ESSS7FerMeODov8hatiKpEZeSCbrnZW vbTFQjVZfJenbLGnyQKsl5BfUBjLc900scbdvq8RTbLCIHEJ+r7LpIohv8mDwPo1hxLj Xp4BfJsVNG7S3n83aTwzl8ingeFTdjETn7SX2YSrjLgt7MURF5/OmhQqpqu3iK8b/6+w d+FJUCFvHz+MfHpuYgLWTHQzh3SnGOZuF10X58R5OgbB8+kXTAyZO+U3YYsC334WDMWL hcFq4MgQJyKVFuq+LXaKZTWY41dMq/grNTpcvNtof7cql+01Bzoo998nboK7R9mH9DR6 kBuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5jsSzfrQJd4kdAcdgMJVP8+6e+Lk4PHk8aBVd48faQc=; b=JGz5mIkpfnf6U0ejfKU2KjrN25q597xFnZPJgQ9LUlNZMX1PEFCsr0g/mtBkN2X2KA jq/o25KZHk9xdxmoeoh401VCh9ERiWWhWgIlw4+YxAFqN2iZYXp4zEMKjl09NrVvWy2y YeroeqS3qMkP2AGw//n2RNYsQA0nzHENzuZqILiqh/CPFGYZ+E+D/jvQBWDtAqHP+T1/ /gillPluXrt3EcGiS6JR9xGBhsq5PaEyf1qVH0K5IfgFqYJM3yBk4EPmSOAYihWffk1/ 7jucnWbzMgyKdjWHv+wJlrAh3ff2roT3ckL8LVjISUB73DmCUpyj6MQPEKh1KKKSdU7W OHyQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si955010iom.2.2021.08.11.17.58.14; Wed, 11 Aug 2021 17:58:25 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232704AbhHLA4R (ORCPT + 99 others); Wed, 11 Aug 2021 20:56:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:35980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233166AbhHLA4N (ORCPT ); Wed, 11 Aug 2021 20:56:13 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59F4361077; Thu, 12 Aug 2021 00:55:49 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mDz0e-003oyV-2T; Wed, 11 Aug 2021 20:55:48 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , "Steven Rostedt (VMware)" Subject: [PATCH 1/2] libtracefs: Add random number to keep synthetic variables unique Date: Wed, 11 Aug 2021 20:55:45 -0400 Message-Id: <20210812005546.910833-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812005546.910833-1-rostedt@goodmis.org> References: <20210812005546.910833-1-rostedt@goodmis.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" The 'hist' triggers expect that all variables are unique. If two synthetic events are created, it is possible that they will use the same variable names, and this can break the logic for synthetic events. Add a random number to the argument names that will help prevent that from happening. There's no guarantee that there wont be collisions, but the chances of that happening is 1 in 65535. If this is a problem, we could possibly look for variables that are already in use. Signed-off-by: Steven Rostedt (VMware) --- src/tracefs-hist.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 7f9cf3820611..8783ef4364bd 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "tracefs.h" #include "tracefs-local.h" @@ -558,6 +560,7 @@ struct tracefs_synth { unsigned int end_parens; unsigned int end_state; int *start_type; + char arg_name[16]; int arg_cnt; }; @@ -957,7 +960,15 @@ static char *new_arg(struct tracefs_synth *synth) char *arg; int ret; - ret = asprintf(&arg, "__arg__%d", cnt); + /* Create a unique argument name */ + if (!synth->arg_name[0]) { + srand(time(NULL)); + ret = rand() + gettid(); + /* Truncate so that ret is at most 65535 (total 13 bytes) */ + ret &= (1 << 16) - 1; + sprintf(synth->arg_name, "__arg_%d_", ret); + } + ret = asprintf(&arg, "%s%d", synth->arg_name, cnt); if (ret < 0) return NULL; -- 2.30.2