The time now is Wed 22 May 2013, 07:06
All times are UTC - 4 |
| Author |
Message |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6856 Location: Perth, Western Australia
|
Posted: Thu 08 May 2008, 19:58 Post subject:
hotplug2stdout C program |
|
I have introduced this on my blog, see posts circa May 8 and 9 2008.
A couple of guys have expressed an interest in the code, so attached.
I compiled it like this:
# gcc -o hotplug2stdout hotplug2stdout.c
| Description |
|

Download |
| Filename |
hotplug2stdout.c.gz |
| Filesize |
804 Bytes |
| Downloaded |
311 Time(s) |
_________________ http://bkhome.org/blog2/
|
|
Back to top
|
|
 |
Nathan F

Joined: 08 Jun 2005 Posts: 1641 Location: Wadsworth, OH (occasionally home)
|
Posted: Thu 08 May 2008, 21:54 Post subject:
|
|
Thanks Barry.
Nathan
_________________ _________________________________________
Bring on the locusts ...
|
|
Back to top
|
|
 |
Everitt
Joined: 19 Dec 2006 Posts: 331 Location: Leeds,UK or Birmingham, UK
|
Posted: Thu 08 May 2008, 22:17 Post subject:
|
|
Hmm, that is really, really weird!
I've been playing with the code, and to be honest I really don't know enough about computers to tell what's going on. If we pass a load of data through the pipe * then the output seems perfectly reliable for my 4in1 card reader or my single flash disk. I sujest this might mean that the output is being buffered, and only let through in packets of a certain size (which makes sense in someways) Seems unlikely though.
Perhaps though... Haha, I love moments like this, when you hit on something whilst posting...
It would seem, that flushing the stdout buffer using fflush causes it to behave! Seems ok for the two devices I listed above. I'll attach the source code below. *crosses fingers*
* | Code: | printf("\nNICELONGSTRINGHEREASAFORMOFTESTOHGODITSSOHARDTOTYPEWITHOUTADDINGSPACESORPUNCTUATIONNICELONGSTRINGHEREASAFORMOFTESTOHGODITSSOHARDTOTYPEWITHOUTADDINGSPACESORPUNCTUATION\n");
printf("\nNICELONGSTRINGHEREASAFORMOFTESTOHGODITSSOHARDTOTYPEWITHOUTADDINGSPACESORPUNCTUATIONNICELONGSTRINGHEREASAFORMOFTESTOHGODITSSOHARDTOTYPEWITHOUTADDINGSPACESORPUNCTUATION\n"); |
|
|
Back to top
|
|
 |
prit1

Joined: 03 Jan 2008 Posts: 540 Location: Los Angeles
|
Posted: Fri 09 May 2008, 00:25 Post subject:
|
|
@Barry: I am not really familiar with the internals and have not written any C code in the last 8 years or more. But I did compile and run the code you provided and it was really interesting to see the add@, remove@ etc coming up. I tried multiple USB's several times and it kept picking up the signal everytime. Thanks for provoking interest in people like me. . I really want to brush up my C knowledge.
|
|
Back to top
|
|
 |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6856 Location: Perth, Western Australia
|
Posted: Fri 09 May 2008, 04:35 Post subject:
|
|
Everitt, where is your code? I'm interested in seeing it!
_________________ http://bkhome.org/blog2/
|
|
Back to top
|
|
 |
Everitt
Joined: 19 Dec 2006 Posts: 331 Location: Leeds,UK or Birmingham, UK
|
Posted: Fri 09 May 2008, 09:04 Post subject:
|
|
Sorry, thought I'd attached it. I'll try again.
| Description |
|

Download |
| Filename |
hotplug2stdout.c.gz |
| Filesize |
1.03 KB |
| Downloaded |
291 Time(s) |
|
|
Back to top
|
|
 |
Everitt
Joined: 19 Dec 2006 Posts: 331 Location: Leeds,UK or Birmingham, UK
|
Posted: Fri 09 May 2008, 15:16 Post subject:
|
|
Barry, futher to my many, many posts on your blog, here's a proof of concept for your consideration.
It both runs the hotplug2stdout deamon, and keeps a constant eye on a file /var/mnt. When hotplug2stdout has something to report it is passed to the while loop, and when the file /var/mnt is changed somehow (open, modified, whatever) it's contents is passed to the loop.
| Code: | ( hotplug2stdout & while [ 1 ]; do inotifywait /var/mnt &>/dev/null & cat /var/mnt;done ) | while read ONE
do
echo "$ONE";
done |
It's a pretty messy solution to the problem, but, as far as I can tell, avoids polling, and is similar to the solution you put on your blog. I'm wondering if it isn't worth making the updates to /var/mnt (made by (u)mount) similar in format to the kernel uevents, and putting this in a script. That way it should be pretty easy to get the output into any program that needs it.
Just an idea I've been playnig with. I hope it's of some use to you.
|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|