По идее, терминал должен настраиваться так, чтобы фразы "Start working" не было видно, однако этого не происходит.
main.c:
Код:
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include "terminal.h"
int main()
{
int exit_code = 0;
openLog();
startTermios();
getTermiosSettings();
printf("Start working.\n");
returnTermiosSettings();
printf("The End\n");
exit( exit_code );
}
Код:
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
FILE *logfile;
static FILE *current_tty;
static struct termios default_termios_settings;
int
openLog ( void )
{
logfile = fopen( "counter.log", "w" );
if ( ! logfile )
{
fprintf( logfile, "Shit happens: Unable to open logfile\n");
return 0;
}
else
return 1;
}
int
startTermios( void )
{
current_tty = fopen( "/dev/tty", "w" );
if ( ! current_tty )
{
fprintf( logfile, "Shit happens: Can't open TTY\n");
return 0;
}
if ( tcgetattr( fileno(current_tty), &default_termios_settings) != 0 )
fprintf( logfile, "Shit happens: tcgetattr() return TRUE\n");
/* return 1; */
else
fprintf( logfile, "Shit happens: tcgetattr() return FALSE\n");
/* return 0; */
return 1;
}
int
getTermiosSettings( void )
{
struct termios changed_termios_settings;
changed_termios_settings = default_termios_settings;
changed_termios_settings.c_lflag &= ~ICANON;
changed_termios_settings.c_lflag &= ~ISIG;
changed_termios_settings.c_lflag &= ~ECHO;
changed_termios_settings.c_cc[VMIN] = 1;
changed_termios_settings.c_cc[VTIME] = 0;
if ( tcsetattr( fileno(current_tty), TCSANOW, &changed_termios_settings ))
{
fprintf( logfile, "Shit happens: Could not set attributes for terminal with getTermiosSettings()\n" );
tcsetattr( fileno(current_tty), TCSANOW, &default_termios_settings );
return 0;
}
else
fprintf( logfile, "Shit happens 2: Could not set attributes for terminal with getTermiosSettings()\n" );
/* return 1; */
}
int
returnTermiosSettings( void )
{
if ( tcsetattr( fileno(current_tty), TCSANOW, &default_termios_settings ))
{
fprintf( logfile, "Shit happens: Can't return terminal default settings.\n");
return 0;
}
else
return 1;
}
Код:
extern FILE *logfile;
int openLog ( void );
int startTermios(void);
int getTermiosSettings(void);
int returnTermiosSettings(void);
Код:
Shit happens: tcgetattr() return FALSE
Shit happens 2: Could not set attributes for terminal with getTermiosSettings()
Если кто-нибудь понял, где я ошибься, буду очень признателен за помощь.