LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2005, 02:40 PM   #1
LWATCDR
LQ Newbie
 
Registered: Apr 2005
Posts: 3

Rep: Reputation: 0
Using ttys0


I wrote a little test program in c++ to read data from ttys0. It works but only as root! I have set the user to be a member of tty, I have even tried to set the ttys0 device to 777. Nothing but running as root seems to work. Any suggestions?
 
Old 04-25-2005, 03:18 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I take it /dev/ttyS0 is in the tty group? Because on my system:
Code:
itsme@dreams:~$ ls -l /dev/ttyS0
crw-rw----    1 root     uucp       4,  64 Jul 17  1994 /dev/ttyS0
 
Old 04-25-2005, 03:49 PM   #3
LWATCDR
LQ Newbie
 
Registered: Apr 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Yes it is

crwxrwxrwx 1 root tty 3, 48 2004-12-03 13:50 /dev/ttys0

As you can see I have even gone so far as to make it world rwx Not the best plan for security I know but the box is not on a network yet.
 
Old 04-25-2005, 04:31 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Please show us the code you're using to access it.
 
Old 04-25-2005, 04:50 PM   #5
LWATCDR
LQ Newbie
 
Registered: Apr 2005
Posts: 3

Original Poster
Rep: Reputation: 0
object

Here is the source to the object I wrote to read the serial port.
I am using Linux

//
// File: kybdevice.cc
// Created on: Mon Apr 11 15:01:33 2005
//

#include "kybdevice.h"


kybdevice::kybdevice()
{ // init
errorcode=0;
// Open serial port
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE);
errorcode=44;
}else{
tcgetattr(fd,&oldtio); /* save current port settings */
memset(&newtio, 0, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 1; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
}

}


kybdevice::~kybdevice()
{
// TODO: put destructor code here
if(!errorcode){
tcsetattr(fd,TCSANOW,&oldtio);
}
}

int kybdevice::getKeystrokes(unsigned char *buffer, int bufsze){
res = read(fd,buffer,bufsze);
buffer[res]=0;
}
int kybdevice::getError(void){
return errorcode;
}
return 28;
}
 
Old 04-26-2005, 04:37 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Where it stops when you run it as non-root. At open() call?
 
  


Reply



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
Trying to get COM (ttyS0) working!! mattp Linux - Hardware 6 10-25-2005 02:54 PM
Opening ttyS0 someshss Linux - General 5 08-19-2005 08:44 PM
l and ttyS0 Gins Linux - General 4 08-06-2005 01:13 PM
problems using ttyS0 _HB_ Linux - Software 1 06-29-2004 01:27 AM
Modem ttyS0 Pedroski Linux - Software 0 01-27-2002 04:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:37 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