LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 09-08-2009, 02:16 PM   #1
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Rep: Reputation: 23
open ("/dev/my_dev",O_RDWR): Operation not permitted


I'm running Vanilla 2.6.30.1 with busybox.
/dev contains a device file called my_dev. It was created using:
mknod my_dev c 248 0
I have a multithreaded application. When I try to open /dev/my_dev using:
rc=open ("/dev/my_dev",O_RDWR)
in the main thread (just after main), I get rc=6 which is OK.
But when I try to open my_dev withing a thread I get:
rc=-1, errno=1 (Operation not permitted).
How can I debug this problem ?
What can cause: Operation not permitted ?

Thanks.
 
Old 09-08-2009, 08:09 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
This is the EPERM error on the open, which would indicate that the thread does not have permission to open the file. It would be worth checking how you have created the thread (because that is where the permissions are first set).
 
Old 09-09-2009, 01:22 PM   #3
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Original Poster
Rep: Reputation: 23
Quote:
Originally Posted by neonsignal View Post
This is the EPERM error on the open, which would indicate that the thread does not have permission to open the file. It would be worth checking how you have created the thread (because that is where the permissions are first set).
Thank you for your reply. Here is pthread_attr_t:
typedef struct __pthread_attr_s
{
int __detachstate;
int __schedpolicy;
struct __sched_param __schedparam;
int __inheritsched;
int __scope;
size_t __guardsize;
int __stackaddr_set;
void *__stackaddr;
size_t __stacksize;
} pthread_attr_t;

Which of the fields in the structure can cause the open error ?

Thanks.
 
Old 09-10-2009, 05:29 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
here is some sample code (the open succeeds in both the main thread and the secondary thread).

Code:
#include <pthread.h>
#include <fcntl.h>
#include <iostream>
void *threadFn(void *p)
{
// open device in second thread
	int handle = open("/dev/dsp",O_RDWR);
	std::cout << "secondary thread " << handle << std::endl;
	if (handle > 0) close(handle);
}
int main()
{
// open device in main thread
	int handle = open("/dev/dsp",O_RDWR);
	std::cout << "main thread " << handle << std::endl;
	if (handle > 0) close(handle);
// start second thread
	pthread_t thread;
	pthread_create( &thread, 0, threadFn, 0);
	pthread_join(thread, 0);
}
Note that you cannot open a handle for writing from both threads at the same time (and you don't need to, since they share open handles, though you do need to arbitrate access to the handle).

The example assumes that the user is in the dsp group (audio).
 
Old 09-10-2009, 10:09 AM   #5
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Original Poster
Rep: Reputation: 23
Solution

Quote:
Originally Posted by neonsignal View Post
here is some sample code (the open succeeds in both the main thread and the secondary thread).

Code:
#include <pthread.h>
#include <fcntl.h>
#include <iostream>
void *threadFn(void *p)
{
// open device in second thread
	int handle = open("/dev/dsp",O_RDWR);
	std::cout << "secondary thread " << handle << std::endl;
	if (handle > 0) close(handle);
}
int main()
{
// open device in main thread
	int handle = open("/dev/dsp",O_RDWR);
	std::cout << "main thread " << handle << std::endl;
	if (handle > 0) close(handle);
// start second thread
	pthread_t thread;
	pthread_create( &thread, 0, threadFn, 0);
	pthread_join(thread, 0);
}
Note that you cannot open a handle for writing from both threads at the same time (and you don't need to, since they share open handles, though you do need to arbitrate access to the handle).

The example assumes that the user is in the dsp group (audio).
It was a silliy mistake. I tried to open the file when it was already opened. Thank you for your time and effort.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"creating symbolic link" "operation not permitted" wheni Linux - Newbie 3 05-08-2011 01:36 AM
Serial Port Access Denied using open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); morty346 Programming 11 01-02-2011 05:23 PM
Serial Port Access Denied using open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); morty346 Linux - Newbie 4 02-11-2009 08:13 AM
Logged in as "root"/Fedora 8 but get "Operation not permitted" when using "chmod etc gosunlee Linux - Newbie 7 02-10-2008 05:56 AM
hdparm -d1 /dev/hda gives me "HDIO_SET_DMA failed: Operation not permitted" elluva Linux - Hardware 7 07-21-2007 03:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration