From patchwork Fri Feb 16 23:51:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp70553dyc; Fri, 16 Feb 2024 16:22:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxv8WMT9nB3shJAK60bk5h9U4Ruvz8ezTRvMHWbBomtHynv95yfLcM+537N2mn09p3bZuyRVmBc6JQm/uGFW4nXtVJrw== X-Google-Smtp-Source: AGHT+IFAJ9YukdiH6nN61dB1bqNvRSdjRWdfFGOfkzb9QeXWViOmVVXBWCi+9AazEaQiGrTkewPD X-Received: by 2002:a05:6358:706:b0:178:92dc:8a32 with SMTP id e6-20020a056358070600b0017892dc8a32mr6751450rwj.20.1708129361842; Fri, 16 Feb 2024 16:22:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708129361; cv=pass; d=google.com; s=arc-20160816; b=domYhRuiS0ofO1kI0bktssLqxqN38pIP7QkLqgovPhnbgaGgaGQtD8vwG9hxEVPbu6 InVhmr8nhOZkEOtq4seCnY9FeHM/6EwBgsFLfh+vY2hFSbbJf+/RDoXRatFlbPErIc8T 7VqjXSHqdnVSZ2M6U+76OI9O2tWCi5zDpi0H6A9ehgbIe4yh/Lfwqz1FeNWO1SPlBX3f T4CsL3lSa9rPGN4rSAF2uS+WLWs4e/9gFhhzKQKDXV9/MKkY0YK9g6iz4q2p1OW45Y2n 0PIWRQNv4jWbjWSvglAyWMzVTqBjwdx8mxywaPSm8OmuD24sXrj68I2787ZDWzAFYyfl rcdw== 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; fh=DEVtZCU+UwPIV/qYU4Kf8V11ilXrf8vFGLwB6Nij0mA=; b=bjPNTh7oRB9hwEmg1uffw/WX3KyZcf3CpkyVy0E2xFwKp0BMZT+5UxqHPRYfVhqyeh sEueo70c3IrlRHRsI0XILaVk+4ALrdEtENdsVBOQGI/bdH2Suy15ZXRZpxxUAFfdfVeU yZOV5c1fU0JGF8Pjo000hW4yEu/pvjW5DdxQA/L4sEC4aq9T9ljkq53B9jXNsmY+lxCx 484fFnMxakxTQEA+yepICW52qpIReUKVG6+WvcqjFCj7wQJan7dRc9Fz8bAtyYCXpzTZ tp2nG1g9LZ6Kjn7o3pXoiG61E8eZI8Ex+uuQzIiPI1mQGU321608oXrx5ErV3HR6lM7x x3Dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PZy5ChhJ; 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-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m14-20020a63f60e000000b005dc81a30772si643017pgh.301.2024.02.16.16.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:22:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PZy5ChhJ; 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-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 82B8CB209F4 for ; Fri, 16 Feb 2024 23:59:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41CF015351D; Fri, 16 Feb 2024 23:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PZy5ChhJ" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 E586214A4F4 for ; Fri, 16 Feb 2024 23:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127724; cv=none; b=kafgkKGGrVEys1pvrGi4CQ6fqQLlxYu0aOzyHS+4Iom/Y8aicrtn2yjB6k8VEl8O0to/yKn4ozTQ31XRPSFj31llvJK3Xo3517wXO0AkcIvtJT1mhCkpAgINRq9xCDbe6pKwjm7WnT8x6FOTQ7yIAYR0Cj+DYzZnx7midmYHIKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127724; c=relaxed/simple; bh=nIwADbFncYymlWUg/R60jRadSx8+xe1bkn0KEBii9rU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Z+bOxQUBHrwhKse4m2mI6syExfTfYpqxtP8uqJ+I1a98xRQ9AwnkT3QuoFN602fRtj9sUA+vcyOCwqM/HPoSfk/BJ2/zuLDRly2qgqK6gLHmfCvj0CwgzMPEf6EKO+7ySeqjD6Kj5ttjwK/MthpurveZ2VhnC4sh3CeMYOoTiys= 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=PZy5ChhJ; arc=none smtp.client-ip=209.85.219.201 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-f201.google.com with SMTP id 3f1490d57ef6-dcc0bcf9256so1796733276.3 for ; Fri, 16 Feb 2024 15:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127722; x=1708732522; 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; b=PZy5ChhJk5JUXUDQLXMQvdXtEOXP11BPV4rBPvaGZpyQL1nyZRMDmOSwSNuxq0/eST upNa0E1k8pXZ1Nb7r02K+1hiRIoFDBWNHxZ90UAeLS33odaDXxKmuyFBweLwL7MbG+Yh DI95Z4Z/KUh4gmlIXnQINyvCcQAx1G0eSJKObAZ7ktCbNYGSQY2kE+JOlB+waObCy6az MO3t+tCD1ghKuN9fSaQ82Y9q+/pZAYUP0uRD3UuJY+PuWN+uT5qqVJVQrBISoG3ja9W+ h9LKbVLAykFBbsE4hY+V34WEDzWtIFvTMOggP3ux8RhEYtYEnvWhInUYixSrzm6lB6ZR tOVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127722; x=1708732522; 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; b=QqYRrlcMgUIMZ64M7vk9w8DfGJRllNFUT6O20IJFkeP/VsWX10tkA6PUhVop+Pi7xb Bxo/vvEiNqRgfR1mMLSC1KNlXKDrzlZdtt3So1kPtoJRYaVBtmKO+bUX0eBb2Ym6rDGa 7/DML17lQSAaCNMg4YveNAPg88faXu2qPljgnih74OmJtX5WGRnxVrIZLIeRmgmMnwRV 2QKGFlH0ZKygs46DuGx9zCUxdXJxQ127QeW8LY1TjnRf/ds5AUu2bD2a+aqkaXk8+Np9 RCEf4C+3HmtRaDG5PxXdNvpT/dmrveZjJFgNDk2bRP2HMezSMHnzK7S0X0tyRlXenoCF +ELw== X-Forwarded-Encrypted: i=1; AJvYcCWFHFC8YOM0fJIwtJa2q4O4u3c7VYylEoS6bZBDVruoy2dHVWv8Q56NBEX8q0eSJ9A8flFPIxaLuoyvdU/+aqD6ePdfS9RM8UwHixOY X-Gm-Message-State: AOJu0YzBzW1eTyF7Mt7V0ThuonkTXXXkh+PUsXhWVxieKiUkX3IMb8de jdoe0EmdpxcYBO5m5+JZVE+xKhovqvhMq8MHjmVqSI8BL4GXEMI48QAXfrZ+UsNzkJQz+tbclcU WTAw1kg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a05:6902:704:b0:dc7:6f13:61d9 with SMTP id k4-20020a056902070400b00dc76f1361d9mr242453ybt.4.1708127721847; Fri, 16 Feb 2024 15:55:21 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:58 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 4/8] tools subcmd: Add a no exec function call option From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Athira Jajeev , James Clark , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791103453591787904 X-GMAIL-MSGID: 1791103453591787904 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 *);