Rewriting pup_event in C

What features/apps/bugfixes needed in a future Puppy
Message
Author
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.

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

#81 Post by jemimah »

akash_rawal wrote:
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.
AFAIK the opening/closing the tray doesn't generate udev events.
[url]http://saluki-linux.com[/url]

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

#82 Post by akash_rawal »

The next version 0.1.0 has arrived.

I have added plugin and config support (There will be one at /etc/xdg/pup-volume-monitor/main.conf), and support for interactive mount operations and optical drive support as a plugin.

I have tried using libburn to do this. It was able to show the type of disk (like CD-R, CD-RW, ...) but ended up locking the optical drive tray several times. It was quite slow too.

I am now using blkid and ioctl calls to probe for optical drives. It's fast but it can't detect type of disk.
Image

And I discover, ioctl calls on drive generates kernel events for opening and closing tray. However I am not using it.

Code: Select all

# udevadm monitor --kernel
monitor will print the received events for:
KERNEL - the kernel uevent

KERNEL[1339013226.789550] change   /devices/pci0000:00/0000:00:1f.2/host3/target3:0:0/3:0:0:0/block/sr0 (block)
KERNEL[1339013230.808583] change   /devices/pci0000:00/0000:00:1f.2/host3/target3:0:0/3:0:0:0/block/sr0 (block)
Currently it can detect only upto audio cds, and that too I haven't tested yet. I don't have any. If ioctl reports that inserted disk is an audio cd, it should use media-cdrom-audio icon and any attempt to mount it should give an error.

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

#83 Post by jamesbond »

akash_rawal wrote:Currently it can detect only upto audio cds, and that too I haven't tested yet. I don't have any.
You can make one. Get a few mp3 and use pburn to make an audio cd of them 8)
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

#84 Post by akash_rawal »

Thanks, you helped me find a bug which actually filtered out audio cds.

I was uselessly checking for presence of filesystem :oops:

I have fixed the bug, and added a more descriptive error message.
Image

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

#85 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.
Is this because blkid executable uses high-level probing, while I use low-level probe?
High-level probing reads /proc/partitions to get list of the drives, which might be the problem.

I have written a small executable using blkid low-level probing, and I have tested it works well from udev rules.

Code: Select all

//gcc -Wall -o blkid-lowlevel blkid-lowlevel.c `pkg-config --cflags --libs glib-2.0 blkid`
//Above is the command to compile this file

/*
 * blkid-lowlevel
 * Uses low-level superblock probing
 */

#include <blkid.h>
#include <glib.h>
#include <stdio.h>

gint main(gint argc, gchar *argv[])
{
	GError *error = NULL;
	GOptionContext *context = g_option_context_new(" [DEVICE1] [DEVICE2] ...");
	g_option_context_set_summary(context, "This uses blkid low-level prober which bypasses cache");
	g_option_context_parse(context, &argc, &argv, &error);
	if (error)
	{
		g_error("%s", error->message);
	}
	
	gint i;
	for (i = 1; i < argc; i++)
	{
		blkid_probe probe = blkid_new_probe_from_filename(argv[i]);
		if (! probe)
		{
			g_warning("Couldn't open %s, %s will not be scanned",
					argv[i], argv[i]);
			continue;
		}
		blkid_do_safeprobe(probe);
		
		gint j, num_tags;
		num_tags = blkid_probe_numof_values(probe);
		printf("%s: ", argv[i]);
		for (j = 0; j < num_tags; j++)
		{
			gchar *name, *value;
			blkid_probe_get_value(probe, j, (const gchar **) &name,
					(const gchar **) &value, NULL);
			printf("%s="%s" ", name, value);
		}
		puts("");
		blkid_free_probe(probe);
	}
	
	return 0;
}

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

#86 Post by disciple »

Is that an alternative to cddetect-quick? Or is it more? Or less?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

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

#87 Post by akash_rawal »

disciple wrote:Is that an alternative to cddetect-quick? Or is it more? Or less?
If cddetect-quick also uses ioctl(), then it is exactly equivalent, neither more, nor less. I cannot get more info using ioctl than cddetect-quick does.

Audio cds are currently detected like this:

Code: Select all

// plugins/cdrom.c:456
	//Check for audio CD
	gint fd = open(volume->unix_dev, O_NONBLOCK | O_RDWR);
	if (fd >= 0)
	{
		if (ioctl(fd, CDROM_DISC_STATUS, 0) == CDS_AUDIO)
		{
			disk->audio_cd = TRUE;
			volume->flags &= (~PUP_VOLUME_IS_MOUNTABLE);
		}
		close (fd);
	}

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

#88 Post by akash_rawal »

I observe a strange problem when I try to start the daemon from a script inside /etc/init.d . It doesn't detect optical drives when started like that.

Optical drives are detected by iterating over each device in /sys/block, testing each device whether it's an optical drive.

I wonder what is the circumstance when scripts at /etc/init.d are launched.

Starting the daemon from /root/.xinitrc solves the problem but the daemon is killed when X exits. The daemon is meant to continue running even after exiting x.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#89 Post by 01micko »

Why don't you start it as a service, but indirectly, with a wrapper script to wait until X starts, but then on a restart of X you may be faced with your initial problem... :?
Puppy Linux Blog - contact me for access

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

#90 Post by jamesbond »

akash_rawal wrote:It doesn't detect optical drives when started like that.
What is the failure mode?
Optical drives are detected by iterating over each device in /sys/block, testing each device whether it's an optical drive.
How do you do the test?
I wonder what is the circumstance when scripts at /etc/init.d are launched.
They are launched by /etc/rc.d/rc.services, in the background, in alphabetical order. /etc/rc.d/rc.services in turn is launched by /etc/rc.d/rc.sysinit; rc.sysinit is launched by /sbin/init --- and that is as early as you get. Before /sbin/init we're talking about initramfs (ie, before the pup.sfs is loaded and executed).

I have no problems detecting the device type: "cat /sys/block/sr0/device/type" returns 5 (which means read-only device - see here for example http://lkml.indiana.edu/hypermail/linux ... /1295.html) even in initramfs.

But of course this depends on when the driver for the particular device is loaded - if the driver is not built into kernel (compiled as a module instead), depending on when the module gets loaded, the device may not be ready for detection in rc.sysinit. In particular, if it is loaded dynamically by udev (udev is started early in rc.sysinit), it may take a while before it appears in /sys/block (that is, after all the udev rules for it are processed). USB devices are particularly prone to this additional delay.
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

#91 Post by akash_rawal »

Well I got the problem.

The problem was that environment variable LD_LIBRARY_PATH wasn't set.

And what's worse is that pup-volume-monitor uses LD_LIBRARY_PATH to search for its plugins. That means the cdrom plugin simply wasn't loaded!

The fix is simple then. Just set LD_LIBRARY_PATH variable.
Last edited by akash_rawal on Fri 08 Jun 2012, 15:33, edited 1 time in total.

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

#92 Post by akash_rawal »

jamesbond wrote:
Optical drives are detected by iterating over each device in /sys/block, testing each device whether it's an optical drive.
How do you do the test?
The mechanism is translated from /lib/udev/rules.d/50-udev-default.rules.

Code: Select all

# cdrom
SUBSYSTEM=="block", KERNEL=="sr[0-9]*", SYMLINK+="scd%n", GROUP="cdrom"
SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="4|5", GROUP="cdrom"
KERNEL=="pktcdvd[0-9]*", GROUP="cdrom"
KERNEL=="pktcdvd", GROUP="cdrom"

Code: Select all

gboolean pup_drive_test_optical(struct udev_device *dev)
{
	gboolean result = FALSE;

	if (strstr(udev_device_get_sysname(dev), "sr")
	    || strstr(udev_device_get_sysname(dev), "pktcdvd"))
		result = TRUE;

	if (!result)
	{
		const gchar *type = udev_device_get_sysattr_value(dev, "device/type");
		if (type)
		{
			if ((type[0] == '4') || (type[0] == '5'))
				result = TRUE;
		}
	}

	return result;
}

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

#93 Post by akash_rawal »

I hope now pup-volume-monitor is stable enough to move it to additional software section?

http://www.murga-linux.com/puppy/viewtopic.php?t=78881

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

#94 Post by akash_rawal »

I quickly wrote an implementation for desktop drive icons for desktops that do not support them. It uses GIO.

Image

It can be configured to stick to a corner of the screen, align icons vertically, change font colors, etc. Settings take effect immediately.

Icons look like rox-filer icons for a while, till you move mouse pointer over it.

Could anyone package this, I myself am running out of time. My school will be reopening next week and I have to rush through my holiday hw for summer vacations before that. :(
Attachments
desktop_drive_icons-0.0.1.tar.gz
(124.61 KiB) Downloaded 500 times

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#95 Post by recobayu »

this is very nice drive icon. the labels are very helpful because i prefer look at the label than sda3 or sda4 like that. can anyone compile that in lupu, dpup, or slacko? i tried to compile myself but didn't result anything.

Code: Select all

./configure
make
make install
but nothing happened.
thank you.

Post Reply