Proper implementation of USB detection on Legato


#1

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.


#2

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.


#3

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.


#4

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


#5

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?


#6

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


#7

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?


#8

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.