Rewriting pup_event in C

What features/apps/bugfixes needed in a future Puppy
Message
Author
User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#61 Post by jemimah »

akash_rawal wrote:
jemimah wrote: Here's the code for mounting.

Code: Select all

gchar *mntpnt = g_build_filename(PUP_EVENT_MNTPNT, (gchar *) input, NULL);
gchar *cmd = g_strdup_printf("tmount '%s'", vol->unix_dev);
g_mkdir_with_parents(mntpnt, S_IRWXU | S_IRWXG | S_IRWXO);
g_spawn_command_line_sync(cmd, NULL, &stderr_data, &exitcode, &error);
//g_chmod(mntpnt, S_IRWXU | S_IRWXG | S_IRWXO);
g_free(cmd);
The correct code is:

Code: Select all

gchar *mntpnt;
if (vol->label && (g_strcmp0(vol->label, "") != 0))
    mntpnt = g_build_filename(PUP_EVENT_MNTPNT, vol->label, NULL);
else
    mntpnt = g_build_filename(PUP_EVENT_MNTPNT, (gchar *) input, NULL);

Rest of the code remains as original. This will also save you from extra hassle of finding labels.
Thanks, that helps a lot.

I do like to use tmount (which is adapted from drive_all) because it does things like offer to fuser the drive when it can't be unmounted.

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#62 Post by jemimah »

akash_rawal wrote:
jemimah wrote: but for some reason the blkid command returns incomplete output when run from a script called by udev as opposed to the command line. I can't figure out why.
udev removes the entire environment , including PATH variable. You have to re-export it yourself or use full path to blkid.
It's not a PATH issue. Blkid correctly returns info about every drive except the one in question. It's bizarre.

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#63 Post by jemimah »

The daemon crashes when loopback devices are unmounted.

Code: Select all

Volume loop5:
	unix_dev=/dev/loop5
	label=(null)
	fstype=squashfs
	uuid=(null)
	drv_sysname=(null)
	mntpnt=/mnt/+initrd+mnt+dev_save+blender-2.61-i686.sfs
	mntflags = 0 | VOLUME_IS_READ_ONLY
*** glibc detected *** pup-volume-monitor: double free or corruption (fasttop): 0x080762a0 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7552c9d]
/lib/libc.so.6[0xb7554247]
/lib/libc.so.6(cfree+0x62)[0xb7556df2]
/usr/lib/libglib-2.0.so.0(g_free+0x27)[0xb76c35e6]
/usr/lib/libpupevent.so.0(volume_free_mem+0x5c)[0xb766d67c]
pup-volume-monitor[0x804b565]
pup-volume-monitor[0x804bccf]
/usr/lib/libglib-2.0.so.0[0xb76e5cf8]
/usr/lib/libglib-2.0.so.0[0xb76e56db]
/lib/libpthread.so.0[0xb762f02f]
/lib/libc.so.6(clone+0x5e)[0xb75b5d1e]
======= Memory map: ========
08048000-0804d000 r-xp 00000000 07:01 216        /initrd/pup_rw/usr/bin/pup-volume-monitor
0804d000-0804e000 rwxp 00004000 07:01 216        /initrd/pup_rw/usr/bin/pup-volume-monitor
0804e000-08093000 rwxp 00000000 00:00 0          [heap]
b6b00000-b6b21000 rwxp 00000000 00:00 0 
b6b21000-b6c00000 ---p 00000000 00:00 0 
b6cd5000-b6ce1000 r-xp 00000000 07:00 7568       /initrd/pup_ro2/usr/lib/libgcc_s.so.1
b6ce1000-b6ce2000 rwxp 0000b000 07:00 7568       /initrd/pup_ro2/usr/lib/libgcc_s.so.1
b6ce2000-b6ce3000 ---p 00000000 00:00 0 
b6ce3000-b74e5000 rwxp 00000000 00:00 0 
b74e5000-b74e8000 r-xp 00000000 07:00 9932       /initrd/pup_ro2/lib/libuuid.so.1.3.0
b74e8000-b74e9000 rwxp 00002000 07:00 9932       /initrd/pup_ro2/lib/libuuid.so.1.3.0
b74e9000-b7623000 r-xp 00000000 07:00 9861       /initrd/pup_ro2/lib/libc-2.10.1.so
b7623000-b7625000 r-xp 0013a000 07:00 9861       /initrd/pup_ro2/lib/libc-2.10.1.so
b7625000-b7626000 rwxp 0013c000 07:00 9861       /initrd/pup_ro2/lib/libc-2.10.1.so
b7626000-b7629000 rwxp 00000000 00:00 0 
b7629000-b763c000 r-xp 00000000 07:00 9933       /initrd/pup_ro2/lib/libpthread-2.10.1.so
b763c000-b763d000 r-xp 00012000 07:00 9933       /initrd/pup_ro2/lib/libpthread-2.10.1.so
b763d000-b763e000 rwxp 00013000 07:00 9933       /initrd/pup_ro2/lib/libpthread-2.10.1.so
b763e000-b7640000 rwxp 00000000 00:00 0 
b7640000-b7666000 r-xp 00000000 07:00 9865       /initrd/pup_ro2/lib/libm-2.10.1.so
b7666000-b7667000 r-xp 00025000 07:00 9865       /initrd/pup_ro2/lib/libm-2.10.1.so
b7667000-b7668000 rwxp 00026000 07:00 9865       /initrd/pup_ro2/lib/libm-2.10.1.so
b7668000-b766f000 r-xp 00000000 07:01 356        /initrd/pup_rw/usr/lib/libpupevent.so.0.0.0
b766f000-b7670000 rwxp 00006000 07:01 356        /initrd/pup_rw/usr/lib/libpupevent.so.0.0.0
b7670000-b7671000 rwxp 00000000 00:00 0 
b7671000-b7794000 r-xp 00000000 07:00 7492       /initrd/pup_ro2/usr/lib/libglib-2.0.so.0.3200.1
b7794000-b7795000 rwxp 00122000 07:00 7492       /initrd/pup_ro2/usr/lib/libglib-2.0.so.0.3200.1
b7795000-b7796000 rwxp 00000000 00:00 0 
b7796000-b779c000 r-xp 00000000 07:00 9898       /initrd/pup_ro2/lib/librt-2.10.1.so
b779c000-b779d000 r-xp 00005000 07:00 9898       /initrd/pup_ro2/lib/librt-2.10.1.so
b779d000-b779e000 rwxp 00006000 07:00 9898       /initrd/pup_ro2/lib/librt-2.10.1.so
b779e000-b779f000 r-xp 00000000 07:00 8151       /initrd/pup_ro2/usr/lib/libgthread-2.0.so.0.3200.1
b779f000-b77a0000 rwxp 00000000 07:00 8151       /initrd/pup_ro2/usr/lib/libgthread-2.0.so.0.3200.1
b77a0000-b77b8000 r-xp 00000000 07:00 9888       /initrd/pup_ro2/lib/libblkid.so.1.1.0
b77b8000-b77ba000 rwxp 00017000 07:00 9888       /initrd/pup_ro2/lib/libblkid.so.1.1.0
b77ba000-b77c6000 r-xp 00000000 07:00 9921       /initrd/pup_ro2/lib/libudev.so.0.11.1
b77c6000-b77c7000 rwxp 0000b000 07:00 9921       /initrd/pup_ro2/lib/libudev.so.0.11.1
b77c7000-b77c8000 rwxp 00000000 00:00 0 
b77c8000-b77e2000 r-xp 00000000 07:00 9953       /initrd/pup_ro2/lib/ld-2.10.1.so
b77e2000-b77e3000 r-xp 00019000 07:00 9953       /initrd/pup_ro2/lib/ld-2.10.1.so
b77e3000-b77e4000 rwxp 0001a000 07:00 9953       /initrd/pup_ro2/lib/ld-2.10.1.so
bfcce000-bfcef000 rw-p 00000000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
Aborted
#

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#64 Post by jemimah »

It seems like some sort of probing needs to happen for optical drives. Udev doesn't seem to generate any events when a CD/DVD is inserted.

Also I'm not sure how to get audio CDs to show up on the desktop. They don't seem to have any volumes associated with them.

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

#65 Post by jamesbond »

jemimah wrote:It seems like some sort of probing needs to happen for optical drives. Udev doesn't seem to generate any events when a CD/DVD is inserted.

Also I'm not sure how to get audio CDs to show up on the desktop. They don't seem to have any volumes associated with them.
Sigh :? http://forum.tinycorelinux.net/index.php?topic=12176.0. Some solution here: http://www.linuxquestions.org/questions ... ve-930081/.

I ended up running cddetect_quick once every few seconds to generate udev events.
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

#66 Post by akash_rawal »

jemimah wrote: My personal thought on rewriting the event manager are this.

You need to get buy-in from Barry to use it in woof if you want it to go mainstream. The best way to do this, IMO, is to start small, debug the heck out of it, and keep it modular.
I think you are right.

Now what I have planned is that I will implement a plugin support in the volume monitor, and then attempt to write a subset of module and firmware loading. Then we'll see whether it is working better.

I have already started this task.

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

#67 Post by akash_rawal »

jemimah wrote:
akash_rawal wrote:
jemimah wrote: but for some reason the blkid command returns incomplete output when run from a script called by udev as opposed to the command line. I can't figure out why.
udev removes the entire environment , including PATH variable. You have to re-export it yourself or use full path to blkid.
It's not a PATH issue. Blkid correctly returns info about every drive except the one in question. It's bizarre.
Strange.

If I were to say that device nodes were not ready yet, then my volume monitor should also not work due to exactly same problem.

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

#68 Post by akash_rawal »

jemimah wrote:It seems like some sort of probing needs to happen for optical drives. Udev doesn't seem to generate any events when a CD/DVD is inserted.

Also I'm not sure how to get audio CDs to show up on the desktop. They don't seem to have any volumes associated with them.
Support for optical drives has been postponed for a while.

GIO API seems to be capable of handling optical drives. Only hurdle is that no events are raised for them and they have to be probed periodically. Maybe this can add an additional dependency.

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#69 Post by jemimah »

akash_rawal wrote:
jemimah wrote:
akash_rawal wrote: udev removes the entire environment , including PATH variable. You have to re-export it yourself or use full path to blkid.
It's not a PATH issue. Blkid correctly returns info about every drive except the one in question. It's bizarre.
Strange.

If I were to say that device nodes were not ready yet, then my volume monitor should also not work due to exactly same problem.
Yeah, even if I put in a very long sleep I get the same results. During the sleep, I can get the correct results from the command line. It's odd.

EDIT: No the above is wrong. It doesn't work from the commandline either until the udev event queue is finished. Guess_fstype doesn't always work either until the queue is finished.

Therefore, I need to have pup-volume-monitor kick off my script - it can't be done from udev as far as I can tell.
Last edited by jemimah on Sat 12 May 2012, 19:33, edited 1 time in total.
[url]http://saluki-linux.com[/url]

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#70 Post by jemimah »

akash_rawal wrote:
jemimah wrote:It seems like some sort of probing needs to happen for optical drives. Udev doesn't seem to generate any events when a CD/DVD is inserted.

Also I'm not sure how to get audio CDs to show up on the desktop. They don't seem to have any volumes associated with them.
Support for optical drives has been postponed for a while.

GIO API seems to be capable of handling optical drives. Only hurdle is that no events are raised for them and they have to be probed periodically. Maybe this can add an additional dependency.
It kindof works for DVDs if I run the probing from another script. But the new drives won't show up on the desktop or in Thunar unless I restart them.

How do I get the daemon to update everything?
[url]http://saluki-linux.com[/url]

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#71 Post by jemimah »

I've been looking at this more closely. So I've got udev generating change events:

Code: Select all

UDEV  [1336829402.295403] add      /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
UDEV  [1336829402.306227] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
KERNEL[1336829410.629103] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
UDEV  [1336829410.641071] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)

And the pup-volume-monitor is working

Code: Select all

Drive sr0:
	unix_dev=/dev/sr0
	model=CDDVDW SE-S084C
	vendor=TSSTcorp
	props = 0 | DRIVE_USB | DRIVE_SCSI | DRIVE_REMOVABLE | DRIVE_FLASH
Drive changed
Drive sr0:
	unix_dev=/dev/sr0
	model=CDDVDW SE-S084C
	vendor=TSSTcorp
	props = 0 | DRIVE_USB | DRIVE_SCSI | DRIVE_REMOVABLE | DRIVE_FLASH
Drive changed
Drive sr0:
	unix_dev=/dev/sr0
	model=CDDVDW SE-S084C
	vendor=TSSTcorp
	props = 0 | DRIVE_USB | DRIVE_SCSI | DRIVE_REMOVABLE | DRIVE_FLASH
Volume changed
Volume sr0:
	unix_dev=/dev/sr0
	label=SERENITY
	fstype=udf
	uuid=
	drv_sysname=sr0
	mntpnt=
	mntflags = 0
But optical drives do no show up on the desktop unless I restart it. Also the drive does not disappear if i eject the disk or if I unplug the whole drive (it's usb).

I think change events are not being handled correctly.
[url]http://saluki-linux.com[/url]

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

#72 Post by jamesbond »

jemimah wrote:I've been looking at this more closely. So I've got udev generating change events:

Code: Select all

UDEV  [1336829402.295403] add      /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
UDEV  [1336829402.306227] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
KERNEL[1336829410.629103] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
UDEV  [1336829410.641071] change   /devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2.4/1-2.4:1.0/host16/target16:0:0/16:0:0:0/block/sr0 (block)
How do you get this without doing ioctl call on the device? :shock:
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

#73 Post by akash_rawal »

If you do manage to generate udev events for optical drives, it will be detected as an internal hard drive or usb flash drive.

You won't have options like ejecting and loading the tray till the support for optical drives is added.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#74 Post by amigo »

CD/DVD drives themselves do not generate any sort of signal when the door is opened or closed. The only way to tell is by polling the device and checking to see whether a disk is there -audio discs are particularly hard to detect.
On my old system, I use a program called 'autorun' to handle CD drives. It runs as a daemon and can be configured to handle different types of disks. If a CD is detected and is mountable, then it is mounted and opened with rox. If it is blank, then it starts my CD burner -can't remember what it does with audio disks...

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#75 Post by disciple »

Do you have that in your repo somewhere?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#76 Post by amigo »

I didn't but quickly uploaded it here:
http://distro.ibiblio.org/amigolinux/do ... orun-3.20/

Here's the command I use to start it (from Window Maker's 'autostart' script):

Code: Select all

autorun --notify-insert="/usr/bin/rox /mnt/cdrom" --cdplayer="/usr/bin/wmcdplay" --recorder="/usr/bin/simplecdrx" --interval=2000 &
There's an archive of patches there you'll want to pay attention to. If you use src2pkg, you should be able to use my autorun.src2pkg script there to build it -otherwise, have a look at it to see the commands used to build it. I created the patches to address some issues with the build (on an older system gcc-3.4.6/glibc-2.3.6), so your mileage may vary.

You could start it during the init scripts, but it is best to start it (backgrounded) after the desktop is up and running. Either way, the code may prove valuable to the OP -although it is written in C++ (Drat it!)

As I mentioned, CD/DVD hardware doesn't issue any kind of signal which would generate a kernel event -you have to poll the drive for any changes and each poll cycle has to be complete. Basicallly, you check the drive to see if there is a disk in there. If not, you go to the next polling loop. If there is a disk, then you have to determine the type -if it has a filesystem you mount it, if it is an audio disc you run the player, otherwise it is a blank disk and you run the burner. You *could* use another method where you'd eject the disk once during bootup, then close the door -that way you'd at least know if the door is open or closed before staring to poll it.

About autorun: as the name suggests, it was meant to provide the functionality provided by Windows when an autorun.inf file is present, but I don't use it for that.

I'm also interested to know what udev rule the OP is using to generate the kernel add/change events -maybe newer kernel drivers are somehow polling the drives automatically?

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#77 Post by jemimah »

akash_rawal wrote:If you do manage to generate udev events for optical drives, it will be detected as an internal hard drive or usb flash drive.

You won't have options like ejecting and loading the tray till the support for optical drives is added.
Ejecting and autorunning the appropriate media player is handled by the mount script I'm using.

I am generating the udev events by leaving the probe-optical function in pup_event_frontend_d. That part works fine.

Pup-volume-monitor-shows the correct information - the only problem is that updates to the optical drive never make it to Thunar or xfdesktop.

I can script around the audio CD problem - but getting DVDs and data disks to show up on the desktop should be an easy fix (they do show up as USB drives). I just haven't figured out what the fix is.

Anyway I'm looking forward to updates. Having a working volume monitor is a huge usability improvement for Saluki.
[url]http://saluki-linux.com[/url]

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

#78 Post by jamesbond »

amigo wrote:I didn't but quickly uploaded it here:
http://distro.ibiblio.org/amigolinux/do ... orun-3.20/

Here's the command I use to start it (from Window Maker's 'autostart' script):

Code: Select all

autorun --notify-insert="/usr/bin/rox /mnt/cdrom" --cdplayer="/usr/bin/wmcdplay" --recorder="/usr/bin/simplecdrx" --interval=2000 &
Thanks amigo - I'd like to look at this.
jemimah wrote: I am generating the udev events by leaving the probe-optical function in pup_event_frontend_d. That part works fine.
pup_event_frontend_d calls cddetect_quick to do this - so this is the same way I'm doing it. My code looks like this

Code: Select all

awk '/^drive name:/ { for (i = 3; i <= NF; i++) print "/dev/" $i; exit }' /proc/sys/dev/cdrom/info | 
xargs -n 1 cddetect_quick -d > /dev/null
I'm calling it once every 5 seconds (5 seconds is about the time required for DVD drive to settle when you insert a new disc anyway). I used patched cddetect_quick; the original one from
Barry returns 255 for anything other than "disc inserted" and that stops xargs from continuing (the patched version returns 1 instead).
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

#79 Post by akash_rawal »

jemimah wrote:
akash_rawal wrote:If you do manage to generate udev events for optical drives, it will be detected as an internal hard drive or usb flash drive.

You won't have options like ejecting and loading the tray till the support for optical drives is added.
Ejecting and autorunning the appropriate media player is handled by the mount script I'm using.
Well, I meant by using GIO API.

Code: Select all

gboolean            g_volume_can_eject                  (GVolume *volume);
void                g_volume_eject                      (GVolume *volume,
                                                         GMountUnmountFlags flags,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
gboolean            g_volume_eject_finish               (GVolume *volume,
                                                         GAsyncResult *result,
                                                         GError **error);
Anyways the plugin support is requiring a major rewrite, it will take time.

I found libburn, but it is absent in lucid puppy:

Code: Select all

# pkg-config --modversion libburn-1  
Package libburn-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libburn-1.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libburn-1' found
# 

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

#80 Post by akash_rawal »

jemimah wrote: Pup-volume-monitor-shows the correct information - the only problem is that updates to the optical drive never make it to Thunar or xfdesktop.

I can script around the audio CD problem - but getting DVDs and data disks to show up on the desktop should be an easy fix (they do show up as USB drives). I just haven't figured out what the fix is.
Do you manage to get udev or kernel events for opening and closing tray? If no, that could be the problem.

Currently hotplugging of USB drives works fine.

I am not interested in relying on udev events for optical drives. In next version the volume monitor will do its own probing of optical drives.

Post Reply