mirror of
https://github.com/KDE/konsole.git
synced 2026-05-18 19:47:16 -04:00
Improve the method of checking whether konsole is started from terminal
The old way of calling isatty() is problmatic, because the checked file descriptor might be redirected by users. For example, 'konsole < /dev/null > /dev/null 2> /dev/null' will make that method fail. The better way is trying to open /dev/tty to see whether we have controlling terminal. Thanks to Askar Safin <safinaskar@mail.ru> for pointing this out.
This commit is contained in:
13
src/main.cpp
13
src/main.cpp
@@ -23,6 +23,8 @@
|
||||
|
||||
// Unix
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// KDE
|
||||
#include <KAboutData>
|
||||
@@ -31,9 +33,6 @@
|
||||
|
||||
#define KONSOLE_VERSION "2.8.999"
|
||||
|
||||
// standard input file descriptor
|
||||
static const int STDIN = 0;
|
||||
|
||||
using Konsole::Application;
|
||||
|
||||
// fill the KAboutData structure with information about contributors to Konsole.
|
||||
@@ -93,7 +92,13 @@ bool shouldUseNewProcess()
|
||||
// Konsole and any debug output or warnings from Konsole are written to
|
||||
// the current terminal
|
||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||
return isatty(STDIN) && !args->isSet("new-tab");
|
||||
|
||||
bool hasControllingTTY = false ;
|
||||
if ( open("/dev/tty", O_RDONLY) != -1 ) {
|
||||
hasControllingTTY = true ;
|
||||
}
|
||||
|
||||
return hasControllingTTY && !args->isSet("new-tab");
|
||||
}
|
||||
|
||||
void fillCommandLineOptions(KCmdLineOptions& options)
|
||||
|
||||
Reference in New Issue
Block a user