[libvirt] [PATCH] parse container id in separate function

There were several places with parsing container id from code. Separate function is used now.

On Fri, Jul 18, 2008 at 06:02:00PM +0400, Evgeniy Sokolov wrote:
There were several places with parsing container id from code. Separate function is used now.
Index: src/openvz_conf.c =================================================================== RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.29 diff -u -p -r1.29 openvz_conf.c --- src/openvz_conf.c 11 Jul 2008 08:56:16 -0000 1.29 +++ src/openvz_conf.c 18 Jul 2008 13:21:07 -0000 @@ -134,9 +134,7 @@ strtoI(const char *str) val = (int) strtol(str, &endptr, base);
/* Check for various possible errors */ - if ((endptr == str) /* "No digits were found" */ - ||((*endptr != '\0') - && (*endptr != ' ')) /*"Name contain characters other than integers" */ ) + if (endptr == str) /* "No digits were found" */ return 0; return val; }
I'd not noticed this function before, but it looks like you could probably just call virStrToLong_i() from the util.h file. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote:
On Fri, Jul 18, 2008 at 06:02:00PM +0400, Evgeniy Sokolov wrote:
There were several places with parsing container id from code. Separate function is used now.
Index: src/openvz_conf.c =================================================================== RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.29 diff -u -p -r1.29 openvz_conf.c --- src/openvz_conf.c 11 Jul 2008 08:56:16 -0000 1.29 +++ src/openvz_conf.c 18 Jul 2008 13:21:07 -0000 @@ -134,9 +134,7 @@ strtoI(const char *str) val = (int) strtol(str, &endptr, base);
/* Check for various possible errors */ - if ((endptr == str) /* "No digits were found" */ - ||((*endptr != '\0') - && (*endptr != ' ')) /*"Name contain characters other than integers" */ ) + if (endptr == str) /* "No digits were found" */ return 0; return val; }
I'd not noticed this function before, but it looks like you could probably just call virStrToLong_i() from the util.h file.
Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote:
There were several places with parsing container id from code. Separate function is used now. Index: src/openvz_conf.c =================================================================== RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.29 diff -u -p -r1.29 openvz_conf.c --- src/openvz_conf.c 11 Jul 2008 08:56:16 -0000 1.29 +++ src/openvz_conf.c 18 Jul 2008 13:21:07 -0000 @@ -134,9 +134,7 @@ strtoI(const char *str) val = (int) strtol(str, &endptr, base);
/* Check for various possible errors */ - if ((endptr == str) /* "No digits were found" */ - ||((*endptr != '\0') - && (*endptr != ' ')) /*"Name contain characters other than integers" */ ) + if (endptr == str) /* "No digits were found" */ return 0; return val; } I'd not noticed this function before, but it looks like you could
On Fri, Jul 18, 2008 at 06:02:00PM +0400, Evgeniy Sokolov wrote: probably just call virStrToLong_i() from the util.h file.
Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function.
I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function int virStrToLongSimple_i(const char *str, int *result) { char *endptr; return virStrToLong_i(str, &endptr, 10, result); }

On Mon, Jul 21, 2008 at 01:41:27PM +0400, Evgeniy Sokolov wrote:
On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function.
I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function
int virStrToLongSimple_i(const char *str, int *result) { char *endptr;
return virStrToLong_i(str, &endptr, 10, result); }
If you don't want to deal wit the endptr return value, you can simply pass in NULL for that param. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Mon, Jul 21, 2008 at 01:41:27PM +0400, Evgeniy Sokolov wrote:
On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function
int virStrToLongSimple_i(const char *str, int *result) { char *endptr;
return virStrToLong_i(str, &endptr, 10, result); }
If you don't want to deal wit the endptr return value, you can simply pass in NULL for that param.
from notes: When END_PTR is NULL, the byte after the final valid digit must be NUL. I don't want to deal the endptr. But I want to parse strings like " 123 abc".
Regards, Daniel

On Mon, Jul 21, 2008 at 03:07:31PM +0400, Evgeniy Sokolov wrote:
On Mon, Jul 21, 2008 at 01:41:27PM +0400, Evgeniy Sokolov wrote:
On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function
int virStrToLongSimple_i(const char *str, int *result) { char *endptr;
return virStrToLong_i(str, &endptr, 10, result); }
If you don't want to deal wit the endptr return value, you can simply pass in NULL for that param.
from notes: When END_PTR is NULL, the byte after the final valid digit must be NUL.
I don't want to deal the endptr. But I want to parse strings like " 123 abc".
Why ? Everywhere else in libvirt treats that as mal-formed input and rejects it. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Mon, Jul 21, 2008 at 03:07:31PM +0400, Evgeniy Sokolov wrote:
On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function
int virStrToLongSimple_i(const char *str, int *result) { char *endptr;
return virStrToLong_i(str, &endptr, 10, result); } If you don't want to deal wit the endptr return value, you can simply
On Mon, Jul 21, 2008 at 01:41:27PM +0400, Evgeniy Sokolov wrote: pass in NULL for that param. from notes: When END_PTR is NULL, the byte after the final valid digit must be NUL.
I don't want to deal the endptr. But I want to parse strings like " 123 abc".
Why ? Everywhere else in libvirt treats that as mal-formed input and rejects it.
Ok. I will follow the same rule. I rewrited code to parse via virStrToLong_i() function. patch is attached.

On Mon, Jul 21, 2008 at 04:55:04PM +0400, Evgeniy Sokolov wrote:
Ok. I will follow the same rule. I rewrited code to parse via virStrToLong_i() function.
As a result strtoI is a bit empty but that's fine :-)
patch is attached.
Looks fine to me, applied and commited. thanks ! Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Evgeniy Sokolov