2009-07-23 03:01:51     detection of USB from the multithreaded user space application

Document created by Aaronwu Employee on Aug 16, 2013
Version 1Show Document
  • View in full screen mode

2009-07-23 03:01:51     detection of USB from the multithreaded user space application

sugumar natarajan (INDIA)

Message: 77904   

 

Dear Mike,

 

     We  are working on a user space application to access the USB. The application is  a multithreaded one.The user space application should be able to know if the usb is inserted or removed.we have already made queries regarding this on the  forum and is working for  an user space application with single process.Thanks for the same.The issue is with the multithreaded application only.

 

This is the script file that would be executed on USB insertion or removal.

 

#!/bin/sh

output=/dev/ttyBF0

/bin/mdev > $output

echo $DEVPATH | grep sda

if [ $? -ne 0 ]

then

exit 0

fi

echo "Hotplug Script" > $output

echo $ACTION > $output

if [ "${ACTION}" = "add" ] ;then

echo "USB Inserted" > $output

mount -t vfat /dev/sda /mnt

killall -USR2 ADMTV315

fi

if [ "${ACTION}" = "remove" ] ;then

echo "USB Remove" > $output

umount /dev/sda

killall -USR2 ADMTV315

fi

echo "Hotplug Script End" > $output

 

We thought of keeping  a flag in the user space application(inside the signal handler function) and toggle the same whenever signal handler function is called  .But the problem is since the application is a multithreaded application ,the signal handler is called as many times as the no of process.

 

Please suggest on how to send the signal to a particular user space process .Please suggest if there is any other way of doing the same.

 

Thanks and regards,

 

N.sugumar

QuoteReplyEditDelete

 

 

2009-07-23 03:08:03     Re: detection of USB from the multithreaded user space application

Mike Frysinger (UNITED STATES)

Message: 77905   

 

so use pthread_sigmask() or something similar to block the signal from all but one thread

QuoteReplyEditDelete

 

 

2009-07-23 07:30:17     Re: detection of USB from the multithreaded user space application

sugumar natarajan (INDIA)

Message: 77952   

 

Dear Mike,

 

           Thanks for your suggestion.But the pthread_sigmask function can be used  only when the signal is sent from some other process,whereas in my case the signal is sent from hot plug script.We have not worked much on the kernel side ie process and signals.So could you please provide some more information.Please provide the references to the documents if any.

 

Thanks and regards,

 

N.sugumar

QuoteReplyEditDelete

 

 

2009-07-23 10:12:05     Re: detection of USB from the multithreaded user space application

Mike Frysinger (UNITED STATES)

Message: 77964   

 

that doesnt make any sense.  the script, when executed, *is another process*.  it isnt "the kernel".  even if it was, signal semantics would most likely be exactly the same.

QuoteReplyEditDelete

 

 

2009-07-23 21:34:53     Re: detection of USB from the multithreaded user space application

sugumar natarajan (INDIA)

Message: 77981   

 

Dear Mike,

 

        Thanks for your inputs.now i got the point.

 

Regards,

 

N.Sugumar

QuoteReplyEditDelete

 

 

2009-07-30 07:28:22     Re: detection of USB from the multithreaded user space application

sugumar natarajan (INDIA)

Message: 78197   

 

Dear Mike,

 

                  Thanks for your inputs.We have used the pthread_sigmask and were able to sucessfully process the signal.But we have still some issues.During testing we found that some usb device are detected as sda and others  as sda1,sdb,etc..How can we know whether the usb device is detected as sda or sdb ? so that the file system can be mounted on the particular device. for eg  we have the following hot plug script.(please see below highlighed one)

 

here only the device detected as sda will be mounted.Can by anyway i could know whether the device is detected as sda,sdb.....

 

We tried the following also,(mentioned in the other thread and also according to our understanding)

 

mount -vfat  $DEVPATH    /mnt

 

This also failed. i checked the value of     $DEVPATH  and these are the values.

 

1.512 m b transend  /block/sda -(hotplug called only one time).

 

2.8mb transend  (hotplug called 2 times)

 

/block/sda/

 

/block/sda/sda1/

 

 

 

hotplug script:

 

#!/bin/sh

output=/dev/ttyBF0

/bin/mdev > $output

echo $DEVPATH | grep sda

if [ $? -ne 0 ]

then

exit 0

fi

echo "Hotplug Script" > $output

echo $ACTION > $output

if [ "${ACTION}" = "add" ] ;then

echo "USB Inserted" > $output

echo $DEVPATH >>devpath

mount -t vfat /dev/sda /mnt

#mount -t vfat /dev/sda /mnt/usb

killall -USR2 ADMTV315

 

So please let us know how to determine if the device is detected as sda,sda1,sdb....

 

Kindly give your inputs.

 

thanks and regards,

 

N.sugumar

QuoteReplyEditDelete

 

 

2009-08-03 00:58:05     Re: detection of USB from the multithreaded user space application

Sonic Zhang (CHINA)

Message: 78284   

 

That depends on the partitions created on your usb memory stick and if you have other disk devices in your system.

QuoteReplyEditDelete

 

 

2009-08-03 23:31:40     Re: detection of USB from the multithreaded user space application

Mike Frysinger (UNITED STATES)

Message: 78327   

 

run `env` to see the complete environment that the kernel populates for you

Attachments

    Outcomes