Bug 7888 - Killing an application under gdb that open pwc drivers did not send the .release() function
Summary: Killing an application under gdb that open pwc drivers did not send the .rele...
Status: REJECTED INSUFFICIENT_DATA
Alias: None
Product: Drivers
Classification: Unclassified
Component: USB (show other bugs)
Hardware: i386 Linux
: P2 normal
Assignee: Greg Kroah-Hartman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-26 01:24 UTC by Nicolas Boulay
Modified: 2007-08-23 18:14 UTC (History)
2 users (show)

See Also:
Kernel Version: 2.6.17-5mdv
Subsystem:
Regression: ---
Bisected commit-id:


Attachments

Description Nicolas Boulay 2007-01-26 01:24:48 UTC
Most recent kernel where this bug did *NOT* occur:
Distribution: mandriva 2007
Hardware Environment: bi athlon 1500+ (SMP)
Software Environment:
Problem Description: After killing a program under gdb that open /dev/video0,
the .Release() function of the driver are not call, and the devices is locked.

Steps to reproduce:
Create a c programme that open /dev/video with a pwc driver. Launch it under
gdb, kill the program, not terminate it. Then the access to /dev/video is
locked, as if a programm still use it.

-----------------------------------------

I wrote an application using pwc. I have a strange behavior when a use the
driver with gdb.

If i launch my application inside gdb, i run it (which display a windows with
the frame at 10 fps ), then i stroke "ctl-z" and then i quit. Then i can't open
a new application, driver say that the file /dev/video is still in use.

But lsof | grep "/dev/video" give nothing. kill -9 does not do this. I have
watch to the trace using modprobe pwc trace=65535 and i see no call to the close
function, but the process is killed.

I use mandriva 2007 with pwc " 9.0.2-unofficial" on kernel "2.6.17-5mdv #1 SMP
Wed Sep 13 14:32:31 EDT 2006 i686 AMD Athlon(TM) MP 1800+ GNU/Linux".
Comment 1 Greg Kroah-Hartman 2007-01-26 12:38:26 UTC
Can you duplicate this on a 2.6.19 kernel.org kernel without any add-on pwc drivers?
Comment 2 Nicolas Boulay 2007-01-27 03:59:06 UTC
I don't think that pwc is the problem. When i use the debug trace in pwc, i
can't see the call to the .release function of the driver. So it did not look
like a pwc bug. I see it with pwc because pwc enable only one process to use it.

I can't reproduice the bug with a tiny programme like :

#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include <errno.h>
main(int argc, char ** argv){
  int  f;

  f=open(argv[1],O_RDWR| O_NONBLOCK, 0);

  if (-1 == f) { 
    perror("! ");
    exit(EXIT_FAILURE);
  }
  while(1){};
  close(f);
}

The programme i wrote is there :
http://astromech.googlecode.com/svn/trunk/ImageLab/nico/

$ svn checkout http://astromech.googlecode.com/svn/trunk/ImageLab/nico astromech
$ cd astromech
$ make
$ ./fps
open device :/dev/video
Video Capture Device Name : Philips 740 webcam
120x160
^c
[cyrano@localhost nico]$ gdb ./fps
GNU gdb 6.3-8mdv2007.0 (Mandriva Linux release 2007.0)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-mandriva-linux-gnu"...Using host libthread_db
library "/lib/i686/libthread_db.so.1".

(gdb) run
Starting program:
/home/cyrano/Documents/eurobot/astromech/2007/dev/astromech/ImageLab/nico/fps
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xbfffe000
[Thread debugging using libthread_db enabled]
[New Thread -1212687696 (LWP 19494)]
[New Thread -1212691552 (LWP 19497)]
open device :/dev/video
Video Capture Device Name : Philips 740 webcam
120x160
^z
Program received signal SIGTSTP, Stopped (user).
[Switching to Thread -1212687696 (LWP 19494)]
0xbfffe410 in __kernel_vsyscall ()
Current language:  auto; currently c
(gdb) quit
The program is running.  Exit anyway? (y or n) y
[cyrano@localhost nico]$ ./fps
open device :/dev/video
Cannot open '/dev/video': 16, Device or resource busy
Comment 3 Nicolas Boulay 2007-02-25 05:21:38 UTC
I have a new test case. the mmap function seems to be the origin of the
comportement. After the following test, i can't reopen the /dev/video0 device.
It's completely locked.
------------------------------------
[cyrano@localhost nico]$ g++ -o t test_pwc.cpp
[cyrano@localhost nico]$ ./t

[cyrano@localhost nico]$ ./t

[cyrano@localhost nico]$ gdb ./t
GNU gdb 6.3-8mdv2007.0 (Mandriva Linux release 2007.0)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-mandriva-linux-gnu"...Using host libthread_db
library "/lib/i686/libthread_db.so.1".

(gdb) run
Starting program:
/home/cyrano/Documents/eurobot/astromech/2007/dev/astromech/ImageLab/nico/t
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xbfffe000

Program received signal SIGINT, Interrupt.  <--- here i press ^C
0x080488b3 in main ()
(gdb) quit
The program is running.  Exit anyway? (y or n) y
[cyrano@localhost nico]$ ./t
Cannot open : 16, Device or resource busy
[cyrano@localhost nico]$ ./t
Cannot open : 16, Device or resource busy

the test_pwc.cpp file-------------------------
#include<stdio.h> //perror()
#include<fcntl.h> //O_RDONLY
#include <sys/ioctl.h> // system d'appel ioctl
#include<iostream>
#include <errno.h>
#include <sys/mman.h> //mmap
#include <linux/videodev.h>
int main(int argc, char ** argv)
{
  int f= open("/dev/video0", O_RDWR | O_NONBLOCK, 0);
  if (-1 == f) {
    fprintf (stderr, "Cannot open : %d, %s\n",
	      errno, strerror (errno));
    exit (EXIT_FAILURE);
  }
  unsigned char *framebuf = (unsigned char*)
    mmap(0, 120 * 160 * 3, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0);

  struct video_mmap       mm;
  mm.frame=0;
  mm.height = 120;
  mm.width  = 160;
  mm.format = 15; 

  if (ioctl(f, VIDIOCMCAPTURE, &(mm.frame)) < 0) {
    perror ("VIDIOCMCAPTURE");
    exit (EXIT_FAILURE);
  }
  if (ioctl(f, VIDIOCSYNC, &(mm.frame)) < 0) {
    perror ("VIDIOCSYNC");
    exit (EXIT_FAILURE);
    }

  while(1);
  munmap(framebuf,120 * 160 * 3);
  close(f);

  return 0;
}
Comment 4 Natalie Protasevich 2007-06-13 19:41:42 UTC
Can you please try the latest kernel (2.6.22-rc4). There were multiple fixes to videodev and also to USB subsystem, including device release and shutdown.
Thanks.
Comment 5 Adrian Bunk 2007-08-23 18:14:30 UTC
Please reopen this bug if it's still present with kernel 2.6.22.

Note You need to log in before you can comment on or make changes to this bug.