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 Tue 02 Sep 2014, 06:20
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Lighweight pup_event_frontend_d Replacement
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [41 Posts]   Goto page: 1, 2, 3 Next
Author Message
Iguleder


Joined: 11 Aug 2009
Posts: 1890
Location: Israel, somewhere in the beautiful desert

PostPosted: Sat 25 May 2013, 08:57    Post subject:  Lighweight pup_event_frontend_d Replacement
Subject description: An example for a lighweight, udev-based pup_event_frontend_d replacement
 

Hello guys, here's something I wrote: part-hotplug-handler.

As you know, I hate pup_event_frontend_d and want it to be replaced with a lightweight, udev-based replacement written in C.

So ... here's an example! Very Happy

Currently, it detects partitions well, but the desktop icons are created in an endless column starting at (32, 32) Laughing

The architecture is modular:
- part-hotplug-handler is a process that should run once the user logs in. Build it with gcc -ludev part-hotplug-handler.c -o part-hotplug-handler. Whenever a partition is added or removed, it runs part-icon. It knows when things happen using udev's API.
- part-icon is a simple script that creates or removes desktop icons using ROX-Filer's XML RPC.
- mount-and-open is nothing but a script executed once the user clicks a desktop icon created by part-icon. This script mounts the partition and opens a ROX-Filer window.

Comments, ideas, anyone? Idea
part-hotplug-handler.tar.bz2
Description 
bz2

 Download 
Filename  part-hotplug-handler.tar.bz2 
Filesize  2.63 KB 
Downloaded  266 Time(s) 

_________________
My homepage
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
sc0ttman


Joined: 16 Sep 2009
Posts: 2376
Location: UK

PostPosted: Sat 25 May 2013, 09:07    Post subject:  

Nice, how does this differ from the 'pup-volume-monitor' and its 'desktop-icons' util..? Can you provide a comparison?
_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send private message 
Iguleder


Joined: 11 Aug 2009
Posts: 1890
Location: Israel, somewhere in the beautiful desert

PostPosted: Sat 25 May 2013, 09:22    Post subject:  

- Previous solutions are polling, this one isn't. They just sleep for a given amount of time (a few seconds), then check /sys or whatever to find new partitions.
- Previous solutions are nothing but shell scripts. They do that polling using executables (for example, find, grep, cut, whatever), which is waaaaay heavier than using a function. This rule is true for any programming language (e.g in Python, using cat and popen() instead of of opening a file and reading it, is much slower).
- udev already knows which partitions exist, so previous solutions just "learn" this information again. This is incredibly inefficient and ugly. If udev knows all this, why don't we just ask it? Razz
- This thingy doesn't replace pup-volume-monitor, which is makes it possible to see partitions in file manager. It only creates desktop icons, but you could merge the two.

_________________
My homepage
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Sat 25 May 2013, 11:49    Post subject:  

pup_event_frontend_d had cost me some teeth, too :BIG LOL:

Iguleder,
looking at it, mount-and-open should replace drive_all .

Not sure if mountpoint is included in Puppies by default, probably a busybox applet ?

A small hint : Never had any problems with mount to automatically detect the fs type until recent times, but shortly had some troubles with partitions being incorrectly assumed (jfs,ext4) .

_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message Visit poster's website 
Iguleder


Joined: 11 Aug 2009
Posts: 1890
Location: Israel, somewhere in the beautiful desert

PostPosted: Sat 25 May 2013, 12:30    Post subject:  

You can always use mount and grep ... but we're after a clean and efficient solution, aren't we? Very Happy

And yes - I agree; recent versions of mount are pretty good at guessing. guess_fstype, disktype and all those crappy hacks can be dropped.

_________________
My homepage
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Sat 25 May 2013, 12:51    Post subject:  

Quote:
mountpoint: btrfs fix. By Vladimir Dronnikov (dronnikov AT gmail.com)

already since Lupu 1.16 http://busybox.net/oldnews.html

There should be a enable everything busybox in the initrd.lz and be copied like the kernel drivers into the /pup_new/bin directory. At least I will do that if I manage to kick my ass, which rarely happens .

Iguleder wrote:
... but we're after a clean and efficient solution, aren't we? Very Happy


Your squeeze-pup 005 from anno 2010 has the mountpoint full binary as I found out . Still runs on atom D525 . Very Happy .
Back to top
View user's profile Send private message Visit poster's website 
akash_rawal

Joined: 25 Aug 2010
Posts: 232
Location: ISM Dhanbad, Jharkhand, India

PostPosted: Sat 25 May 2013, 14:20    Post subject:  

Tried it.

Works very well for first attempt. And much faster than anything else Smile

Well commented and easy to read code too Smile

A small tip: At part-hotplug-handler.c:136, If you aren't planning to add more file descriptors you can remove the select() function call and save an overhead of one system call.
Back to top
View user's profile Send private message 
Iguleder


Joined: 11 Aug 2009
Posts: 1890
Location: Israel, somewhere in the beautiful desert

PostPosted: Sat 25 May 2013, 14:33    Post subject:  

Nope, cannot do this - I want the process to be blocked by a system call until an event occurs (e.g so the process gets skipped by the scheduler, instead of wasting CPU cycles - that's the main benefit compared to a script).

I tried to set O_ASYNC on the file descriptor, but for some reason it does not emit SIGIO.

_________________
My homepage
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
akash_rawal

Joined: 25 Aug 2010
Posts: 232
Location: ISM Dhanbad, Jharkhand, India

PostPosted: Sat 25 May 2013, 15:25    Post subject:  

Iguleder wrote:

Nope, cannot do this - I want the process to be blocked by a system call until an event occurs (e.g so the process gets skipped by the scheduler, instead of wasting CPU cycles - that's the main benefit compared to a script).

On removing select() stuff, udev_monitor_receive_device() does the blocking job when there's no data to read. That way you do the same task in just one system call than two system calls.

There's no wastage of CPU cycles, there's conservation instead Smile

Iguleder wrote:

I tried to set O_ASYNC on the file descriptor, but for some reason it does not emit SIGIO.

Strange. Probably that's due to BSD features have problems with netlink sockets.

But anyways udev doesn't seem to support asynchronous reading of events. You cannot wait for anything more other than udev events in same thread.
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2134
Location: The Blue Marble

PostPosted: Sat 25 May 2013, 15:29    Post subject:  

Nice contribution as usual, Iguleder.
Just a question - since we already have udevd running in puppy anyway, why don't just use udev rules to create all these Rox icons? That's what I did in earlier Fatdogs.

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
akash_rawal

Joined: 25 Aug 2010
Posts: 232
Location: ISM Dhanbad, Jharkhand, India

PostPosted: Sat 25 May 2013, 15:41    Post subject:  

jamesbond wrote:
Nice contribution as usual, Iguleder.
Just a question - since we already have udevd running in puppy anyway, why don't just use udev rules to create all these Rox icons? That's what I did in earlier Fatdogs.

That'll work better if daemon isn't storing any long-term useful information in memory.

I'm now wondering whether there's a fuel-efficient way of arranging icons so that they don't collide with each other.

The logic is complex enough to drive me away from idea of desktop drive icons.
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Sat 25 May 2013, 20:20    Post subject:  

Surprise .. mountpoint seems to be enabled in Puppy since Lupu 5 in busybox and exists as binary or symlink in /bin .

/usr/sbin/filemnt wrote:
#130223 BK is it already mounted?
MNTEDLOOP="$(cat /proc/mounts | grep "$MntPt" | cut -f 1 -d ' ')"

Crying or Very sad Laughing
Back to top
View user's profile Send private message Visit poster's website 
Iguleder


Joined: 11 Aug 2009
Posts: 1890
Location: Israel, somewhere in the beautiful desert

PostPosted: Mon 27 May 2013, 01:56    Post subject:  

So inefficient! Laughing

The second pipe is redundant.

Code:
grep "$MntPt" /proc/mounts | cut -f 1 -d ' '

_________________
My homepage
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Mon 27 May 2013, 12:55    Post subject:  

And problematic if spaces in filename
Code:
mount-FULL /dev/sda3 /mnt/"s d a 3"
grep 'sda3' /proc/mounts
/dev/sda3 /mnt/s\040d\040a\0403 ext4 rw,relatime,barrier=1,data=ordered 0 0
grep 's d a 3' /proc/mounts
busybox mountpoint /mnt/"s d a 3"
/mnt/s d a 3 is a mountpoint
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Mon 27 May 2013, 14:09    Post subject:  

First Success in Compiling on Puppy-4.3 :
http://pkgs.fedoraproject.org/repo/pkgs/udev/udev-142.tar.bz2/3edc4cf383dccb06d866c5156d59ddd5/

141 was missing udev_monitor_filter_add_match_subsystem_devtype

Code:
# gcc -DLIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE -ludev part-hotplug-handler.c -o part-hotplug-handler
part-hotplug-handler.c:194:2: warning: no newline at end of file
# ldd part-hotplug-handler
   linux-gate.so.1 =>  (0xffffe000)
   libudev.so.0 => /lib/libudev.so.0 (0xb7f45000)
   libc.so.6 => /lib/libc.so.6 (0xb7e4a000)
   /lib/ld-linux.so.2 (0xb7f51000)
# ls -s --block-size=kB !$
ls -s --block-size=kB part-hotplug-handler
8kB part-hotplug-handler
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 3 [41 Posts]   Goto page: 1, 2, 3 Next
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.0858s ][ Queries: 13 (0.0059s) ][ GZIP on ]