Subject: pkg/16626: icewm runs out of fd if apm ioctl fails
To: None <gnats-bugs@gnats.netbsd.org>
From: Joachim Koenig-Baltes <joachim@joachim.handshake.de>
List: netbsd-bugs
Date: 05/03/2002 12:10:26
>Number:         16626
>Category:       pkg
>Synopsis:       icewm runs out of fd if apm ioctl fails
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 03 03:08:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Joachim Koenig-Baltes
>Release:        NetBSD 1.5ZC
>Organization:
	
>Environment:
System: NetBSD joachim 1.5ZC NetBSD 1.5ZC (JOACHIM_ISDN) #0: Mon Apr 29 14:57:36 MEST 2002 joachim@duron:/user/unix/work/NetBSD-current/src/sys/arch/i386/compile/JOACHIM_ISDN i386
Architecture: i386
Machine: i386
>Description:
icewm/icewm-gnome 1.0.9.2nb1 runs out of file descriptors if ioctl on apm
device fails, because the file descriptor is not closed in case of an
error.
>How-To-Repeat:
install and run icewm with apm enabled an find that after some time, no
application can be started via icewm menues.
>Fix:
The fix fixes the reason for the failing ioctl, which is essentially the
same as for gkrellm, described in pkg/15577:
  The apm_power_info structure has to zeroed, otherwise you get info for 
  random batteries (that may not exist). 
in addition, the file descriptor is now closed when the ioctl fails.
Below is a patch for patch-ab as found in patches:
--- ../../../icewm/patches/patch-ab     Wed Feb 27 11:31:57 2002
+++ patch-ab    Fri May  3 12:04:39 2002
@@ -1,7 +1,7 @@
 $NetBSD: patch-ab,v 1.2 2002/02/26 09:41:40 martti Exp $
 
 --- src/aapm.cc.orig   Tue Oct  9 16:54:03 2001
-+++ src/aapm.cc        Tue Feb 26 09:02:17 2002
++++ src/aapm.cc        Fri May  3 11:49:14 2002
 @@ -25,6 +25,12 @@
  
  #ifdef CONFIG_APPLET_APM
@@ -23,7 +23,7 @@
      char buf[45];
      int len, i, fd = open("/proc/apm", O_RDONLY);
      char driver[16];
-@@ -102,6 +109,44 @@
+@@ -102,6 +109,46 @@
              strcat(s,_(" - Charging"));
          else
              strcat(s,_("M"));
@@ -35,8 +35,10 @@
 +        return;
 +    }
 +
++    memset(&aip, 0, sizeof(aip)); 
 +    if (ioctl(fd, APM_IOC_GETPOWER, &aip) == -1) {
 +        fprintf(stderr, "ioctl failed on APMDEV");
++        close(fd);
 +        return;
 +    }
 +

>Release-Note:
>Audit-Trail:
>Unformatted: