Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1422159rdb; Fri, 16 Feb 2024 15:59:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWu8iVM7/hS/TAmQvxBAsJYT9Nr9iI7dSELUVfuGkuvR0noQd8X7an5RDnUo7/u0pzBCgpjEQbnV++gTsFSAwEHOhbFSEdUqFz3O63CLA== X-Google-Smtp-Source: AGHT+IG+6D+WrAVaoCFLHPnByY0EGZQfupSeEmVeuE7zCyIPC8NX3JIo7gjQWAXUane2NkzOQpMo X-Received: by 2002:a19:7407:0:b0:512:9e9f:2f1d with SMTP id v7-20020a197407000000b005129e9f2f1dmr785099lfe.58.1708127958046; Fri, 16 Feb 2024 15:59:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127958; cv=pass; d=google.com; s=arc-20160816; b=LjGHtqU5qZchP5gt1nHyGZKhdCbagylFv2x94fVnrM46V4G4hmNxrKnajhauPoO8yQ wPK7olUfz1pLoyhSjsKBhbhtYLsPwjwsmomlXLuz59TGLc1A4Oemf7QvlVayn/YPnJci OWzxT4Bi1vex75+36Mo7wZtVut62yknlx58nwMyCTB/2wxntTSR2MJQysUJZmlH0fTeO AFhAfGxGatmJbT4IBel3ZpR13JYzo4VYs7xlc9HugRD06E0XCth5X5pP67e+BnxX9759 zZ2CweKFEOCLeVNJtE8iyfsxFydFaeZpRL0f44T9ddDAeYXcZ7+b0g2Vq04Mpsx4slXy eezQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cw13-20020a056402228d00b00561f629d5c7si393061edb.456.2024.02.16.15.59.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-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 C3FD71F225A9 for ; Fri, 16 Feb 2024 23:59:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 530F515350E; Fri, 16 Feb 2024 23:55:25 +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 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.44.0.rc0.258.g7320e95886-goog