LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-10-2009, 11:36 AM   #1
morty346
Member
 
Registered: Feb 2009
Posts: 52

Rep: Reputation: 15
Serial Port Access Denied using open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);


I am creating a program that opens a serial port for communication but it gets denied when I open it
I have installed a board that has two ports and have verified they are working by using the terminal:
dmesg | grep tty
console [tty0] enabled
0000:02:00.0: ttyS0 at I/O 0xdf00 (irq = 21) is a 16550A
0000:02:00.0: ttyS1 at I/O 0xde00 (irq = 21) is a 16550A

Code:
 int open_port(void)
    {
      int fd; /* File descriptor for the port */


      fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
      if (fd == -1)
      {
       /*
	* Could not open the port.
	*/
	perror("open_port: Unable to open /dev/ttyS0 - ");
      }
      else
	fcntl(fd, F_SETFL, 0);

      return (fd);
    }
Thank you
Greg

open_port: Unable to open /dev/ttyS0 -: Permission denied
return code -1

Last edited by morty346; 02-10-2009 at 11:37 AM. Reason: description
 
Old 02-10-2009, 12:03 PM   #2
morty346
Member
 
Registered: Feb 2009
Posts: 52

Original Poster
Rep: Reputation: 15
Smile

Solved!

chmod o+rw /dev/ttyS0
chmod o+rw /dev/ttyS1

Thank you anyways!
Greg
 
Old 02-10-2009, 01:44 PM   #3
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
You solve it the "bad" way. It's far better to add the user(s) who will run your program to the tty group, then only the users you choose will have access to it, not everybody... Unix philosophy is "keep doors as closed as necessary", not "open everything to everybody until somebody blow my system"...
 
Old 02-11-2009, 08:50 AM   #4
morty346
Member
 
Registered: Feb 2009
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jf.argentino View Post
You solve it the "bad" way. It's far better to add the user(s) who will run your program to the tty group, then only the users you choose will have access to it, not everybody... Unix philosophy is "keep doors as closed as necessary", not "open everything to everybody until somebody blow my system"...
Could you explain in more detail?

I am sick of having to open the terminal to reopen the ports everytime I am on the computer,(this is my personal work computer so I perfer not to ever enter the root password again if that is possible, no one else will be on this computer
 
Old 02-11-2009, 09:13 AM   #5
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
if you
Code:
ls -l /dev/ttyS*
, you'll have something like:
Code:
crw-rw---- 1 root uucp 4, 64 fév 11 13:51 /dev/ttyS0
crw-rw---- 1 root uucp 4, 65 fév 11 13:51 /dev/ttyS1
there you can see that each tty devices belong to "uucp" group, so if your user name is "toto", make something like:
Code:
usermod -a -G uucp toto
to add your login to the "uucp" group, then restore the initial permissions:
Code:
chmod o-rw /dev/ttyS0
chmod o-rw /dev/ttyS1
 
  


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
Squid url port 81 access-denied error steve@korehicom.com Linux - Networking 0 10-13-2005 10:55 AM
usb serial port persimission denied yhus Red Hat 2 09-11-2005 11:25 PM
How to access the second serial port cheema Programming 2 07-29-2004 02:26 PM
Serial Port Access stweaver Linux - Newbie 3 09-14-2003 02:21 AM
Serial Port Access gblydenburgh Linux - General 3 08-21-2001 08:57 AM


All times are GMT -5. The time now is 03:47 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration