Lighweight pup_event_frontend_d Replacement

Under development: PCMCIA, wireless, etc.
Message
Author
User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

Lighweight pup_event_frontend_d Replacement

#1 Post 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:
Attachments
part-hotplug-handler.tar.bz2
(2.63 KiB) Downloaded 547 times
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#2 Post by sc0ttman »

Nice, how does this differ from the 'pup-volume-monitor' and its 'desktop-icons' util..? Can you provide a comparison?
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#3 Post 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.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post 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) .
«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 :P

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#5 Post 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.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#6 Post 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 .

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#7 Post 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.

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#8 Post 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.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#9 Post 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.

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#10 Post 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.
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#11 Post 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.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#12 Post 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:

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#13 Post by Iguleder »

So inefficient! :lol:

The second pipe is redundant.

Code: Select all

grep "$MntPt" /proc/mounts | cut -f 1 -d ' '
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#14 Post 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

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#15 Post 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

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#16 Post 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.
Attachments
part-what.jpg
(21.19 KiB) Downloaded 704 times
«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 :P

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#17 Post 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 .
«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 :P

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#18 Post by musher0 »

Hi, iguleder.

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

Thanks in advance and best regards.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#19 Post 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
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#20 Post 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 :)
Attachments
udevadm_trigger.jpg
(35.92 KiB) Downloaded 620 times

Post Reply