<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Dear Raphaël,<div><br></div><div>thanks for your reply and your patience.</div><div>Unfortunately I couldn’t solve my problem yet; thus, I will provide here further information.</div><div><br></div><div>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.</div><div>I created a shell script (in the folder src) which executes all the individual commands.</div><div>Here the output of the shell script:</div><div>=========================================START</div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="color: #34bd26"><b>pi@raspberrypi</b></span> <span style="color: #5330e1"><b>~/AugeasDemoC $</b></span> sudo sh ./src/equivalentAugtoolCommands.sh </div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/augeas/load</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/augeas/load/Interfaces</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/augeas/load/Interfaces/lens = "Interfaces.lns"</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/augeas/load/Interfaces/incl = "/home/pi/AugeasDemoC/network/interfaces"</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Saved 1 file(s)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/augeas/events/saved = "/files/home/pi/AugeasDemoC/network/interfaces“</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="font-family: Helvetica; font-size: 12px;">=========================================END</span></div><div><br></div><div>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.</div><div>Here the output of the program:</div><div><br></div><div>=========================================START</div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="color: #34bd26"><b>pi@raspberrypi</b></span> <span style="color: #5330e1"><b>~/AugeasDemoC $</b></span> ./augeasDemo </div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Execution path is: /home/pi/AugeasDemoC/network/interfaces/</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Here we start the initialization.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Set lens: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Set incl: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Load augeas: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Number of errors: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Here we start searching for a specific node.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Number of matches: 3</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">The following paths have been found:</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/files/home/pi/AugeasDemoC/network/interfaces/iface[1]</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/files/home/pi/AugeasDemoC/network/interfaces/iface[2]</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">/files/home/pi/AugeasDemoC/network/interfaces/iface[3]</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Interface number of wlan0: 3</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Here we start changing the value of the node.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Set value: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Augeas version: 1.4.0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">The value read from node: dhcp<span class="Apple-tab-span" style="white-space:pre">    </span><<<<——— That means the value has been changed.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Here we start saving changes back to files.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Save mode set: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">File saved: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Number of stored files: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Number of errors: 0</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Return: 0</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><div style="font-family: Helvetica; font-size: 12px;">=========================================END</div><div style="font-family: Helvetica; font-size: 12px;"></div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">All the code can be found here: <a href="https://github.com/cmolitor/AugeasDemoC/tree/simple">https://github.com/cmolitor/AugeasDemoC/tree/simple</a></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">I really have no idea what I am doing wrong and I am really grateful for suggestions and help.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">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.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Cheers,</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Christoph</div><div> </div><div><br></div><div><br><div><div>Am 11.01.2016 um 09:38 schrieb Raphaël Pinson <<a href="mailto:raphael.pinson@camptocamp.com">raphael.pinson@camptocamp.com</a>>:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hello Christoph,<div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 10, 2016 at 6:09 PM, Christoph Molitor <span dir="ltr"><<a href="mailto:christoph.molitor@googlemail.com" target="_blank">christoph.molitor@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Hello Raphaël,<div><br></div><div>thanks for your reply and your suggestions.</div><div>I added some code to read the error messages. </div><div>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.</div><div>The latest source code can be found here:</div><div><a href="https://github.com/cmolitor/AugeasDemoC/blob/simple/src/main.cpp" target="_blank">https://github.com/cmolitor/AugeasDemoC/blob/simple/src/main.cpp</a></div></div></blockquote><div><br></div><div><br></div><div>You need to really look into how to use XPath in Augeas. You can remove pretty much all of <a href="https://github.com/cmolitor/AugeasDemoC/blob/simple/src/main.cpp#L93-L111">https://github.com/cmolitor/AugeasDemoC/blob/simple/src/main.cpp#L93-L111</a> (and probably more) by using proper XPath expressions instead of manually parsing the tree node by node.</div><div><br></div><div><br></div><div>Also, Augeas 1.0.0 introduced aug_transform, which is easier/better than manually manipulating nodes in /augeas/load.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>I also went through all the steps using augtool and added the commands as comments to the source code.</div><div>If I execute the commands in augtool the changes are saved to the configuration file.</div><div><br></div><div>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.</div><div><br></div></div></blockquote><div><br></div><div>And what is the output of your code then?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div></div><div>I tried this with augeas version 1.2 and 1.4.</div><div><br></div><div>It would be great if I could get further advice how to proceed or a hint what I am doing wrong.</div><div><br></div><div>I will also have a look at netcf but could not find a detailed documentation yet.</div><div><br></div></div></blockquote><div><br></div><div>netcf has been used for a few years in libvirt. See <a href="https://github.com/saaros/libvirt/blob/master/src/interface/interface_backend_netcf.c">https://github.com/saaros/libvirt/blob/master/src/interface/interface_backend_netcf.c</a> for example.</div><div><br></div><div><br></div><div><br></div><div>Cheers,</div><div><br></div><div>Raphaël</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div class="h5"><div><div>Am 04.01.2016 um 09:44 schrieb Raphaël Pinson <<a href="mailto:raphael.pinson@camptocamp.com" target="_blank">raphael.pinson@camptocamp.com</a>>:</div><br><blockquote type="cite"><div dir="ltr">Hello Christoph and happy new year to you too!<div><br></div><div><br></div><div>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).</div><div><br></div><div>One way to debug your code would also be to try it with augtool, which would be easier to debug.</div><div><br></div><div>Also, are you aware of the netcf project, which provides a higher API on top of Augeas to access and modify /etc/network/interfaces?</div><div><br></div><div><br></div><div><br></div><div>Cheers,</div><div><br></div><div>Raphaël</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 1, 2016 at 5:05 PM, Christoph Molitor <span dir="ltr"><<a href="mailto:christoph.molitor@googlemail.com" target="_blank">christoph.molitor@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Dear all,<br><br>first of all a happy new year to everyone.<br><br>I am trying to use the augeas C API to apply changes to the "/etc/network/interfaces" file.<br>So far I was able to apply changes to the tree. However, I am not able to save the changes back to the file.<br>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.<br>Using the command line tool augtool, I am able to make the changes and save them to the file.<br><br>I uploaded an (almost) minimal version of my program to:<br><a href="https://github.com/cmolitor/AugeasDemoC" target="_blank">https://github.com/cmolitor/AugeasDemoC</a><br><br>The repository includes an example „interfaces“.<br>I am working on a Raspberry Pi with Raspbian Jessie.<br>It would be great if someone could give me a hint what I am doing work and where the problem might come from.<br><br>Thanks for your support!<span><font color="#888888"><br><br>Christoph</font></span></div><br>_______________________________________________<br>
augeas-devel mailing list<br>
<a href="mailto:augeas-devel@redhat.com" target="_blank">augeas-devel@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/augeas-devel" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/augeas-devel</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div dir="ltr">Raphaël Pinson<div>Infrastructure Developer & Training Leader</div><div>+33 458 482 013<div><br></div><div>Camptocamp France<br>
Savoie Technolac<br>
BP 352<br>
48, avenue du Lac du Bourget<br>
73372 Le Bourget du Lac, Cedex<br>
<a href="http://www.camptocamp.com/" target="_blank">www.camptocamp.com</a><br>
</div></div></div></div></div>
</div>
</blockquote></div><br></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div dir="ltr">Raphaël Pinson<div>Infrastructure Developer & Training Leader</div><div>+33 458 482 013<div><br></div><div>Camptocamp France<br>
Savoie Technolac<br>
BP 352<br>
48, avenue du Lac du Bourget<br>
73372 Le Bourget du Lac, Cedex<br>
<a href="http://www.camptocamp.com/" target="_blank">www.camptocamp.com</a><br>
</div></div></div></div></div>
</div></div></div>
</blockquote></div><br></div></body></html>