krjones
Posts: 19
Joined: Wed May 23, 2012 1:53 am

Motion Webcam Permissions Issue

Thu Mar 14, 2013 10:56 pm

First of all I want to say that I don't post until I have exhausted my internet research. That being said I need some help. Let me explain what I am trying to do and I'll get to what the issue is.

1) I have a logitech webcam that I have connected to my pi.
2) I have used motion webcam software to successfully connect my pi and camera without issue.
3) Last week I keept getting a grey screen that said it couldn't connect to my video device. Upgrading the software didn't help so I wound up reflashing my pi and starting over.
4) After I reflashed I logged in and I created a new user called motion (for the webcam)
5) I installed motion using apt-get and configured it the same way I did previously.

Here's the problem...It's not working this time.
1) I restart the pi and motion keeps quitting immediately after starting. (see below)
2) These are the two offending lines

Mar 14 16:15:33 raspberrypi motion: [1] Error opening file /media/CHERRY/www/webcam/motion/images/lastsnap.jpg with mode w: Permission denied
Mar 14 16:15:33 raspberrypi motion: [1] Can't write picture to file /media/CHERRY/www/webcam/motion/images/lastsnap.jpg

3) Basically motion can't overwrite lastsnap.jpg.
4) I'm starting this via /etc/init.d/motion
5) Here are the permissions for the file that motion creates
-rw-r--r-- 1 motion motion 12082 Mar 14 16:14 lastsnap.jpg

and the encapsulating folder

drwxrwxr-x 5 motion root 4096 Mar 14 16:14 .
drwxrwxr-x 3 motion root 4096 Mar 9 19:57 ..
drwxrwxr-x 7 motion root 4096 Mar 14 16:14 images
lrwxrwxrwx 1 motion motion 19 Mar 14 16:14 lastsnap.jpg -> images/lastsnap.jpg
drwxrwxr-x 6 motion root 4096 Mar 12 05:02 movies
drwxrwxr-x 2 motion root 4096 Mar 9 19:57 timelapse

Please help, I have no idea why motion can't write to this file. I have tired all combinations of pi:pi, motion:motion, motion:pi, motion:root, etc.....

Thank you all in advance,
Kyle

********************** log file **************************

Code: Select all

Mar 14 16:14:07 raspberrypi motion: [0] httpd Closing
Mar 14 16:14:07 raspberrypi motion: [0] httpd thread exit
Mar 14 16:14:08 raspberrypi motion: [0] Motion terminating
Mar 14 16:14:18 raspberrypi motion: [0] Processing thread 0 - config file /etc/motion/motion.conf
Mar 14 16:14:18 raspberrypi motion: [0] Motion 3.2.12 Started
Mar 14 16:14:18 raspberrypi motion: [0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478784
Mar 14 16:14:18 raspberrypi motion: [0] Thread 1 is from /etc/motion/motion.conf
Mar 14 16:14:18 raspberrypi motion: [0] motion-httpd/3.2.12 running, accepting connections
Mar 14 16:14:18 raspberrypi motion: [0] motion-httpd: waiting for data on port TCP 8080
Mar 14 16:14:18 raspberrypi motion: [1] Thread 1 started
Mar 14 16:14:18 raspberrypi motion: [1] cap.driver: "uvcvideo"
Mar 14 16:14:18 raspberrypi motion: [1] cap.card: "UVC Camera (046d:0825)"
Mar 14 16:14:18 raspberrypi motion: [1] cap.bus_info: "usb-bcm2708_usb-1.3"
Mar 14 16:14:18 raspberrypi motion: [1] cap.capabilities=0x04000001
Mar 14 16:14:18 raspberrypi motion: [1] - VIDEO_CAPTURE
Mar 14 16:14:18 raspberrypi motion: [1] - STREAMING
Mar 14 16:14:18 raspberrypi motion: [1] Test palette YUYV (544x288)
Mar 14 16:14:18 raspberrypi motion: [1] Using palette YUYV (544x288) bytesperlines 1088 sizeimage 313344 colorspace 00000008
Mar 14 16:14:18 raspberrypi motion: [1] found control 0x00980900, "Brightness", range 0,255 
Mar 14 16:14:18 raspberrypi motion: [1] #011"Brightness", default -8193, current 128
Mar 14 16:14:18 raspberrypi motion: [1] found control 0x00980901, "Contrast", range 0,255 
Mar 14 16:14:18 raspberrypi motion: [1] #011"Contrast", default 57343, current 32
Mar 14 16:14:18 raspberrypi motion: [1] found control 0x00980902, "Saturation", range 0,255 
Mar 14 16:14:18 raspberrypi motion: [1] #011"Saturation", default 57343, current 32
Mar 14 16:14:18 raspberrypi motion: [1] found control 0x00980913, "Gain", range 0,255 
Mar 14 16:14:18 raspberrypi motion: [1] #011"Gain", default 57343, current 16
Mar 14 16:14:18 raspberrypi motion: [1] mmap information:
Mar 14 16:14:18 raspberrypi motion: [1] frames=4
Mar 14 16:14:18 raspberrypi motion: [1] 0 length=313344
Mar 14 16:14:18 raspberrypi motion: [1] 1 length=313344
Mar 14 16:14:18 raspberrypi motion: [1] 2 length=313344
Mar 14 16:14:18 raspberrypi motion: [1] 3 length=313344
Mar 14 16:14:18 raspberrypi motion: [1] Resizing pre_capture buffer to 1 items
Mar 14 16:14:19 raspberrypi motion: [1] Started stream webcam server in port 8081
Mar 14 16:14:19 raspberrypi motion: [1] Resizing pre_capture buffer to 10 items
Mar 14 16:15:33 raspberrypi motion: [1] Error opening file /media/CHERRY/www/webcam/motion/images/lastsnap.jpg with mode w: Permission denied
Mar 14 16:15:33 raspberrypi motion: [1] Can't write picture to file /media/CHERRY/www/webcam/motion/images/lastsnap.jpg - check access rights to target directory: Permission denied
Mar 14 16:15:33 raspberrypi motion: [1] Thread is going to finish due to this fatal error: Permission denied
Mar 14 16:15:33 raspberrypi motion: [1] Could not create symbolic link [images/lastsnap.jpg]: Permission denied
Mar 14 16:15:34 raspberrypi motion: [1] Calling vid_close() from motion_cleanup
Mar 14 16:15:34 raspberrypi motion: [1] Closing video device /dev/video0
Mar 14 16:15:34 raspberrypi motion: [0] httpd Closing
Mar 14 16:15:34 raspberrypi motion: [0] httpd thread exit
Mar 14 16:15:35 raspberrypi motion: [0] Motion terminating

TMcC
Posts: 3
Joined: Fri Mar 15, 2013 10:03 pm

Re: Motion Webcam Permissions Issue

Fri Mar 15, 2013 10:15 pm

The last error is about creating the symlink for lastsnap, what does the output of 'ls -l' show in that directory? Possibly the file that is linked to lastsnap is owned by some other UID. Also, what UID is motion actually running as? (ps -eaf | grep motion). This should not be hard to sort out.

Permissions issues aside, I've seen various USB web cams fail to work properly with motion on the Pi. In more than one case I had to use the MJPEG palette as YUYV (which you are using) failed silently.

# V4L2_PIX_FMT_MJPEG : 2 'MJPEG'
# V4L2_PIX_FMT_YUYV : 6 'YUYV'


Good Luck -

krjones
Posts: 19
Joined: Wed May 23, 2012 1:53 am

Re: Motion Webcam Permissions Issue

Sat Mar 16, 2013 2:12 am

Thanks for the reply. This is the the output of the ps -eaf | grep motion.

root 2211 1998 0 20:07 ? 00:00:00 sshd: motion [priv]
motion 2218 2211 4 20:07 ? 00:00:02 sshd: motion@pts/1

Here is the output of where the ln -s link should be made.
/media/CHERRY/www/webcam/motion
lrwxrwxrwx 1 motion motion 19 Mar 14 16:14 lastsnap.jpg -> images/lastsnap.jpg
drwxrwxr-x 7 motion root 4096 Mar 14 16:14 images
/media/CHERRY/www/webcam/motion/images
-rw-r--r-- 1 motion motion 12082 Mar 14 16:14 lastsnap.jpg

I agree, this shouldn't be that hard to sort out, so I am sure I'm just missing something easy.

Does the above mean anything to you in terms of what I may be missing?

TMcC
Posts: 3
Joined: Fri Mar 15, 2013 10:03 pm

Re: Motion Webcam Permissions Issue

Sat Mar 16, 2013 3:01 am

1. It does not look like motion is running (which makes sense since your log shows it fails on start:)

[tm@atom motion]$ ps -aef | grep [m]otion
root 13935 1 15 Mar11 ? 16:45:42 /usr/local/bin/motion -c /usr/local/etc/motion.conf

2. lastsnap.jpg is created from the motion process and is a link to the last snapshot. I'm not sure how you configured your file names / dir names in motion.conf but here is an example from a working system with the default snapshot_filename.

[tm@atom motion]$ ls -la lastsnap.jpg
lrwxrwxrwx 1 root root 33 Mar 15 19:42 lastsnap.jpg -> 1-187-20130315194200-snapshot.jpg

If it were me, I would delete the symlink and the file (which you show named as 'lastsnap.jpg') and then start motion. Also, the symlink is normally created in the same dir as target_dir, you should not need the symlink at /media/CHERRY/www/webcam/motion unless you added that for another reason.
The symlink, created by motion, should be under /media/CHERRY/www/webcam/motion/images if that is your target_dir.

krjones
Posts: 19
Joined: Wed May 23, 2012 1:53 am

Re: Motion Webcam Permissions Issue

Sat Mar 16, 2013 4:25 am

So, I got rid of the lastsnap.jpg files and stopped motion from creating a symbolic link. I restarted and it came up just fine. But, I've seen this before when I would get rid of those files. When I restarted again it shutdown motion shortly after starting just like before.

Mar 15 22:17:30 raspberrypi motion: [1] Error opening file /media/CHERRY/www/webcam/motion/lastsnap.jpg with mode w: Permission denied
Mar 15 22:17:30 raspberrypi motion: [1] Can't write picture to file /media/CHERRY/www/webcam/motion/lastsnap.jpg - check access rights to target directory: Permission denied

/media/CHERRY/www/webcam/motion
drwxrwxr-x 7 motion root 4096 Mar 15 22:12 images
-rw-r--r-- 1 motion motion 91135 Mar 15 22:16 lastsnap.jpg
drwxrwxr-x 6 motion root 4096 Mar 12 05:02 movies
drwxrwxr-x 2 motion root 4096 Mar 9 19:57 timelapse


Any thoughts on this?

Thanks

AndrewdAzotus
Posts: 83
Joined: Wed Feb 06, 2013 3:07 pm
Location: Canada

Re: Motion Webcam Permissions Issue

Sun Sep 15, 2013 9:51 pm

Has anyone found a solution to this. I'm getting the same problem when trying to write to a mounted drive on another Pi even though it actually creates the picture, it reports this error and quits anyway

when I revert to the local SDHC card it works fine!

weirdly, when looking at the mounted share, all ownership was

bd indiecity

I've removed barracudadrive and now it shows as

1001 indiecity

chilinski
Posts: 16
Joined: Mon Sep 16, 2013 8:08 pm

Re: Motion Webcam Permissions Issue

Wed Oct 02, 2013 8:21 pm

Permissions issues on Unix can drive you mad.

Step away from the whole camera/motion thing for a moment and try to do some stuff manually. Log in as "motion" and try copying/creating a lastsnap.jpg file in the images directory. If you can, then see if you can overwrite it. Experiment with different permissions on the lastsnap.jpg file so you can figure out exactly what the program is thinking it needs to do to function properly.

AndrewdAzotus
Posts: 83
Joined: Wed Feb 06, 2013 3:07 pm
Location: Canada

Re: Motion Webcam Permissions Issue

Wed Oct 02, 2013 11:45 pm

I've sorted it now, it was all because different Pi had different user accounts and the same user account had different ... uh, numbers.

I may need to set up Samba 4, LDAP and SSO.

Unless there is a better solution? how did Linux handle different user accounts on different machines before LDAP and SSO?

Return to “HATs and other add-ons”