Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 27 Nov 2014, 10:25
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
hotplug2stdout C program
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7084
Location: Perth, Western Australia

PostPosted: 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
hotplug2stdout.c.gz
Description 
gz

 Download 
Filename  hotplug2stdout.c.gz 
Filesize  804 Bytes 
Downloaded  351 Time(s) 

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Nathan F


Joined: 08 Jun 2005
Posts: 1760
Location: Wadsworth, OH (occasionally home)

PostPosted: Thu 08 May 2008, 21:54    Post subject:  

Thanks Barry.

Nathan

_________________
Bring on the locusts ...
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger 
Everitt

Joined: 19 Dec 2006
Posts: 331
Location: Leeds,UK or Birmingham, UK

PostPosted: 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
View user's profile Send private message 
prit1


Joined: 03 Jan 2008
Posts: 540
Location: Los Angeles

PostPosted: 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. Smile . I really want to brush up my C knowledge.
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7084
Location: Perth, Western Australia

PostPosted: Fri 09 May 2008, 04:35    Post subject:  

Everitt, where is your code? I'm interested in seeing it!
_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Everitt

Joined: 19 Dec 2006
Posts: 331
Location: Leeds,UK or Birmingham, UK

PostPosted: Fri 09 May 2008, 09:04    Post subject:  

Sorry, thought I'd attached it. I'll try again.
hotplug2stdout.c.gz
Description 
gz

 Download 
Filename  hotplug2stdout.c.gz 
Filesize  1.03 KB 
Downloaded  333 Time(s) 
Back to top
View user's profile Send private message 
Everitt

Joined: 19 Dec 2006
Posts: 331
Location: Leeds,UK or Birmingham, UK

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

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
[ Time: 0.0553s ][ Queries: 12 (0.0035s) ][ GZIP on ]