summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-02 14:17:15 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-02 14:17:15 +0100
commit9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28 (patch)
tree6ec5b46400b7bf5b69af41dd26484f51b02ef9c4 /src
downloadabrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.tar.gz
abrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.tar.xz
abrt-9eb8eb3c8a1b291da7359a9fc1f1c749272a1f28.zip
Initial git commit
Diffstat (limited to 'src')
-rw-r--r--src/Applet/Applet.cpp40
-rw-r--r--src/Applet/CCApplet.cpp45
-rw-r--r--src/Applet/CCApplet.h37
-rw-r--r--src/Applet/Makefile.am6
-rw-r--r--src/Daemon/CrashWatcher.cpp176
-rw-r--r--src/Daemon/CrashWatcher.h58
-rw-r--r--src/Daemon/Daemon.cpp66
-rw-r--r--src/Daemon/Makefile.am6
-rw-r--r--src/Hooks/CCpp.cpp94
-rw-r--r--src/Hooks/Makefile.am5
-rw-r--r--src/Makefile.am1
11 files changed, 534 insertions, 0 deletions
diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp
new file mode 100644
index 00000000..39b0cc41
--- /dev/null
+++ b/src/Applet/Applet.cpp
@@ -0,0 +1,40 @@
+#include "CCApplet.h"
+#include "DBusManager.h"
+#include <iostream>
+
+//@@global applet object
+CApplet *applet;
+static void
+crash_notify_cb(DBusGProxy *proxy, char* progname, gpointer user_data)
+{
+ DBusError error;
+ dbus_error_init (&error);
+#ifdef DEBUG
+ std::cerr << "Application " << progname << " has crashed!" << std::endl;
+#endif
+ /* smth happend, show the blinking icon */
+ applet->BlinkIcon(true);
+ applet->ShowIcon();
+}
+
+int main(int argc, char **argv)
+{
+ Gtk::Main kit(argc, argv);
+ applet = new CApplet();
+ CDBusManager dm;
+ /* connect to the daemon */
+ try
+ {
+ dm.ConnectToDaemon();
+ }
+ catch(std::string err)
+ {
+ std::cerr << "Applet: " << err << std::endl;
+ return -1;
+ }
+ /* catch the CC crash notify on the dbus */
+ dm.RegisterToMessage("Crash",G_CALLBACK(crash_notify_cb),NULL,NULL);
+ /* run the main loop and wait for some events */
+ Gtk::Main::run();
+ return 0;
+}
diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp
new file mode 100644
index 00000000..a48260cd
--- /dev/null
+++ b/src/Applet/CCApplet.cpp
@@ -0,0 +1,45 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "CCApplet.h"
+
+CApplet::CApplet()
+{
+ m_nStatusIcon = Gtk::StatusIcon::create(Gtk::Stock::DIALOG_WARNING);
+ m_nStatusIcon->set_visible(false);
+}
+
+CApplet::~CApplet()
+{
+}
+
+void CApplet::ShowIcon()
+{
+ m_nStatusIcon->set_visible(true);
+}
+
+void CApplet::HideIcon()
+{
+ m_nStatusIcon->set_visible(false);
+}
+
+void CApplet::BlinkIcon(bool pBlink)
+{
+ m_nStatusIcon->set_blinking(pBlink);
+}
diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h
new file mode 100644
index 00000000..83c3e750
--- /dev/null
+++ b/src/Applet/CCApplet.h
@@ -0,0 +1,37 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef CC_APPLET_H_
+#define CC_APPLET_H_
+
+#include <gtkmm.h>
+
+class CApplet
+{
+ private:
+ Glib::RefPtr<Gtk::StatusIcon> m_nStatusIcon;
+ public:
+ CApplet();
+ ~CApplet();
+ void ShowIcon();
+ void HideIcon();
+ void BlinkIcon(bool pBlink);
+};
+
+#endif /*CC_APPLET_H_*/
diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am
new file mode 100644
index 00000000..f98b5bc0
--- /dev/null
+++ b/src/Applet/Makefile.am
@@ -0,0 +1,6 @@
+bin_PROGRAMS = applet
+applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h
+applet_CPPFLAGS = -I../../lib/MiddleWare \
+ -I../../lib/DBus \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(DBUS_GLIB_CFLAGS) $(GTKMM_CFLAGS)
+applet_LDADD = ../../lib/MiddleWare/libMiddleWare.la ../../lib/DBus/libDBus.la $(DL_LIBS) $(GTKMM_LIBS)
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
new file mode 100644
index 00000000..2155b2b7
--- /dev/null
+++ b/src/Daemon/CrashWatcher.cpp
@@ -0,0 +1,176 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "CrashWatcher.h"
+#include <unistd.h>
+#include <iostream>
+#include <climits>
+#include <cstdlib>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <cstring>
+#include <csignal>
+
+void terminate(int signal)
+{
+ exit(0);
+}
+
+gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer daemon){
+ GIOError err;
+ char buf[INOTIFY_BUFF_SIZE];
+ guint len;
+ int i = 0;
+ err = g_io_channel_read (gio, buf, INOTIFY_BUFF_SIZE, &len);
+ if (err != G_IO_ERROR_NONE) {
+ g_warning ("Error reading inotify fd: %d\n", err);
+ return FALSE;
+ }
+ /* reconstruct each event and send to the user's callback */
+ while (i < len) {
+ const char *name;
+ struct inotify_event *event;
+
+ event = (struct inotify_event *) &buf[i];
+ if (event->len)
+ name = &buf[i] + sizeof (struct inotify_event);
+ i += sizeof (struct inotify_event) + event->len;
+#ifdef DEBUG
+ std::cout << "Created file: " << name << std::endl;
+#endif /*DEBUG*/
+ /* send message to dbus */
+ CCrashWatcher *cc = (CCrashWatcher*)daemon;
+ cc->m_nDbus_manager.SendMessage("Crash", name);
+ }
+ return TRUE;
+}
+
+CCrashWatcher::CCrashWatcher(const std::string& pPath)
+{
+ int watch = 0;
+ m_sTarget = pPath;
+ m_nMainloop = g_main_loop_new(NULL,FALSE);
+ /* register on dbus */
+ m_nDbus_manager.RegisterService();
+ if((m_nFd = inotify_init()) == -1){
+ throw std::string("Init Failed");
+ //std::cerr << "Init Failed" << std::endl;
+ exit(-1);
+ }
+ if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1){
+ throw std::string("Add watch failed");
+ //std::cerr << "Add watch failed: " << pPath << std::endl;
+ exit(-1);
+ }
+ m_nGio = g_io_channel_unix_new(m_nFd);
+}
+
+CCrashWatcher::~CCrashWatcher()
+{
+}
+
+void CCrashWatcher::Lock()
+{
+ int lfp = open("crashcatcher.lock",O_RDWR|O_CREAT,0640);
+ if (lfp < 0)
+ throw "CCrashWatcher.cpp:can not open lock file";
+ if (lockf(lfp,F_TLOCK,0) < 0)
+ throw "CCrashWatcher.cpp:Lock:cannot create lock on lockfile";
+ /* only first instance continues */
+ //sprintf(str,"%d\n",getpid());
+ //write(lfp,str,strlen(str)); /* record pid to lockfile */
+}
+
+void CCrashWatcher::StartWatch()
+{
+ char *buff = new char[INOTIFY_BUFF_SIZE];
+ int len = 0;
+ int i = 0;
+ char action[FILENAME_MAX];
+ struct inotify_event *pevent;
+ //run forever
+ while(1){
+ i = 0;
+ len = read(m_nFd,buff,INOTIFY_BUFF_SIZE);
+ while(i < len){
+ pevent = (struct inotify_event *)&buff[i];
+ if (pevent->len)
+ std::strcpy(action, pevent->name);
+ else
+ std::strcpy(action, m_sTarget.c_str());
+ i += sizeof(struct inotify_event) + pevent->len;
+#ifdef DEBUG
+ std::cout << "Created file: " << action << std::endl;
+#endif /*DEBUG*/
+ }
+ }
+ delete[] buff;
+}
+
+/* daemon loop with glib */
+void CCrashWatcher::GStartWatch()
+{
+ char *buff = new char[INOTIFY_BUFF_SIZE];
+ int len = 0;
+ int i = 0;
+ char action[FILENAME_MAX];
+ struct inotify_event *pevent;
+ g_io_add_watch (m_nGio, G_IO_IN, handle_event_cb, this);
+ //enter the event loop
+ g_main_run (m_nMainloop);
+ delete[] buff;
+}
+
+void CCrashWatcher::RegisterSignals()
+{
+ signal(SIGTERM, terminate);
+}
+
+void CCrashWatcher::Daemonize()
+{
+#ifdef DEBUG
+ std::cout << "Daemonize" << std::endl;
+#endif
+ // forking to background
+ pid_t pid = fork();
+ if (pid < 0)
+ {
+ throw "CCrashWatcher.cpp:Daemonize:Fork error";
+ }
+ /* parent exits */
+ if (pid > 0) _exit(0);
+ /* child (daemon) continues */
+ pid_t sid = setsid();
+ if(sid == -1){
+ throw "CCrashWatcher.cpp:Daemonize:setsid failed";
+ }
+ Lock();
+ GStartWatch();
+}
+
+void CCrashWatcher::Run()
+{
+#ifdef DEBUG
+ std::cout << "Run" << std::endl;
+#endif
+ Lock();
+ GStartWatch();
+}
+
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
new file mode 100644
index 00000000..77cc1562
--- /dev/null
+++ b/src/Daemon/CrashWatcher.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef CRASHWATCHER_H_
+#define CRASHWATCHER_H_
+
+#include <string>
+#include <sys/inotify.h>
+#include <sys/inotify.h>
+#include <glib.h>
+#include "DBusManager.h"
+#include "MiddleWare.h"
+
+// 1024 simultaneous actions
+#define INOTIFY_BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
+
+
+class CCrashWatcher
+{
+ private:
+ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer data);
+ void RegisterSignals();
+ void StartWatch();
+ void GStartWatch();
+ void Lock();
+
+ CDBusManager m_nDbus_manager;
+ int m_nFd;
+ GIOChannel* m_nGio;
+ GMainLoop *m_nMainloop;
+ std::string m_sTarget;
+ public:
+ CCrashWatcher(const std::string& pPath);
+ //CCrashWatcher();
+ ~CCrashWatcher();
+ //run as daemon
+ void Daemonize();
+ //don't go background - for debug
+ void Run();
+};
+
+#endif /*CRASHWATCHER_H_*/
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp
new file mode 100644
index 00000000..2f0e575b
--- /dev/null
+++ b/src/Daemon/Daemon.cpp
@@ -0,0 +1,66 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "CrashWatcher.h"
+#include <iostream>
+
+#define daemonize 0
+
+int main(int argc, char** argv){
+ try{
+ CCrashWatcher daemon(DEBUG_DUMPS_DIR);
+ //if (argc > 1){
+ // if (strcmp(argv[1], "-d") == 0){
+ // daemonize = 0;
+ // }
+ // }
+ if(daemonize){
+ try{
+ daemon.Daemonize();
+ }
+ catch(std::string err)
+ {
+ std::cerr << err << std::endl;
+ }
+ catch(...){
+ std::cerr << "daemon.cpp:Daemonize" << std::endl;
+ }
+ }
+ else{
+ try{
+ #ifdef DEBUG
+ std::cerr << "trying to run" << std::endl;
+ #endif /*DEBUG*/
+ daemon.Run();
+ }
+ catch(std::string err)
+ {
+ std::cerr << err << std::endl;
+ }
+ catch(...){
+ std::cerr << "daemon.cpp:Run" << std::endl;
+ }
+ }
+ }
+ catch(std::string err)
+ {
+ std::cerr << "Cannot create daemon: " << err << std::endl;
+ }
+}
+
diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am
new file mode 100644
index 00000000..395eb120
--- /dev/null
+++ b/src/Daemon/Makefile.am
@@ -0,0 +1,6 @@
+bin_PROGRAMS = CrashCatcher
+CrashCatcher_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp
+CrashCatcher_CPPFLAGS = -I../../lib/MiddleWare \
+ -I../../lib/DBus \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(DBUS_GLIB_CFLAGS)
+CrashCatcher_LDADD = ../../lib/MiddleWare/libMiddleWare.la ../../lib/DBus/libDBus.la $(DL_LIBS)
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
new file mode 100644
index 00000000..79156d27
--- /dev/null
+++ b/src/Hooks/CCpp.cpp
@@ -0,0 +1,94 @@
+/*
+ CCpp.cpp - the hook for C/C++ crashing program
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "DebugDump.h"
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#define CORESTEP (1024)
+
+int main(int argc, char** argv)
+{
+ const char* program_name = argv[0];
+ if (argc < 4)
+ {
+ fprintf(stderr, "Usage: %s: <pid> <time> <signal>\n",
+ program_name);
+ return -1;
+ }
+ const char* pid = argv[1];
+ const char* time = argv[2];
+ const char* signal = argv[3];
+
+ if (strcmp(signal, "11") != 0)
+ {
+ return 0;
+ }
+
+ char path[PATH_MAX];
+ CDebugDump dd;
+ snprintf(path, sizeof(path), "%s/%s%s", DEBUG_DUMPS_DIR, time, pid);
+ try
+ {
+ dd.Open(path, CDebugDump::CREATE);
+ dd.SaveText(FILENAME_TIME, time);
+ dd.SaveText(FILENAME_LANGUAGE, "CCpp");
+ dd.SaveProc(pid);
+
+ int size = CORESTEP*sizeof(char);
+ int ii = 0;
+ int data = 0;
+ char* core = NULL;
+ if ((core = (char*)malloc(size)) == NULL)
+ {
+ fprintf(stderr, "%s: not enaught memory.\n", program_name);
+ perror("");
+ return -3;
+ }
+ while ((data = getc(stdin)) != EOF)
+ {
+ if (ii >= size)
+ {
+ size *= CORESTEP*sizeof(char);
+ if ((core = (char*)realloc(core, size)) == NULL)
+ {
+ fprintf(stderr, "%s: not enaught memory.\n", program_name);
+ perror("");
+ return -3;
+ }
+ }
+ core[ii] = data;
+ ii++;
+ }
+ dd.SaveBinary(FILENAME_BINARY_FILE1, core, ii);
+ free(core);
+ }
+ catch (std::string sError)
+ {
+ fprintf(stderr, "%s: %s\n", program_name, sError.c_str());
+ return -2;
+ }
+
+ return 0;
+}
diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am
new file mode 100644
index 00000000..92efb6eb
--- /dev/null
+++ b/src/Hooks/Makefile.am
@@ -0,0 +1,5 @@
+libexec_PROGRAMS = hookCCpp
+hookCCpp_SOURCES = CCpp.cpp
+hookCCpp_LDADD = ../../lib/DebugDump/libDebugDump.la
+hookCCpp_CPPFLAGS = -I$(srcdir)/../../lib/DebugDump \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 00000000..e653c2a8
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = Hooks Daemon Applet \ No newline at end of file