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 Fri 21 Nov 2014, 15:10
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 Posts_count  
Author Message
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7081
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_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 YIM MSNM 
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: 7081
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_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  332 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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0546s ][ Queries: 12 (0.0040s) ][ GZIP on ]