Motion - Watchdog And Thread Patch

Watchdog and thread video device patch

Description of Patch

Motion isn't able to start if a video device isn't there at startup, Motion even exits if it can't capture an image at startup. This patch changes this behavior and make it possible to start motion if the device can't be opened. It retries to open the device every 10sec (same as netcam before). It can also reopen a device if it was lost, this is a problematic area see notes below. It also implements a event_camera_lost event, that is called if a device can't be opened at startup, or if it is lost later. There is also a watchdog that keeps a look at all threads to see if they aren't stuck somewhere, if it is it first retries to restart it by setting a flag. If the thread isn't closed after a while it kills it and restarts it. Threads can also be stopped/restarted one by one in the control http api.

Camera lost is a problematic area. I have tested with some usb cams, one of them hangs the PC compleatly when I disconnect it (even if motion haven't been run). One other camera, if I disconnect it while motion running, motion hangs in one thread. The watchdog detects it and kills the thread, but it keeps saying that the device dosn't exists if I reconnect the camera. I have to end motion and restart it to be able to open the device again.

Installation of Patch

Download the patch file. If it is packed as a gz or tar.gz unpack it first. Then copy it to the motion source directory and issue the command (assuming the patch file is called filename_of_patch_file.diff)

patch < filename_of_patch_file.diff

Then re-build Motion and test the patch.

Change History of Patch

  • 1.0 Initial revision

Discussion and Comments

Good feature.

And on the roadmap so go ahead and commit

Thanks smile

-- KennethLavrsen - 28 Nov 2007

included since svn 278

Thanks Dag smile

-- AngelCarpintero - 02 Dec 2007

Current implementation in 3.2.10 and svn has some issues , if you want to really make a thread quit not always work. Moreover there some situations where motion must quit.

I.ex , running motion with one thread , motion got a problem because is trying to write a jpeg or video to a device with no space left.

Other example if you running motion with one thread ( motion.conf , thread1.conf ) motion doesn't quit if you run quit for thread 1 from http control.

Attached a patch against svn to fix both issues.

-- AngelCarpintero - 05 May 200

If I remember correct from when I implemented the watchdog and quit threads it works i this way. If you have one thread and do a quit on that, motion still runns to be able to start it again. If you in the http control do a quit in thread 0 (not thread 1) Motion quit.

When I looked at your patch I saw that I missed that I needed to set watchdog to WATCHDOG_OFF when I don't want to restart the thread. I think it is better to add this code in the end of motion_loop instead of setting it when we want to quit a thread. It is simple to forget somewhere in the code... (and the watchdog can also handle the situation when the thread dosn't quit of any reason)

if (!cnt->restart)
      cnt->watchdog = WATCHDOG_OFF;

-- DagErlandsson - 05 May 2008

Thanks Dag, i've updated my patch adding your suggestion and also some missing details in picture.c ... although i think that we should add a wrapper function

to handle jpeglib errors. So if you are agree i will include in 3.2.10 this patch.

-- AngelCarpintero - 05 May 2008

Included partialy in 3.2.10 ( all except ffmpeg fix ).

-- AngelCarpintero - 07 May 2008

Topic revision: r10 - 07 May 2008, AngelCarpintero
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.