| Author |  | 
| linto.thomas 
 
 
 Joined: 17 Apr 2013
 Posts: 5
 Location: India
 
 | 
|  Posted: Thu 18 Apr '13 11:15    Post subject: /dev/mem access from phpextension (from .so file) |   |  
| 
 |  
| I need to write some configuration to hardware by accessing /dev/mem from apache but the function 'open("/dev/mem",O_RDWR)' in php extension returns '-1' ,permission denied 
 if any body knows how to solve this problem please help
 
 thanks in advance
 
 linto
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Tue 23 Apr '13 10:53    Post subject: |   |  
| 
 |  
| I guess the apache process has no rights / permission to write to it. Which chmod has /dev/mem ? |  | 
| Back to top |  | 
| linto.thomas 
 
 
 Joined: 17 Apr 2013
 Posts: 5
 Location: India
 
 | 
|  Posted: Tue 23 Apr '13 13:09    Post subject: |   |  
| 
 |  
| -bash-4.2# ls -l /dev/mem* crw-r----- 1 root kmem 1, 1 Dec 31 19:00 /dev/mem
 
 I add a user www and add the user in root ,kmem,wheel groups .
 
 if i log in as www and run a sample C code to open it will work . the same user is used in httpd.conf
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Tue 23 Apr '13 13:29    Post subject: |   |  
| 
 |  
| Open yes, but the group is only allowed to read, not to write. So you should allow the group to write! 
 
 |  | 
| Back to top |  | 
| linto.thomas 
 
 
 Joined: 17 Apr 2013
 Posts: 5
 Location: India
 
 | 
|  Posted: Tue 23 Apr '13 13:59    Post subject: |   |  
| 
 |  
| but open itself return -1 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Tue 23 Apr '13 15:25    Post subject: |   |  
| 
 |  
| -1 is false. So it does not seem to work. 
 You might try to get a better error message.
 
 
  	  | Code: |  	  | int fd;
 if ((fd=open("/dev/mem", O_RDWR)) < 0)
 {
 fprintf(stderr, "Fehler beim öffnen von /dev/mem\n");
 exit(1);
 }
 
 | 
 |  | 
| Back to top |  | 
| linto.thomas 
 
 
 Joined: 17 Apr 2013
 Posts: 5
 Location: India
 
 | 
|  Posted: Wed 24 Apr '13 12:36    Post subject: |   |  
| 
 |  
| I also use the same code  and the handle fd returns -1 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 |  | 
| Back to top |  | 
| linto.thomas 
 
 
 Joined: 17 Apr 2013
 Posts: 5
 Location: India
 
 | 
|  Posted: Thu 25 Apr '13 15:03    Post subject: |   |  
| 
 |  
| error value 22 EINVAL
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Thu 25 Apr '13 15:15    Post subject: |   |  
| 
 |  
| I think you should ask a linux kernel guy about that. |  | 
| Back to top |  |