Proper implementation of USB detection on Legato

Hello,

My idea is to detect when a USB flash memory is connected and to copy logs (from logread) to it.
For now I have two issues:

  • Detection of USB flash memory

  • Copying log to USB flash memory

I tried making an app that would poll if /dev/sda exists, but that would require access to /dev/sda file trough sandbox which isn’t possible to put into adef because it only exists when USB is mouted.

Questions:

  1. What would be the right way to do this?
  2. Would it be possible without editing existing linux kernel?
  3. Does Legato provide a way to add udev rules like on Ubuntu?

Thanks in advance.

How about writing a script to check if the /dev/sda exists?
After that you can use logread in the script to copy file to usb drive.

In order to be able to check if /dev/sda exists I need to have permission to read /dev/sda file.
In order to do so I have to define the in .adef file of my application. When the application is started if /dev/sda isn’t present application won’t be able to start.

Yoy can use a linux a script to check or you can disable the sandbox feature.

As I understood disabling sandbox is a security risk?
And if i would do it trough a linux script how would I make it run at startup without modifying kernel?

You can modify those init script in/etc/init.d to run your script.

Thank you for the hints, I would know how to do this with regular linux distribution and udev/init.d combination. However, we want to use SierraWireless provided SPK file without modifications of kernel and rootfs and have only access to legato framework. Can you help?

I have no idea on udev. But I saw the link below saying we can use mdev instead. You can have a try.

BTW, if you only want to use legato application, you need to first write a shell script to periodically checking if the new USB storage has been inserted (/dev/sda).
Also this script will mount the USB drive and write the logread to USB drive in case /dev/sda is found.
e.g.


/bin/mount -t auto -o sync /dev/sda1 "/tmp/usbflash”
logread > /tmp/usbflash
umount /tmp/usbflash


After that you need to write a unsandboxed application which using system() API to call this script during when legato system starts.

1 Like

Here is what I did at the end:

I have modified /mnt/flash/ufs/etc/mdev.conf by adding line:

sd[a-z][0-9]? 0:0 660 @(echo $MDEV > /tmp/usb_det; /legato/systems/current/bin/app start Log2USB)

This line instructs mdev mechanism to save detected disk device name to temp file (e.g. sda1) and to start unsandboxed legato application Log2USB when USB disk is inserted. Log2USB application executes shell script which mounts, copies logs and unmounts disk.

Only drawback for this solution is that /etc/mdev.conf file must be edited which is sometimes not handy (e.g. spk update in the field).

Can you write an unsandboxed application to modify the mdev.conf filr?