[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: KNotify: Crash Prevention Fix
From: Charles <charles () altair ! dhs ! org>
Date: 2000-09-23 1:37:12
[Download RAW message or body]
Ok, here it is. The fresh clean wazzit.
On Fri, 22 Sep 2000, Charles wrote:
> On Fri, 22 Sep 2000, Waldo Bastian wrote:
> > On Fri, 22 Sep 2000, Charles Samuels wrote:
> > > > The following patch prevents KNotify from buggin the user with
> > > > KCrash, and
> > >
> > > most importantly, will allow knotify to work on a system without a
> > > functioning artsd.
> >
> > I suggest not to use your config file for this since this increases the
> > risk of not working/corrupting it. Instead I would do something like:
>
> True.
>
> And will do. but yuck, stdlib syscalls for opening files ;)
>
> > close(creat("$HOME/.knotify-nosound));
> >
> > E.g.:
> >
> > buf[256];
> > const char *home = getenv("HOME");
> > if (!home) return;
> > if (strlen(home) > 256-20) return;
> > strcpy(buf, home);
> > strcat(buf, "/.knotify-nosound);
> > int fd = creat(buf, 0777);
> > if (fd >= 0) close(fd);
> >
> > After all, you are crashing so it's a sort of a wonder if anything works
> > at all.
> >
> > Cheers,
> > Waldo
["knotify_artsdcrash.diff" (text/x-c++)]
? knotify_artsdcrash.diff
Index: knotify.cpp
===================================================================
RCS file: /home/kde/kdelibs/arts/knotify/knotify.cpp,v
retrieving revision 1.37
diff -u -r1.37 knotify.cpp
--- knotify.cpp 2000/09/07 21:00:05 1.37
+++ knotify.cpp 2000/09/23 01:36:09
@@ -19,8 +19,10 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <unistd.h>
-#include <signal.h>
+#include <kcrash.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <kdebug.h>
#include <kmessagebox.h>
@@ -62,6 +64,7 @@
*/
Arts::SimpleSoundServer g_soundServer;
+bool enableAudio;
bool connectSoundServer()
@@ -100,6 +103,7 @@
KCmdLineArgs::init( argc, argv, &aboutdata );
KUniqueApplication::addCmdLineOptions();
+
// initialize application
if ( !KUniqueApplication::start() ) {
kdDebug() << "Running knotify found" << endl;
@@ -109,11 +113,24 @@
KUniqueApplication app;
app.disableSessionManagement();
- // setup mcop communication
- Arts::QIOManager qiomanager;
- Arts::Dispatcher dispatcher(&qiomanager);
- g_soundServer = Arts::SimpleSoundServer::null();
+ KCrash::setCrashHandler(KNotify::crashHandler);
+ { // check if we should shouldn't allow sound events..
+ char file[512];
+ sprintf(file, "%s/.knotify-noaudio", getenv("HOME"));
+ int fd=open(file, O_RDONLY);
+ enableAudio=(fd==-1);
+ if (fd!=-1)
+ close(fd);
+ }
+ // setup mcop communication
+ if (enableAudio)
+ {
+ Arts::QIOManager qiomanager;
+ Arts::Dispatcher dispatcher(&qiomanager);
+ g_soundServer = Arts::SimpleSoundServer::null();
+ }
+
// start notify service
KNotify notify;
app.dcopClient()->setDefaultObject( "Notify" );
@@ -239,12 +256,15 @@
soundFile = locate( "sound", sound );
// Oh dear! we seem to have lost our connection to artsd!
- if( !external && (g_soundServer.isNull() || g_soundServer.error()) )
+ if( enableAudio && !external && (g_soundServer.isNull() || g_soundServer.error()) )
connectSoundServer();
kdDebug() << "KNotify::notifyBySound - trying to play file " << soundFile << endl;
if (!external && !g_soundServer.isNull() && !g_soundServer.error()) {
+ if (!enableAudio)
+ return false;
+
// play sound finally
g_soundServer.play( QFile::encodeName(soundFile).data() );
@@ -318,3 +338,16 @@
{
return d->globalEvents->hasGroup( eventname );
}
+
+void KNotify::crashHandler(int)
+{
+ // try to save the fact knotify likes to crash...
+ char file[512];
+ sprintf(file, "%s/.knotify-noaudio", getenv("HOME"));
+ int fd=creat(file, O_RDWR);
+ close(fd);
+
+ _exit(255);
+}
+
+
Index: knotify.h
===================================================================
RCS file: /home/kde/kdelibs/arts/knotify/knotify.h,v
retrieving revision 1.15
diff -u -r1.15 knotify.h
--- knotify.h 2000/09/07 21:00:05 1.15
+++ knotify.h 2000/09/23 01:36:09
@@ -36,6 +36,8 @@
KNotify();
~KNotify();
+ static void crashHandler(int);
+
protected:
k_dcop:
void notify(const QString &event, const QString &fromApp,
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic