Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034147AbdD0M5z (ORCPT ); Thu, 27 Apr 2017 08:57:55 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35691 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031811AbdD0M5o (ORCPT ); Thu, 27 Apr 2017 08:57:44 -0400 Subject: Re: [PATCH] plugin python: Adjust the handling after PyRun_String() failed To: Steven Rostedt References: <1493250381-25278-1-git-send-email-treeze.taeung@gmail.com> <20170426224720.58733a9a@grimm.local.home> <09569170-b800-dfca-8267-d0c2a23df85b@gmail.com> <20170427073033.3a5e16dd@gandalf.local.home> Cc: linux-kernel@vger.kernel.org From: Taeung Song Message-ID: <69459c9a-f02b-1491-17c9-79799208089d@gmail.com> Date: Thu, 27 Apr 2017 21:57:39 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170427073033.3a5e16dd@gandalf.local.home> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1858 Lines: 76 On 04/27/2017 08:30 PM, Steven Rostedt wrote: > On Thu, 27 Apr 2017 11:52:14 +0900 > Taeung Song wrote: > >> On 04/27/2017 11:47 AM, Steven Rostedt wrote: >>> On Thu, 27 Apr 2017 08:46:21 +0900 >>> Taeung Song wrote: >>> >>>> Even though PyRun_String() failed, >>>> just 0 will be returned but we need to return -1 >>>> that means error status, so fix it. >>>> >>>> Signed-off-by: Taeung Song >>>> --- >>>> plugin_python.c | 5 +++-- >>>> 1 file changed, 3 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/plugin_python.c b/plugin_python.c >>>> index 2997679..dcfad0f 100644 >>>> --- a/plugin_python.c >>>> +++ b/plugin_python.c >>>> @@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, >>>> const char *name, void *data) >>>> { >>>> PyObject *globals = data; >>>> - int err; >>>> + int err, ret = 0; >>> >>> Hmm, we can either reuse err. >>> >> >> But return value of asprintf() can be more 1, >> when it succeeded. >> So I think it is better the below you said. > > What I meant was to simply reset err = 0; and set it if we failed and > returned that. No need to add more variables. > I understood ! :) >> >>>> int len = strlen(path) + strlen(name) + 2; >>>> int nlen = strlen(name) + 1; >>>> char *full = malloc(len); >>>> @@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path, >>>> if (!res) { >>>> fprintf(stderr, "failed loading %s\n", full); >>>> PyErr_Print(); >>>> + ret = -1; >>>> } else >>>> Py_DECREF(res); >>>> >>>> free(load); >>>> >>>> - return 0; >>>> + return ret; >>> >>> or do a: return res ? 0 : -1; >>> >>> -- Steve >>> >> >> Okey! I'll resent the patch after modifying this! > > But this is fine as well. > > -- Steve > Thank you !! Have a nice day :) Taeung