Solved Carriage Return

I've turned my service into a daemon and am observing strange behaviour. While it was just a console application, I used printf for output:

Code:
printf("Bla bla bla\n");

Now I have to open the system console — /dev/console — and write into it.

Code:
fCon = fopen("/dev/console", "w");
fprintf(fCon, "Bla bla bla\n");

The output goes to the ttyv0 terminal. If I'm logged in on that terminal, everything is fine. But once I log out - exit - the output continues without carriage returns. I can, of course, add a carriage return explicitly:

Code:
fprintf(fCon, "Bla bla bla\r\n");

But they say you do not need that in UNIX. What's the matter? Where can I read about this?
 
This would be my first attempt to learn what is going on.
screen.jpg
 
Can I ask a more basic question: Is "logging" by printing to the console a sensible choice in the long run? There is no record of the output kept; if someone logs in, the output will mix with their screen content, and so on.

Perhaps you should use syslog instead, and then configure syslog to print the messages from your program to the console. Or log to a file, and when necessary tail the file.
 
Can I ask a more basic question: Is "logging" by printing to the console a sensible choice in the long run?

Perhaps you should use syslog instead

I wouldn't call it logging. I do use syslog for certain events such as when the service blocks an IP address. Network errors are not in this league.

I decided on adding explicit carriage returns. Thanks to everyone for responding.
 
termios(4) is very useful here too. It helped me a lot when I wrote a text editor in C, because for such programs most of the default behaviour should be turned off (it's called to enter a raw terminal mode).
 
Back
Top