LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-30-2013, 08:17 AM   #1
leonp
LQ Newbie
 
Registered: Apr 2005
Posts: 7

Rep: Reputation: 0
Question Freeing ttyS0 for loopback test - application hangs/blocks


I run Montavista 2.6.18 on ARM/TI.
I need to use external loopback on ttyS0, which is linux console by default.
The application will test the whole serial track via loopback.

It is started from initd (script in rc3.d) and getty start in iniittab is allowed as "once" only (not respawn).
The reduced initialization code looks like:

system("killall getty");
out = open("/dev/null", O_WRONLY);
dup2(out, fileno(stdout))
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
tcgetattr(fd, &Opts);
cfmakeraw(&Opts);
Opts.c_cflag &= ~CRTSCTS;
Opts.c_cflag |= CLOCAL | CREAD;
tcsetattr(fd,TCSANOW,&Opts);

Now, the questions/problems:
1. When the first line of the initialization code system("killall getty") is active, application hangs at this point (never exits system() call), if the loopback is closed. Otherwise it passes OK, the test starts, and even passes, when I close the loopback later.

2. Removing system() call allows the application to initialize and pass to the first write(fd,"Test text",10), which hangs.
Again the same - starting with loopback opened and closing it later after makes everything working as required.

Any hints/recommendations/help will be highly appreciated...
 
Old 06-30-2013, 10:12 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You have to disable ttys0 from being started for login.

The problem is that the init process will restart the getty process as soon as it exits. The only to way to prevent that is to stop init from starting it. And that requires you to change the configuration for init. Otherwise you are in a race condition between init respawining getty before you get your test started.

I'm not familiar with Montavista, but usually the console terminals are started in /etc/inittab.

For such testing, I would suggest using an unused runlevel that doesn't initialize a getty ttys0 (try to have an alternate though). This runlevel can then be used to run your diagnostics. When they have finished, have the diagnostic script switch run levels to something else.
 
Old 07-01-2013, 01:46 AM   #3
leonp
LQ Newbie
 
Registered: Apr 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you, JPollard (Jonathan Pollard? My Respect!

May be you did not noticed that I start getty in inittab with option "once" instead of "respawn" in hope that this will allow one login, if required. Therefore I do kill getty, when the testing starts. Otherwise, one will still be able to login...

But you point to the right way - I tried to remove getty at all and found that after this everything works fine!
SO, the issue is - how to allow getty to run when there is no need in testing (most of the work).
 
Old 07-01-2013, 08:52 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
That was why I mentioned using an "unused" run level. Going to that run level would stop the getty from running, when the tests would be done, the last thing the script would do is switch runlevels to the default. To start the test, just tell init to switch to the test run level. The current login would be terminated (getty execs login, login execs shell, so killing the process that was started by getty will terminate the login).
 
  


Reply

Tags
programming, serial port, ttys0



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] problem with ethernet loopback test using loopback plug/stub: receiving socket not se mcha Linux - Kernel 3 08-26-2010 11:28 AM
kernel hangs after freeing memory ashlesha Linux - Software 2 10-31-2006 12:30 PM
Red Hat 6.2 disk space error - "Freeing blocks not in datazone" richfink Linux - Software 2 08-26-2006 04:08 PM
xen hangs when freeing unused kernel memory camlinux Linux - Server 1 08-09-2006 03:34 PM
boot hangs after freeing kernel memory complus Linux - Security 20 08-21-2003 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:44 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
Open Source Consulting | Domain Registration