cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Example how to configure tmpfs to persist an acquired license

Example how to configure tmpfs to persist an acquired license

fzankl
Member

Hi everyone,

within the docs for license handling there is a note to perists the acquired license to tmpfs to prevent blocked licenses in case of a faulty app state. 
Can anybody provide an example how to configure tmps within snapcraft.yaml so that the id of the acquired license can be persisted by the app? 

Thanks in advance.

Regards,
Fabian

4 REPLIES 4

nickH
Community Moderator
Community Moderator

Hi Fabian, 

you can just use /tmp in your snap as the file location. The snap is then using a for your snap specific /tmp directory, which is a subdirectory of the host’s /tmp. 

I quickly tried it out with the hello.world example of the SDK to make it clearer. I added these lines to the code: 

  // Create and open a file
  std::ofstream MyFile("/tmp/tmpfile.txt");

  // Write something to the file
  MyFile << "Sample Text!";

  // Close the file
  MyFile.close();

 

And then the file was created here (I logged into the ctrlX CORE virtual with ssh): 

nickH_0-1709025565150.png

I did not need to do any changes in the snapcraf.yaml. 

Best regards, 

Nick

Hi Nick,

thanks for your suggestion.
When try to write a file directly to /tmp using a .NET-based application I get an unauthorized access exception (permission denied).
Is there anything else I have to consider?

Regards,
Fabian

nickH
Community Moderator
Community Moderator

I just tested it also from .Net. I used the hello-world sample in .Net from the ctrlX SDK and added these lines: 

 

...

string path = "/tmp/tmpfiledotnet.txt";

// Create the file, or overwrite if the file exists.
using (FileStream fs = File.Create(path))
{
byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
// Add some information to the file.
fs.Write(info, 0, info.Length);
}
...

 

Except for that I did no changes. And it works like expected:2024-02-27_13h22_59.png

 

I tested everything with V2.4 (SDK and virtual ctrlX CORE). Which version did you use?

Hi Nick,

the issue was based on a kind of misconfiguration - everything works as expected.

As an improvement for the documentation:
It might be good for clarification to remove the reference to tmpfs if nothing is required at this point.


Regards,
Fabian

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist