Bug 582144 - $g->aug_set doesn't allow a NULL value
Summary: $g->aug_set doesn't allow a NULL value
Status: CLOSED ERRATA
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: libguestfs
Version: el5
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Keywords:
Depends On:
Blocks: 582173
TreeView+ depends on / blocked
 
Reported: 2010-04-14 09:16 UTC by Matthew Booth
Modified: 2010-09-03 21:57 UTC (History)
4 users (show)

(edit)
Clone Of:
: 582173 (view as bug list)
(edit)
Last Closed: 2010-09-03 21:57:22 UTC


Attachments (Terms of Use)

Description Matthew Booth 2010-04-14 09:16:04 UTC
Description of problem:
$g->aug_set(augeas_label, NULL) results in an empty string being set, rather than a label being created with no value. There is no alternative mechanism for creating a label with no value.

Specifically, this problem prevents adding kernel arguments to grub.conf which don't have a value.

Comment 2 Fedora Update System 2010-04-14 13:39:49 UTC
libguestfs-1.2.2-1.el5.6 has been submitted as an update for Fedora EPEL 5.
http://admin.fedoraproject.org/updates/libguestfs-1.2.2-1.el5.6

Comment 3 Fedora Update System 2010-04-15 15:47:44 UTC
libguestfs-1.2.2-1.el5.6 has been pushed to the Fedora EPEL 5 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update libguestfs'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/libguestfs-1.2.2-1.el5.6

Comment 4 Jinxin Zheng 2010-06-28 09:53:36 UTC
In my knowledge perl does not have a definition for 'NULL' as in other languages. Usually perl scripts uses empty string as replacement.

Although we can pass a real NULL through C or python to aug_set, it results in an error because aug_set does not accept NULL.

I can verify this as I said in bug 582173, and with the package provided in comment 2 the aug_clear API is available for us to delete the value associated with the node.

Comment 5 Richard W.M. Jones 2010-06-28 10:09:33 UTC
(In reply to comment #4)
> In my knowledge perl does not have a definition for 'NULL' as in other
> languages. Usually perl scripts uses empty string as replacement.

This isn't true.  In Perl, undef is different from the empty string "".

> Although we can pass a real NULL through C or python to aug_set, it results in
> an error because aug_set does not accept NULL.

The issue wasn't with Perl.  It was an issue in the RPC protocol that
we use between the library and the daemon.  We incorrectly used the
XDR "string<>" type to represent the second parameter to aug_set.  However
the XDR "string<>" type is not a nullable type (you cannot pass a NULL),
and we cannot change this without breaking the ABI between the library
and daemon.  Therefore we had to introduce another API call (aug_clear)
which sets the named node to NULL.

By using both aug_set and aug_clear you can now set a node either to
a string value (including the empty string) _or_ to NULL.

For details, see:
libguestfs/src/guestfs_protocol.x
struct guestfs_aug_set_args vs struct guestfs_aug_clear_args

Comment 6 Jinxin Zheng 2010-06-28 10:56:17 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > In my knowledge perl does not have a definition for 'NULL' as in other
> > languages. Usually perl scripts uses empty string as replacement.
> 
> This isn't true.  In Perl, undef is different from the empty string "".

I see. But what happens if we pass undef? Does perl translate it to empty string since it's expecting a string that is not nullable?

Comment 7 Richard W.M. Jones 2010-06-28 11:14:44 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > In my knowledge perl does not have a definition for 'NULL' as in other
> > > languages. Usually perl scripts uses empty string as replacement.
> > 
> > This isn't true.  In Perl, undef is different from the empty string "".
> 
> I see. But what happens if we pass undef? Does perl translate it to empty
> string since it's expecting a string that is not nullable?    

Yes, sometimes.

In the underlying C API, if you call:

  guestfs_aug_set (g, "/foo", NULL);

then you would either get a segfault (in the stable branch and in RHEL)
or you would get an error message (in the development branch, see
bug 501893 and [1]).

In Perl it's depends on how the function parameter was declared in
the generator[2].

If the parameter was declared as String, then the Perl bindings translate
undef -> "".  If the parameter was declared as OptString, then the Perl bindings
pass through undef as NULL to the C binding and any string as a string.

You can probably most easily see the difference in a test script.  First
using add_drive where the parameter is declared as String:

  $ perl -MSys::Guestfs -w -e '$g = Sys::Guestfs->new (); $g->add_drive (undef);'
  Use of uninitialized value in subroutine entry at -e line 1.
  : No such file or directory at -e line 1.

Second using set_path where the parameter is declared as OptString;

  $ perl -MSys::Guestfs -w -e '$g = Sys::Guestfs->new (); $g->set_path (undef);'

One possible bug/improvement here would be to catch the case where
undef is passed to a String parameter, since the implicit conversion of
undef -> "" in Perl is never useful or intentional.

[1] http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=30c091f49dafab4ca9c8b6640d19fc0450b15971
[2] http://git.annexia.org/?p=libguestfs.git;a=blob;f=src/generator.ml;h=d640343e7a407543401dc30c58451f7c6e7a74ae;hb=HEAD#l1258

Comment 8 Fedora Update System 2010-07-01 10:48:39 UTC
libguestfs-1.2.9-1.el5.2 has been submitted as an update for Fedora EPEL 5.
http://admin.fedoraproject.org/updates/libguestfs-1.2.9-1.el5.2

Comment 9 Fedora Update System 2010-07-02 19:27:09 UTC
libguestfs-1.2.9-1.el5.2 has been pushed to the Fedora EPEL 5 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update libguestfs'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/libguestfs-1.2.9-1.el5.2

Comment 10 Jinxin Zheng 2010-07-05 02:50:04 UTC
(In reply to comment #8)
> libguestfs-1.2.9-1.el5.2 has been submitted as an update for Fedora EPEL 5.
> http://admin.fedoraproject.org/updates/libguestfs-1.2.9-1.el5.2    

The aug_clear API is included in this version, so move to VERIFIED.

$ rpm -q libguestfs
libguestfs-1.2.9-1.el5.2

$ guestfish help aug_clear
NAME
    aug-clear - clear Augeas path

SYNOPSIS
     aug-clear augpath

DESCRIPTION
    Set the value associated with "path" to "NULL". This is the same as the
    augtool(1) "clear" command.

Comment 11 Fedora Update System 2010-07-12 11:02:00 UTC
libguestfs-1.2.10-1.el5 has been submitted as an update for Fedora EPEL 5.
http://admin.fedoraproject.org/updates/libguestfs-1.2.10-1.el5

Comment 12 Fedora Update System 2010-07-21 12:22:57 UTC
libguestfs-1.2.10-1.el5 has been pushed to the Fedora EPEL 5 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update libguestfs'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/libguestfs-1.2.10-1.el5

Comment 13 Jinxin Zheng 2010-07-22 11:18:24 UTC
# rpm -q libguestfs
libguestfs-1.2.10-1.el5

# guestfish help aug-clear
NAME
    aug-clear - clear Augeas path

SYNOPSIS
     aug-clear augpath

DESCRIPTION
    Set the value associated with "path" to "NULL". This is the same as the
    augtool(1) "clear" command.

Move to VERIFIED again..

Comment 14 Fedora Update System 2010-08-17 22:11:55 UTC
libguestfs-1.2.11-1.2.el5 has been submitted as an update for Fedora EPEL 5.
http://admin.fedoraproject.org/updates/libguestfs-1.2.11-1.2.el5

Comment 15 Fedora Update System 2010-08-19 21:59:06 UTC
libguestfs-1.2.11-1.2.el5 has been pushed to the Fedora EPEL 5 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update libguestfs'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/libguestfs-1.2.11-1.2.el5

Comment 16 Jinxin Zheng 2010-08-20 02:31:27 UTC
# rpm -q libguestfs
libguestfs-1.2.11-1.2.el5

# guestfish help aug-clear
NAME
    aug-clear - clear Augeas path

SYNOPSIS
     aug-clear augpath

DESCRIPTION
    Set the value associated with "path" to "NULL". This is the same as the
    augtool(1) "clear" command.

# guestfish -i test.img
...
><fs> aug-get /files/etc/passwd/root/home
/root
><fs> aug-clear /files/etc/passwd/root/home
><fs> aug-get /files/etc/passwd/root/home
libguestfs: error: aug_get: Augeas returned NULL match

According to the test above, the aug_clear API is verified to effectively erase a value associated with a node.

Comment 17 Fedora Update System 2010-09-03 21:56:32 UTC
libguestfs-1.2.11-1.2.el5 has been pushed to the Fedora EPEL 5 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.