Hi,
I've allread posted something about this, but let's say it a bit
different: It would be nice, if the attached patch would be applied to the
irmanager.c code. It changes the behavior of the irmanager on exiting
after receiving a SIGTERM, SIGINT or SIGHUP.
I find it inconsistent, if the irmanager fires up the whole irda stuff (by
calling /etc/irda/drivers start) but on exit there is no way to automate
the removal of those irda drivers (which should be done, IMO, by executing
/etc/irda/drivers stop). The patch romoves this inconsistent behavior.
The following lines are from my /etc/irda/drivers script, which works fine
for me:
#! /bin/sh
action=$1
device=$2
case "${action:?}" in
'start')
irattach /dev/ttyS0 # The first serial port is an IrDA port
modprobe irlan # activate irlan support
;;
'stop')
ifconfig | grep irlan0 >/dev/null && \
ifconfig irlan0 down # shutdown the network
killall irattach # detache all IrDA ports
modprobe -r irlan irtty irda # remove modules
;;
esac
Any comments?
Martin
--- irmanager.c.orig Tue Nov 9 16:26:50 1999
+++ irmanager.c Wed Dec 8 20:18:42 1999
@@ -63,6 +63,8 @@ char *pidfile = "/var/run/irmanager.pid"
#define BEEP_WARN 2000
#define BEEP_ERR 4000
+int dev_fd=-1;
+
/*
* Function start_service (service, dev_name)
*
@@ -122,19 +124,32 @@ int load_module(char *name)
static void cleanup(int signo)
{
+ int exiting=FALSE;
+
switch (signo) {
case SIGTERM:
case SIGINT:
syslog(LOG_INFO, "got SIGTERM or SIGINT\n");
- exit(0);
+ exiting=TRUE;
break;
case SIGHUP:
syslog(LOG_INFO, "got SIGHUP\n");
- exit(0);
+ exiting=TRUE;
break;
default:
break;
}
+
+ if(exiting)
+ {
+ if(dev_fd>-1)
+ {
+ close(dev_fd);
+ dev_fd=-1;
+ }
+ stop_service("drivers", "");
+ exit(0);
+ }
unlink(pidfile);
}
@@ -150,7 +165,6 @@ int main(int argc, char *argv[])
struct irmanager_event event;
struct utsname buf;
int not_used; /* For now! */
- int fd;
int minor;
int ret;
int c;
@@ -203,8 +217,8 @@ int main(int argc, char *argv[])
if (chdir(configpath) != 0)
syslog(LOG_INFO, "chdir to %s failed: %m", configpath);
- fd = open_dev((10 << 8)+minor,S_IREAD|S_IFCHR);
- if (fd == -1) {
+ dev_fd = open_dev((10 << 8)+minor,S_IREAD|S_IFCHR);
+ if (dev_fd == -1) {
syslog(LOG_INFO, "Unable to open IrDA device!\n");
exit(-1);
}
@@ -213,7 +227,7 @@ int main(int argc, char *argv[])
start_service("drivers", "", 0);
while (TRUE) {
- ret = read(fd, &event, sizeof(event));
+ ret = read(dev_fd, &event, sizeof(event));
if (ret <= 0) {
/* Device closed, so probably a shutdown */
exit(ret);
@@ -221,7 +235,7 @@ int main(int argc, char *argv[])
switch (event.event) {
case EVENT_NEED_PROCESS_CONTEXT:
- ioctl(fd, IRMGR_IOCTNPC, not_used);
+ ioctl(dev_fd, IRMGR_IOCTNPC, not_used);
break;
case EVENT_DEVICE_DISCOVERED:
switch (event.service) {
@@ -263,9 +277,6 @@ int main(int argc, char *argv[])
break;
}
}
- close(fd);
-
- return 0;
}