[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] Saving changed tree to file does not work but no error message



Dear Raphaël,

thanks for your reply and your patience.
Unfortunately I couldn’t solve my problem yet; thus, I will provide here further information.

If I use augtool, I can change the value of the node and also save the changes to the config file. So, this works fine.
I created a shell script (in the folder src) which executes all the individual commands.
Here the output of the shell script:
=========================================START
pi raspberrypi ~/AugeasDemoC $ sudo sh ./src/equivalentAugtoolCommands.sh 
/augeas/load
/augeas/load/Interfaces
/augeas/load/Interfaces/lens = "Interfaces.lns"
/augeas/load/Interfaces/incl = "/home/pi/AugeasDemoC/network/interfaces"
Saved 1 file(s)
/augeas/events/saved = "/files/home/pi/AugeasDemoC/network/interfaces“
=========================================END

In contrast, the C++ program does not save the changed node value back to the file. However, the program does not give any error message.
Here the output of the program:

=========================================START
pi raspberrypi ~/AugeasDemoC $ ./augeasDemo 
Execution path is: /home/pi/AugeasDemoC/network/interfaces/

Here we start the initialization.
Set lens: 0
Set incl: 0
Load augeas: 0
Number of errors: 0

Here we start searching for a specific node.
Number of matches: 3
The following paths have been found:
/files/home/pi/AugeasDemoC/network/interfaces/iface[1]
/files/home/pi/AugeasDemoC/network/interfaces/iface[2]
/files/home/pi/AugeasDemoC/network/interfaces/iface[3]
Interface number of wlan0: 3

Here we start changing the value of the node.
Set value: 0
Augeas version: 1.4.0
The value read from node: dhcp <<<<——— That means the value has been changed.

Here we start saving changes back to files.
Save mode set: 0
File saved: 0
Number of stored files: 0
Number of errors: 0
Return: 0
=========================================END

All the code can be found here: https://github.com/cmolitor/AugeasDemoC/tree/simple

I really have no idea what I am doing wrong and I am really grateful for suggestions and help.
Excuse also my not so nice programming style as I am not a professional programmer. Suggestions are welcome as well. I will have a look at the xpath in the next steps.

Cheers,
Christoph
 


Am 11.01.2016 um 09:38 schrieb Raphaël Pinson <raphael pinson camptocamp com>:

Hello Christoph,



On Sun, Jan 10, 2016 at 6:09 PM, Christoph Molitor <christoph molitor googlemail com> wrote:
Hello Raphaël,

thanks for your reply and your suggestions.
I added some code to read the error messages. 
When I execute the code there are no error messages but still the changes made to the value of one node are not saved back to the configuration file.
The latest source code can be found here:


You need to really look into how to use XPath in Augeas. You can remove pretty much all of https://github.com/cmolitor/AugeasDemoC/blob/simple/src/main.cpp#L93-L111 (and probably more) by using proper XPath expressions instead of manually parsing the tree node by node.


Also, Augeas 1.0.0 introduced aug_transform, which is easier/better than manually manipulating nodes in /augeas/load.

 

I also went through all the steps using augtool and added the commands as comments to the source code.
If I execute the commands in augtool the changes are saved to the configuration file.

In general, I can load the configuration file, change the value, check that the value has been really changed by reading it again. Calling aug_save() does not give an error message but still the changes are not saved to the file.


And what is the output of your code then?

 
I tried this with augeas version 1.2 and 1.4.

It would be great if I could get further advice how to proceed or a hint what I am doing wrong.

I will also have a look at netcf but could not find a detailed documentation yet.


netcf has been used for a few years in libvirt. See https://github.com/saaros/libvirt/blob/master/src/interface/interface_backend_netcf.c for example.



Cheers,

Raphaël


 
Am 04.01.2016 um 09:44 schrieb Raphaël Pinson <raphael pinson camptocamp com>:

Hello Christoph and happy new year to you too!


Your code doesn't check for errors (either parsing or saving errors). You could add checks (looking for `/augeas//error` nodes) just after your call to aug_load (for parsing errors) and to aug_save (for saving errors).

One way to debug your code would also be to try it with augtool, which would be easier to debug.

Also, are you aware of the netcf project, which provides a higher API on top of Augeas to access and modify /etc/network/interfaces?



Cheers,

Raphaël





On Fri, Jan 1, 2016 at 5:05 PM, Christoph Molitor <christoph molitor googlemail com> wrote:
Dear all,

first of all a happy new year to everyone.

I am trying to use the augeas C API to apply changes to the "/etc/network/interfaces" file.
So far I was able to apply changes to the tree. However, I am not able to save the changes back to the file.
First, I thought it is a problem with the permissions. However, I copied the interfaces file to a different folder and it still does not work.
Using the command line tool augtool, I am able to make the changes and save them to the file.

I uploaded an (almost) minimal version of my program to:
https://github.com/cmolitor/AugeasDemoC

The repository includes an example „interfaces“.
I am working on a Raspberry Pi with Raspbian Jessie.
It would be great if someone could give me a hint what I am doing work and where the problem might come from.

Thanks for your support!

Christoph

_______________________________________________
augeas-devel mailing list
augeas-devel redhat com
https://www.redhat.com/mailman/listinfo/augeas-devel



--
Raphaël Pinson
Infrastructure Developer & Training Leader
+33 458 482 013

Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com




--
Raphaël Pinson
Infrastructure Developer & Training Leader
+33 458 482 013

Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]