LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2004, 01:13 PM   #1
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
CDROM autoload on commandline


The Plan:
I am setting up a self-sustaining Linux system that requires no user interaction on the terminal. Once booted, and not logged in, if a CDROM is loaded into the drive I want the system to launch a desired application.

The Question:
How do I receive signals from the kernel/system that a CDROM is loaded?
How do I determine whay type of CD it is (ie Audio or data)?

Any help would be greatly appreciated.

JN
 
Old 05-27-2004, 03:27 PM   #2
Vlad-A
Member
 
Registered: May 2004
Location: Vienna, Austria
Distribution: Open SuSE 11, Mac OS X 10.5
Posts: 299

Rep: Reputation: 33
So no one is logged in. My question: In which user context shall the action be executed when the CD-ROM is inserted?
Root ? Normal user ? I mean this can be a serious treat to the overall syste security.

I think that you have to write a daemnon, which is then started on system start-up/boot.

This deamon can check if a CD-ROM is inserted or not.

One option can be by:

...
while ( (handler=open("/dev/cdrom", O_READONLY)) == -1)
sched_yield();
...


with ioctl you can detremine what type the cd is.

I *suggest* you take a look in file:/usr/src/linux/drivers/cdrom directory and browse through
the sources of the cd-rom subsystem for further information.

You may also take a look on the supermounter (submount) sorces to get an idea
how to write an autodetect for cd-rom insert.
http://sourceforge.net/projects/submount/

You may also consider to browse the web to see if maybe someone has already written
such software.
 
Old 05-28-2004, 06:23 AM   #3
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Original Poster
Rep: Reputation: 15
I already have automounter installed and working fine. I have to enter the /auto/cdrom folder (location where I put the automounter mount) to activate the cdrom. I know there is a way to mount and load the cd when it is inserted into the drive. My Red Hat system does this when I am in X, using KDE. I would like the same feature when I am at the command line (not in X at all).

As for the user, the system is standalone in a place where security doesn't really matter. Plus I am hoping that when I catch the insert cdrom signal that I can have it execute a job as a dummy user.

So, in short, I need to know how to start an application when a signal is sent from the cdrom. I will use the application to mount the cdrom.

I couldn't get the while code posted earlier to work. Maybe I need a little more instruction on what it is supposed to do and where it is supposed to be put.

Thanks.

Jay
 
Old 05-28-2004, 06:58 AM   #4
Vlad-A
Member
 
Registered: May 2004
Location: Vienna, Austria
Distribution: Open SuSE 11, Mac OS X 10.5
Posts: 299

Rep: Reputation: 33
It could look like:


#include <unistd.h>
#include <fcntl.h>
#include <sched.h>

int main ()
{
int handler;
while ( (handler=open("/dev/cdrom", O_READONLY)) == -1) sched_yield();

###### CD-ROM inserted #########
close handler;
##### YOUR ACTION ######


return (0);
}

now compile it using gcc.

You may start it via an init script in the run-level you want. init level 3 is one where you do not have X.

/dev/cdrom is the device file for your CD-ROM. You may use a different name according to the
dev file of your CD-ROM.

BTW: You may try to mount a CD. If mount succeeds then it's very likely that you have a data CD.
If NOT, then either there is a Audio CD inserted *or* something's wrong with the CD media.
So the mount test isn't 100% bullet proof., but it's simple to implement.

Last edited by Vlad-A; 05-28-2004 at 06:59 AM.
 
Old 05-28-2004, 10:14 AM   #5
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Original Poster
Rep: Reputation: 15
What I ended up doing:
Already had autofs installed (uses automounter, except it is used on distros other than debian and redhat).
installed cdde (compact disc detection and execution) available at http://freshmeat.net/cdde
had to write a python script to launch cdde in daemon mode:
Code:
#!/usr/bin/python
import os
pid = file('/var/run/cdde.pid','w')
pgm = 'cdde'
arg = [pgm,'-c','/etc/cdde.xml']
this = os.spawnvp(os.P_NOWAIT,pgm,arg)
pid.write(str(this) + '\n')
pid.close()
Created init.d script:
Code:
#!/bin/bash
# Begin $rc_base/init.d/cdde

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
     start)
          echo "Starting cdde..."
          loadproc /usr/sbin/cdde_py
          ;;
     stop)
          echo "Stopping cdde..."
          killproc /var/bin/cdde
          ;;
     reload)
          echo "Reloading cdde..."
          killall -HUP cdde
          ;;
     restart)
          $0 stop
          sleep 1
          $0 start
          ;;
     status)
          statusproc /usr/bin/cdde
          ;;
     *)
          echo "Usage: $0 {start|stop|reload|restart|status}"
          exit 1
          ;;
esac
# End $rc_base/init.d/cdde
Then I make the init.d script execute on boot up using:
Code:
cd /etc/rc.d/init.d &&
ln -sf ../init.d/cdde ../rc0.d/K25cdde &&
ln -sf ../init.d/cdde ../rc1.d/K25cdde &&
ln -sf ../init.d/cdde ../rc2.d/K25cdde &&
ln -sf ../init.d/cdde ../rc3.d/S35cdde &&
ln -sf ../init.d/cdde ../rc4.d/S35cdde &&
ln -sf ../init.d/cdde ../rc5.d/S35cdde &&
ln -sf ../init.d/cdde ../rc6.d/K25cdde
I modified the /etc/cdde.xml according to the cdde instructions.

Now when I insert a cd, no matter the type, it will launch the desired application accordingly.

Works pretty much how I wanted.
[edit]Small clarification: I use as the command /auto/cdrom, when it is a data cd to get the drive mounted. Then all I do is use the information from it.
If it is an audio cd, I launch an application that rips the cd to mp3's and ejects the cd when complete.
[/edit]

Thanks for all of the pointers. I wouldn't have known where to look for any of the iformation without certian key words.

JN

Last edited by jazernorth; 05-28-2004 at 10:18 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
autoload modules zanku Slackware 3 03-21-2005 09:40 AM
Autoload driver St4ckHOu5e Linux - Networking 1 02-02-2005 03:41 AM
Autoload ndiswrapper on startup m2stian Fedora 2 12-05-2004 05:34 AM
Autoload problem??? MasterC Linux - General 2 04-17-2002 12:41 AM
autoload modules? captgoodnight Linux - Newbie 1 03-10-2002 07:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration