From patchwork Fri Sep 17 15:21:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12502591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 288E7C433FE for ; Fri, 17 Sep 2021 15:23:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05FD161216 for ; Fri, 17 Sep 2021 15:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233957AbhIQPYj (ORCPT ); Fri, 17 Sep 2021 11:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344241AbhIQPYY (ORCPT ); Fri, 17 Sep 2021 11:24:24 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D3FC0613A8 for ; Fri, 17 Sep 2021 08:21:51 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id j13so31381323edv.13 for ; Fri, 17 Sep 2021 08:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qdRP+S5joetPVUch9/SeJ+zgj23hWt4gtcuRnFZANnY=; b=Yy76MAmFbH86LGAjWgHE0rRMwE6b7PCd3bT12Kn0ifmfCCeM9nV+dC9k9JSpo+b52W 9/5SQVuc+eRiCvtZJDvyKxx5gCOHozFmb/KKpWuQxdgfRu7rcDh+nGDx4LkiKdVfdjQy xZ2j+1GIzRzHbAcrzTovc+0+tynDqx0SoC4pcuxOqX5wNwauPlj64TtjvWNnoohZMS/e EGaRa56aSHUF1baBUeegH5mUkb/FMtSamqlSL2nhErFoEg2oBbLTb9H/K0QIqk7M0bBJ x5xfaWX/cu20QbyAcwwrH9V1IjBeXVQ2OX8PiJFV8LM3gzX6qKiJumdRj8njObwu183z YwOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qdRP+S5joetPVUch9/SeJ+zgj23hWt4gtcuRnFZANnY=; b=2u8RygYBkI1rukyMC8EiJLRF22w9OjwAs2BSoY+a1q+X+J7EhDLKsFod1npSTWv1BK LV5yC62HuXtqwP6TqDoWsh/Ev27zC3DetJL8GfWsre0VIIqR8oWOwdfdkWrQ6LYOBv6V ZFuEdruLNFhRbkxvWiuI2qCcF2mbo1GB/JBI+QUlaakZfpgdXV113VMHC/wrd1ow8LMD LHqsaQB0a5eGhqlk2Py0xvwYH1J+QHVEWD9LJ8Q9DbIOnRZyq1tHO5PTMiuFuc+aJMan gq9qGBlandWrhBAcNrzuDUo5HFjYkqBpLKlp0+53Ztb+0xZdZRcHzsV6HWH86ubf6n9w UKPg== X-Gm-Message-State: AOAM533qsep5TyFwSu8DAfOO/5IS29xRioVWvik1E1gnXLWBfATAoiQi aBbf+slAixSyAQYrMO+WH9J8U2BCT3E= X-Google-Smtp-Source: ABdhPJyQUhP7SIgjcZzlO7VA4Q5UTEczcD89WfhAv3CVWlwxswpNHBMjKoZeN1tDUzQWpgJqbV+5Mw== X-Received: by 2002:a05:6402:445:: with SMTP id p5mr12971526edw.208.1631892109960; Fri, 17 Sep 2021 08:21:49 -0700 (PDT) Received: from crow.. ([95.87.199.246]) by smtp.gmail.com with ESMTPSA id p19sm2407464ejo.81.2021.09.17.08.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 08:21:49 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 1/2] trace-cruncher: Fix get_comm_from_pid() Date: Fri, 17 Sep 2021 18:21:38 +0300 Message-Id: <20210917152139.574350-1-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Make sure that the buffer string is properly initialized and that the new line at the end is removed. Fixes: defe053 (trace-cruncher: Add generic methods for printing) SignedFixes: -off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 58f543a..7b1ff1b 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -384,10 +384,16 @@ static bool init_print_seq(void) return true; } +static inline void trim_new_line(char *val) +{ + if (val[strlen(val) - 1] == '\n') + val[strlen(val) - 1] = '\0'; +} + static char *get_comm_from_pid(int pid) { char *comm_file, *comm = NULL; - char buff[PATH_MAX]; + char buff[PATH_MAX] = {0}; int fd, r; if (asprintf(&comm_file, "/proc/%i/comm", pid) <= 0) { @@ -409,6 +415,7 @@ static char *get_comm_from_pid(int pid) if (r <= 0) return NULL; + trim_new_line(buff); comm = strdup(buff); if (!comm) MEM_ERROR; @@ -654,11 +661,6 @@ static int read_from_file(struct tracefs_instance *instance, return size; } -static inline void trim_new_line(char *val) -{ - val[strlen(val) - 1] = '\0'; -} - static bool write_to_file_and_check(struct tracefs_instance *instance, const char *file, const char *val) From patchwork Fri Sep 17 15:21:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12502589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DACAC433F5 for ; Fri, 17 Sep 2021 15:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42A6361164 for ; Fri, 17 Sep 2021 15:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbhIQPYi (ORCPT ); Fri, 17 Sep 2021 11:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344243AbhIQPYY (ORCPT ); Fri, 17 Sep 2021 11:24:24 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F9F7C0613A9 for ; Fri, 17 Sep 2021 08:21:52 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id v22so27064720edd.11 for ; Fri, 17 Sep 2021 08:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5iDb27AA1mUrq+X7sEclo0+MUulcbuU4r4C9WPy7Zjg=; b=Hs9d/CEe01xCa679copWzHX+54II53Io1MIIYQlVsDdQ5kQXFSHLRZFWjag65l2bOD 2jGm87lZaEK6lUfVAKj1Z06EWjmicpkyPjing0r0erlIKyFKDBu3Frd4DKNbEGwa/oWI 33Xa4O0w1HhmmnhdUAHr28kS9PYYiSIbo20P5BkcuKaWyYgYgJEIE4krp1P4KtPa3OER Y4rtIuX3G2xEnOaovw260wBSTBF0dZhT67fom32fkw1m5yAcEBnYLlDpm0tYU/icwtGd EPPkhljh/gU+DNvOYfaH7hUeGpX2Ipmj92Vk8naRe03ZcmBL5S5cEzs325wnyZrBrglt ib5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5iDb27AA1mUrq+X7sEclo0+MUulcbuU4r4C9WPy7Zjg=; b=GiVeBlP95nrX/6QutPm9iEj9fk6Oq+UjAUCpRzfeeRyDjfDLSv1dmXkn4NEwdgDu7q LnwMlR9LgLKA+6dMqyzJE4NklLTWciq9Xkw8qldWPDC1lmSu8O9BA+eTyl0HvGNQeDw9 JoUKM/1w+VjsynLGXZpC1Cq7rBQhsrmgBrpbYtXFtxlIEy16BdV4ODjRKEbvu0w/2l7R borM7AhQUvUsyLJeoIDD8KLlae63tjTGb4ZUKUfR16Y2BXzzYgxc6Q4F9UhGOmbW9xhq s5cSpZQZ8MzTtbuF1gvLD8cmXGmG2LsxT5r10gIayqKdAlC3V1LZsflam+gBCUbYL5Y1 VhzA== X-Gm-Message-State: AOAM5310n4aw//jL9Nfi7cl9N6gO5tuB8eCq0iSITuY1h4VSJ4t53zxv OV3WdC+wxFc4S9iKUl0yuoxYaDaIV6s= X-Google-Smtp-Source: ABdhPJzRtVIKgvaTjXpL8EOrgnejJmAq82s+GOUl2TSH4Ws92SmG8Bl+nHXl1aXbUx5+on65L4eSDg== X-Received: by 2002:a17:906:369a:: with SMTP id a26mr12648052ejc.539.1631892110821; Fri, 17 Sep 2021 08:21:50 -0700 (PDT) Received: from crow.. ([95.87.199.246]) by smtp.gmail.com with ESMTPSA id p19sm2407464ejo.81.2021.09.17.08.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 08:21:50 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 2/2] trace-cruncher: More options for stopping data iteration Date: Fri, 17 Sep 2021 18:21:39 +0300 Message-Id: <20210917152139.574350-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210917152139.574350-1-y.karadz@gmail.com> References: <20210917152139.574350-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org So far the only option to stop the iteration over the tracing data from the callback function was to call 'sys.exit()'. However, this only stops the iteration without actually exiting. With this change calling 'sys.exit()' will terminate (exit the module), while in order to just stop the iteration, the callback should return nonzero integer value. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 7b1ff1b..814e1d6 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2101,21 +2101,36 @@ static int callback(struct tep_event *event, struct tep_record *record, ret = PyObject_CallObject((PyObject *)ctx->py_callback, arglist); Py_DECREF(arglist); - if (ret) { - Py_DECREF(ret); - } else { + if (!ret) { if (PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_SystemExit)) { - PyErr_Clear(); + PyObject *err_type, *err_value, *err_traceback; + + PyErr_Fetch(&err_type, &err_value, &err_traceback); + if (err_type == PyExc_SystemExit) { + if (PyLong_CheckExact(err_value)) + Py_Exit(PyLong_AsLong(err_value)); + else + Py_Exit(0); } else { + PyErr_Restore(err_type, err_value, err_traceback); PyErr_Print(); } } - ctx->status = false; + goto stop; + } + + if (PyLong_CheckExact(ret) && PyLong_AsLong(ret) != 0) { + Py_DECREF(ret); + goto stop; } + Py_DECREF(ret); return 0; + + stop: + ctx->status = false; + return 1; } static bool notrace_this_pid(struct tracefs_instance *instance)