Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1631801 > unrolled thread

[PATCH] plugin python: Adjust the handling after PyRun_String() failed

Started byTaeung Song <treeze.taeung@gmail.com>
First post2017-04-27 01:50 +0200
Last post2017-04-27 15:00 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] plugin python: Adjust the handling after PyRun_String() failed Taeung Song <treeze.taeung@gmail.com> - 2017-04-27 01:50 +0200
    Re: [PATCH] plugin python: Adjust the handling after PyRun_String()  failed Steven Rostedt <rostedt@goodmis.org> - 2017-04-27 04:50 +0200
      Re: [PATCH] plugin python: Adjust the handling after PyRun_String()  failed Taeung Song <treeze.taeung@gmail.com> - 2017-04-27 05:00 +0200
        Re: [PATCH] plugin python: Adjust the handling after PyRun_String()  failed Steven Rostedt <rostedt@goodmis.org> - 2017-04-27 13:40 +0200
          Re: [PATCH] plugin python: Adjust the handling after PyRun_String()  failed Taeung Song <treeze.taeung@gmail.com> - 2017-04-27 15:00 +0200

#1631801 — [PATCH] plugin python: Adjust the handling after PyRun_String() failed

FromTaeung Song <treeze.taeung@gmail.com>
Date2017-04-27 01:50 +0200
Subject[PATCH] plugin python: Adjust the handling after PyRun_String() failed
Message-ID<tAER3-QX-7@gated-at.bofh.it>
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 <treeze.taeung@gmail.com>
---
 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;
 	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;
 }
 
 int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
-- 
2.7.4

[toc] | [next] | [standalone]


#1631832 — Re: [PATCH] plugin python: Adjust the handling after PyRun_String() failed

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-04-27 04:50 +0200
SubjectRe: [PATCH] plugin python: Adjust the handling after PyRun_String() failed
Message-ID<tAHFf-2FC-1@gated-at.bofh.it>
In reply to#1631801
On Thu, 27 Apr 2017 08:46:21 +0900
Taeung Song <treeze.taeung@gmail.com> 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 <treeze.taeung@gmail.com>
> ---
>  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.

>  	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

>  }
>  
>  int PEVENT_PLUGIN_LOADER(struct pevent *pevent)

[toc] | [prev] | [next] | [standalone]


#1631835 — Re: [PATCH] plugin python: Adjust the handling after PyRun_String() failed

FromTaeung Song <treeze.taeung@gmail.com>
Date2017-04-27 05:00 +0200
SubjectRe: [PATCH] plugin python: Adjust the handling after PyRun_String() failed
Message-ID<tAHOV-2IP-9@gated-at.bofh.it>
In reply to#1631832

On 04/27/2017 11:47 AM, Steven Rostedt wrote:
> On Thu, 27 Apr 2017 08:46:21 +0900
> Taeung Song <treeze.taeung@gmail.com> 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 <treeze.taeung@gmail.com>
>> ---
>>  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.

>>  	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!


Thanks,
Taeung

[toc] | [prev] | [next] | [standalone]


#1632040 — Re: [PATCH] plugin python: Adjust the handling after PyRun_String() failed

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-04-27 13:40 +0200
SubjectRe: [PATCH] plugin python: Adjust the handling after PyRun_String() failed
Message-ID<tAPWa-8ku-7@gated-at.bofh.it>
In reply to#1631835
On Thu, 27 Apr 2017 11:52:14 +0900
Taeung Song <treeze.taeung@gmail.com> wrote:

> On 04/27/2017 11:47 AM, Steven Rostedt wrote:
> > On Thu, 27 Apr 2017 08:46:21 +0900
> > Taeung Song <treeze.taeung@gmail.com> 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 <treeze.taeung@gmail.com>
> >> ---
> >>  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.

> 
> >>  	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

[toc] | [prev] | [next] | [standalone]


#1632086 — Re: [PATCH] plugin python: Adjust the handling after PyRun_String() failed

FromTaeung Song <treeze.taeung@gmail.com>
Date2017-04-27 15:00 +0200
SubjectRe: [PATCH] plugin python: Adjust the handling after PyRun_String() failed
Message-ID<tARbz-Jt-9@gated-at.bofh.it>
In reply to#1632040

On 04/27/2017 08:30 PM, Steven Rostedt wrote:
> On Thu, 27 Apr 2017 11:52:14 +0900
> Taeung Song <treeze.taeung@gmail.com> wrote:
>
>> On 04/27/2017 11:47 AM, Steven Rostedt wrote:
>>> On Thu, 27 Apr 2017 08:46:21 +0900
>>> Taeung Song <treeze.taeung@gmail.com> 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 <treeze.taeung@gmail.com>
>>>> ---
>>>>  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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web