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.
wilder-portage
Jekyll Wu 14 years ago
parent 1e722af5ab
commit 819475ff1d
  1. 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)

Loading…
Cancel
Save