Page 1 of 3

Lighweight pup_event_frontend_d Replacement

Posted: Sat 25 May 2013, 12:57
by Iguleder
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! :D

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

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:

Posted: Sat 25 May 2013, 13:07
by sc0ttman
Nice, how does this differ from the 'pup-volume-monitor' and its 'desktop-icons' util..? Can you provide a comparison?

Posted: Sat 25 May 2013, 13:22
by Iguleder
- 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? :P
- 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.

Posted: Sat 25 May 2013, 15:49
by Karl Godt
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) .

Posted: Sat 25 May 2013, 16:30
by Iguleder
You can always use mount and grep ... but we're after a clean and efficient solution, aren't we? :D

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

Posted: Sat 25 May 2013, 16:51
by Karl Godt
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 .

Posted: Sat 25 May 2013, 18:20
by akash_rawal
Tried it.

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

Well commented and easy to read code too :)

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.

Posted: Sat 25 May 2013, 18:33
by Iguleder
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.

Posted: Sat 25 May 2013, 19:25
by akash_rawal
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 :)
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.

Posted: Sat 25 May 2013, 19:29
by jamesbond
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.

Posted: Sat 25 May 2013, 19:41
by akash_rawal
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.

Posted: Sun 26 May 2013, 00:20
by Karl Godt
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 ' ')"
:cry: :lol:

Posted: Mon 27 May 2013, 05:56
by Iguleder
So inefficient! :lol:

The second pipe is redundant.

Code: Select all

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

Posted: Mon 27 May 2013, 16:55
by Karl Godt
And problematic if spaces in filename

Code: Select all

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

Posted: Mon 27 May 2013, 18:09
by Karl Godt
First Success in Compiling on Puppy-4.3 :
http://pkgs.fedoraproject.org/repo/pkgs ... 56d59ddd5/

141 was missing udev_monitor_filter_add_match_subsystem_devtype

Code: Select all

# 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

Posted: Mon 27 May 2013, 18:45
by Karl Godt
first snap as frontend?d renamed fronend?d.sh and part-what cp as /sbin/pup_event_frontgend_d, restarted new udevd, restarted X, plugged in sd card in usb-reader .

Nice. probably let it be as it is . Needs the add part of rc.sysinit to show internal drives I guess.

Posted: Mon 27 May 2013, 20:38
by Karl Godt
myself wrote:Needs the add part of rc.sysinit to show internal drives I guess.
Nope,
did not work ( kernel 2.6.30.5 ) to trigger pdeskdrived which I think would be a good name for part-hotplug-handler to show all internal and external drives .

For now it is a partial drive handler .

Posted: Tue 28 May 2013, 03:27
by musher0
Hi, iguleder.

Where do these utilities go? Alternately, would a *.pet be useful?

Thanks in advance and best regards.

musher0

Posted: Tue 28 May 2013, 06:46
by jamesbond
Karl Godt wrote:
myself wrote:Needs the add part of rc.sysinit to show internal drives I guess.
Nope,
did not work ( kernel 2.6.30.5 ) to trigger pdeskdrived which I think would be a good name for part-hotplug-handler to show all internal and external drives .

For now it is a partial drive handler .
Run this after you run the handler. You should get all the internal drives displayed.

Code: Select all

for p in $(ls /sys/class/block | grep -Ev ^ram|^loop); do
udevadm trigger --action=add --sysname-match=$p
done

Posted: Tue 28 May 2013, 13:02
by Karl Godt
142 complains about trigger: unrecognized option `--sysname-match='

what works is something like udevadm trigger /block/sda

Looking good so far . Just needs the Icons :)