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

List:       kde-core-devel
Subject:    Proposal: KProcess API enhancement and konsole
From:       Malte Starostik <malte () kde ! org>
Date:       2003-07-27 23:49:43
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi,

the attached KProcess patch adds some functions to check whether the process 
died with a signal. The konsole patch makes use of it in konsole to get rid 
display "Session blah exited with signal 2" etc. if applicable.
On systems where ECOREDUMP is defined the user is also informed whether the 
session dumped core.
Any objections/portability issues?
BTW, is there some function available to translate signal numbers into their 
names (and maybe with a short textual description)?

Cheers,
-Malte



["konsole.diff" (text/x-diff)]

Index: session.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/session.cpp,v
retrieving revision 1.90
diff -u -3 -d -p -r1.90 session.cpp
--- session.cpp	20 Jun 2003 13:04:31 -0000	1.90
+++ session.cpp	27 Jul 2003 23:47:42 -0000
@@ -278,9 +278,19 @@ void TESession::done(int exitStatus)
     emit updateTitle();
     return;
   }
-  if (!wantedClose && exitStatus)
+  if (!wantedClose && (exitStatus || sh->signalled()))
   {
-    KNotifyClient::event("Finished", i18n("Session '%1' exited with status \
%2.").arg(title).arg(exitStatus)); +    if (sh->normalExit())
+      KNotifyClient::event("Finished", i18n("Session '%1' exited with status \
%2.").arg(title).arg(exitStatus)); +    else if (sh->signalled())
+    {
+      if (sh->coreDumped())
+        KNotifyClient::event("Finished", i18n("Session '%1' exited with signal %2 \
and dumped core.").arg(title).arg(sh->exitSignal())); +      else
+        KNotifyClient::event("Finished", i18n("Session '%1' exited with signal \
%2.").arg(title).arg(sh->exitSignal())); +    }
+    else
+      KNotifyClient::event("Finished", i18n("Session '%1' exited \
unexpectedly.").arg(title));  }
   emit processExited();
   emit done(this);


["kprocess.diff" (text/x-diff)]

Index: kprocess.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kprocess.cpp,v
retrieving revision 1.125
diff -u -3 -d -p -r1.125 kprocess.cpp
--- kprocess.cpp	16 Jul 2003 20:58:22 -0000	1.125
+++ kprocess.cpp	27 Jul 2003 23:47:37 -0000
@@ -575,12 +575,32 @@ bool KProcess::normalExit() const
 }
 
 
+bool KProcess::signalled() const
+{
+  return (pid_ != 0) && !runs && WIFSIGNALED(status);
+}
+
+
+bool KProcess::coreDumped() const
+{
+#ifdef WCOREDUMP
+  return signalled() && WCOREDUMP(status);
+#else
+  return false;
+#endif
+}
+
 
 int KProcess::exitStatus() const
 {
   return WEXITSTATUS(status);
 }
 
+
+int KProcess::exitSignal() const
+{
+  return WTERMSIG(status);
+}
 
 
 bool KProcess::writeStdin(const char *buffer, int buflen)
Index: kprocess.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kprocess.h,v
retrieving revision 1.79
diff -u -3 -d -p -r1.79 kprocess.h
--- kprocess.h	16 Jul 2003 20:58:22 -0000	1.79
+++ kprocess.h	27 Jul 2003 23:47:38 -0000
@@ -333,6 +333,27 @@ public:
   bool normalExit() const;
 
   /**
+   * Checks whether the process was killed by a signal.
+   *
+   * @return true if the process has already finished and has not exited
+   * "voluntarily", ie: it has been killed by a signal.
+   *
+   * @since 3.2
+   */
+  bool signalled() const;
+
+  /**
+   * Checks whether a killed process dumped core.
+   *
+   * @return true if @ref signalled() returns true and the process
+   * dumped core. Note that on systems that don't define the
+   * WCOREDUMP macro, the return value is always false.
+   *
+   * @since 3.2
+   */
+  bool coreDumped() const;
+
+  /**
    * Returns the exit status of the process.
    *
    * @return the exit status of the process. Note that this value
@@ -340,6 +361,15 @@ public:
    */
   int exitStatus() const;
 
+  /**
+   * Returns the signal the process was killed by.
+   *
+   * @return the signal number that caused the process to exit.
+   * Note that this value is not valid if @ref signalled() returns false.
+   *
+   * @since 3.2
+   */
+  int exitSignal() const;
 
   /**
    *	 Transmit data to the child process' stdin.

[Attachment #7 (application/pgp-signature)]

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

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