Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1995885rdb; Wed, 31 Jan 2024 16:16:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHyy8kSe73oN+ahL//uD/nWI9/1i8ZaTivoxPYUCHrvYO7cuq+go7+mwRR0zo6Y+HPDauH X-Received: by 2002:a17:906:4689:b0:a35:a7ba:c642 with SMTP id a9-20020a170906468900b00a35a7bac642mr576362ejr.51.1706746615922; Wed, 31 Jan 2024 16:16:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706746615; cv=pass; d=google.com; s=arc-20160816; b=CDOE9yuXQ4D0WWG1LY6Kc84/YEnT/gGs87ChwSBIVG4xC2k8GK2WJN0oPodmfh4PC0 zT9LmkhDNvnlU5nLnurUP49z8grYhWu86FWLGw07pJ56oEh14R+P7uvX5SaZKT4BbyIQ FTXrhdPHs2Z/orPkLPM1m6xqnyuUIWgtUhgV2kmdTvwFfbhgnd90KhlrS99n9d/X9G7f LgR1GgxWHmuYm+iPkM//65pr1MigwKOyV83WbWJy4idcf0T07FdqP+ycSL1EXhLtSrUl HW4ydsZOWt1P64eboP/L21gZ9UNws3s3qztEqJnmkoZrAbDvcfrTL5uSBqHmYCj2yZAh hT0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=iap9AX1ulrmbLUTYu3qyDksm4nz07RhuxN54fV9TeXc=; fh=WQye0NAJj/vZxfOyF9VJUtFf2P4qLTPWh+Unwn64MnU=; b=HNgNTg1OZNbDAFaq6MHfWEte1aGZW117JGw60ieHdAm6TL2eZPUjrkTs96SM8UYvo2 HgKTxeotMmPsujDAMUZQFSPRO3fi1jRMYFAf3hZdRaFLi3IxZXyC2tcwYFLflAlL5KU7 +lSnTBzTl8v1Ul46W+TeaOzs5TpXjJRibb6mI0wiRwkvrIWD7to1fH/d52wWgt/ijXKT 7VA69gEIS3Sl/evnTotANrRYdTFeoz4nHfdMtlqiPNHy4ds/fuK49Qi1B7p4g847XfaL N6W5fbAgckmB1LigFZLTTIlc9/4HWNUZx3JOLfh7+lvicQJ4zmjvhvlZkWlc9DmDtb0j 4plw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nHDLIFzG; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXsOYZ2shIGprCVN0EW9zhlBlKlcveAnfRdItPIzQG+sQQc7/XIqEs6CpdasTu+gaY1khRlK4GgNn+KRX/rQ6OkJk7vPw04whXHtbB6Mw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cr20-20020a170906d55400b00a34d1fbe4c0si6459977ejc.455.2024.01.31.16.16.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:16:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nHDLIFzG; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 564871F2216A for ; Thu, 1 Feb 2024 00:16:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E6C146B7; Thu, 1 Feb 2024 00:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nHDLIFzG" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B0323C0D for ; Thu, 1 Feb 2024 00:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746530; cv=none; b=QHbxnbYHag4oKVD8iODTfnMYe1LVsbVd63ONfKkDdMpKaa9U6Id43REJBI8PAN+MpQqeHLQyemoPVk91uHeTCmuvgWArNdjeCQNDJNlTAc8Y8ONBLphpG8K6nQyshjxVnhQtfLWXT3o9AurpFtQVlQnsLxfDAOXZDZcr2vvnf1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746530; c=relaxed/simple; bh=P0dE4SZC6JMGyd4Zz6ysHena7Iqo04wzT6xeGII9Szk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qkguyNvgGIYCets3FBXhHtP+MiP/akTBrYp7KrTvJ3DXJP1R/TpMp/WQIU1l/+JGCVPA9+DsnncG1ynF7tdufByuSlcjQ6AloKgsUluwoV1oJuH+IRpIidD8D0HPXBOh2aJzZoXJqui6M2dwMihYxrOHxe/pdZCjWwmVd98wKoY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nHDLIFzG; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6bea4c8b9so482980276.3 for ; Wed, 31 Jan 2024 16:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706746528; x=1707351328; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=iap9AX1ulrmbLUTYu3qyDksm4nz07RhuxN54fV9TeXc=; b=nHDLIFzGWBCxcdSTVZ5+aNUiwVraAfNfr8Tzc0DMpWYk/CHh0M56nzPxx/mpjEWNlq G6Z/F88sCNYlVaBYZogLUTfPmr5yw6YwHfTnN5FvQzCvETLXBo7xfbIZoIxnJxZk2ZWg lr6adnw+YgdcivQhahbZfh6x0Z+mVEcAc8bk+RYI8VAdlS3Ncd/5ifOogza28b2t1dNI GwUO7Cf909GyueoPI0zBN2I3TcV3wGlPy7E0E2RFoTFfUf1HfdjLc6BRtikmWry/d8Qg J1Do6xirVvyBSgsQV57EDxy23kKyzajKfWoHyQHSphrj48YclGHT8BMwdHNZcrpDCUca NeFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706746528; x=1707351328; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iap9AX1ulrmbLUTYu3qyDksm4nz07RhuxN54fV9TeXc=; b=KUo9Zt7hPzj2ktgwRXBUFcszggaSV+nAcYc2A7jDoxIdgTfNM02H7+mw4L486sersd /tHu1tSlLh28HXLhr3BtqNxW8YiLouRp8rh+sTVTu1ariTCSz2G4XPAlugfHKf1D66m/ PSuMSZ9++z/iRMtrCy+k1mU8tFCuDnuXGPtJ0bvErL/QbX2+rnRfeE9bY8NIbP4tq0XF kUPrKVsQU6BhG2kHM++WHnVHlHx6oZaMsxNjrpdeEqxp4j0adA2sNvaI40ASwNzSkPSX T7RqMyoqYOQksVxma+RTEiJ+0Uu7F2BcalQRBd9LcWJP/XbzOBN+poMWCizbXofQrl0D DMbw== X-Gm-Message-State: AOJu0Yz5YDjfMx8/sgbloN8CR5TFEQkJ+fp8+rV7CI5q1lwbYjVXFDL3 PH9I890c0uttewmGS3ZCuuXlsfYtRkxyNRmPXkpSKIMVNYLKgJ+U3xmK1KDeka9Vm4rlrxCLG0N PaOJ+hA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a25:db82:0:b0:dc6:d890:1a97 with SMTP id g124-20020a25db82000000b00dc6d8901a97mr9830ybf.9.1706746528067; Wed, 31 Jan 2024 16:15:28 -0800 (PST) Date: Wed, 31 Jan 2024 16:14:58 -0800 In-Reply-To: <20240201001504.1348511-1-irogers@google.com> Message-Id: <20240201001504.1348511-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240201001504.1348511-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 4/9] tools subcmd: Add a no exec function call option From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Tom Rix , Ravi Bangoria , James Clark , Kan Liang , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Tools like perf fork tests in case they crash, but they don't want to exec a full binary. Add an option to call a function rather than do an exec. The child process exits with the result of the function call and is passed the struct of the run_command, things like container_of can then allow the child process function to determine additional arguments. Signed-off-by: Ian Rogers --- tools/lib/subcmd/run-command.c | 2 ++ tools/lib/subcmd/run-command.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/lib/subcmd/run-command.c b/tools/lib/subcmd/run-command.c index 5cdac2162532..d435eb42354b 100644 --- a/tools/lib/subcmd/run-command.c +++ b/tools/lib/subcmd/run-command.c @@ -122,6 +122,8 @@ int start_command(struct child_process *cmd) } if (cmd->preexec_cb) cmd->preexec_cb(); + if (cmd->no_exec_cmd) + exit(cmd->no_exec_cmd(cmd)); if (cmd->exec_cmd) { execv_cmd(cmd->argv); } else { diff --git a/tools/lib/subcmd/run-command.h b/tools/lib/subcmd/run-command.h index 17d969c6add3..d794138a797f 100644 --- a/tools/lib/subcmd/run-command.h +++ b/tools/lib/subcmd/run-command.h @@ -47,6 +47,8 @@ struct child_process { unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1; void (*preexec_cb)(void); + /* If set, call function in child rather than doing an exec. */ + int (*no_exec_cmd)(struct child_process *process); }; int start_command(struct child_process *); -- 2.43.0.429.g432eaa2c6b-goog