[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/io
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2007-04-30 14:27:34
Message-ID: 1177943254.260628.21789.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 659620 by ossi:

add closeSlave().

originally i wanted to scrap slaveFd() alltogether, but this causes too
much trouble. so this is plan b.


 M  +14 -6     kpty.cpp  
 M  +16 -2     kpty.h  


--- trunk/KDE/kdelibs/kdecore/io/kpty.cpp #659619:659620
@@ -3,7 +3,7 @@
    This file is part of the KDE libraries
    Copyright (C) 1997-2002 The Konsole Developers
    Copyright (C) 2002 Waldo Bastian <bastian@kde.org>
-   Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
+   Copyright (C) 2002-2003,2007 Oswald Buddenhagen <ossi@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -125,7 +125,7 @@
 #endif
 
 #include <kdebug.h>
-#include <kstandarddirs.h>	// locate
+#include <kstandarddirs.h>	// findExe
 
 #include <QtCore/Q_PID>
 
@@ -343,10 +343,19 @@
   return true;
 }
 
+void KPty::closeSlave()
+{
+    if (d->slaveFd < 0)
+        return;
+    ::close(d->slaveFd);
+    d->slaveFd = -1;
+}
+
 void KPty::close()
 {
    if (d->masterFd < 0)
       return;
+   closeSlave();
    // don't bother resetting unix98 pty, it will go away after closing master anyway.
    if (memcmp(d->ttyName.data(), "/dev/pts/", 9)) {
       if (!geteuid()) {
@@ -354,15 +363,14 @@
          if (!stat(d->ttyName.data(), &st)) {
             chown(d->ttyName.data(), 0, st.st_gid == getgid() ? 0 : -1);
             chmod(d->ttyName.data(), S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
-	 }
+         }
       } else {
          fcntl(d->masterFd, F_SETFD, 0);
          chownpty(false);
       }
    }
-   ::close(d->slaveFd);
    ::close(d->masterFd);
-   d->masterFd = d->slaveFd = -1;
+   d->masterFd = -1;
 }
 
 void KPty::setCTty()
@@ -384,7 +392,7 @@
     // make our new process group the foreground group on the pty
     int pgrp = getpid();
 #if defined(_POSIX_VERSION) || defined(__svr4__)
-    tcsetpgrp (d->slaveFd, pgrp);
+    tcsetpgrp(d->slaveFd, pgrp);
 #elif defined(TIOCSPGRP)
     ioctl(d->slaveFd, TIOCSPGRP, (char *)&pgrp);
 #endif
--- trunk/KDE/kdelibs/kdecore/io/kpty.h #659619:659620
@@ -2,7 +2,7 @@
 
     Copyright (C) 1997-2002 The Konsole Developers
     Copyright (C) 2002 Waldo Bastian <bastian@kde.org>
-    Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
+    Copyright (C) 2002-2003,2007 Oswald Buddenhagen <ossi@kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -64,6 +64,20 @@
   void close();
 
   /**
+   * Close the pty slave descriptor.
+   *
+   * When creating the pty, KPty also opens the slave and keeps it open.
+   * Consequently the master will never receive an EOF notification.
+   * Usually this is the desired behavior, as a closed pty slave can be
+   * reopened any time - unlike a pipe or socket. However, in some cases
+   * pipe-alike behavior might be desired.
+   *
+   * After this function was called, slaveFd() and setCTty() cannot be
+   * used.
+   */
+  void closeSlave();
+
+  /**
    * Creates a new session and process group and makes this pty the
    * controlling tty.
    */
@@ -129,7 +143,7 @@
   /**
    * @return the file descriptor of the slave pty
    *
-   * This function should be called only while the pty is open.
+   * This function should be called only while the pty slave is open.
    */
   int slaveFd() const;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic