Add Tizen specific changes.
authorWilliam Douglas <william.douglas@intel.com>
Wed, 24 Oct 2012 18:54:04 +0000 (11:54 -0700)
committerWilliam Douglas <william.douglas@intel.com>
Wed, 24 Oct 2012 19:00:00 +0000 (12:00 -0700)
Add changes for popping up a crash backtrace when a coredump is found,
dealing with Tizen's older glib thread handling and a check to avoid
popping up crashes from before a restart.

Signed-off-by: William Douglas <william.douglas@intel.com>
packaging/0001-add-tizen-crash-popup.patch [new file with mode: 0644]
packaging/0002-old-glib-changes.patch [new file with mode: 0644]
packaging/0003-add-check-for-file-creation-time-to-show-only-new-cr.patch [new file with mode: 0644]
packaging/corewatcher.spec

diff --git a/packaging/0001-add-tizen-crash-popup.patch b/packaging/0001-add-tizen-crash-popup.patch
new file mode 100644 (file)
index 0000000..fe13e09
--- /dev/null
@@ -0,0 +1,336 @@
+From 8ea67b4bfcf82d0fc0f297ec47ee7018a2e691d2 Mon Sep 17 00:00:00 2001
+From: William Douglas <william.douglas@intel.com>
+Date: Tue, 9 Oct 2012 11:48:41 -0700
+Subject: [PATCH 1/3] add tizen crash popup
+
+Signed-off-by: William Douglas <william.douglas@intel.com>
+---
+ autogen.sh        |   2 +-
+ configure.ac      |   3 +-
+ src/Makefile.am   |  15 ++++--
+ src/crash-popup.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ src/crash-popup.h |  32 +++++++++++++
+ src/submit.c      |  22 +++++++++
+ 6 files changed, 209 insertions(+), 6 deletions(-)
+ create mode 100644 src/crash-popup.c
+ create mode 100644 src/crash-popup.h
+
+diff --git a/autogen.sh b/autogen.sh
+index 0b59b63..c7a0662 100755
+--- a/autogen.sh
++++ b/autogen.sh
+@@ -3,7 +3,7 @@
+ autoreconf --install
+ args="--prefix=/usr \
+---libdir=/usr/lib64 \
++--libdir=/usr/lib \
+ --sysconfdir=/etc"
+ echo ./configure $args $@
+diff --git a/configure.ac b/configure.ac
+index 9c676b2..98af6f6 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1,5 +1,5 @@
+ AC_PREREQ([2.68])
+-AC_INIT([nitra-corewatcher],[0.9.8],[timothy.c.pepper@linux.intel.com])
++AC_INIT([corewatcher],[0.9.8],[william.douglas@intel.com])
+ AM_INIT_AUTOMAKE([foreign -Wall -Werror])
+ AC_CONFIG_FILES([Makefile src/Makefile])
+ AC_CONFIG_SRCDIR([src/corewatcher.c])
+@@ -13,6 +13,7 @@ AC_PROG_INSTALL
+ # PkgConfig tests
+ PKG_CHECK_MODULES([glib], [glib-2.0 gthread-2.0])
+ PKG_CHECK_MODULES([curl], [libcurl])
++PKG_CHECK_MODULES([ELEMENTARY], [elementary])
+ # Checks for header files.
+ AC_CHECK_HEADERS([stdio.h assert.h sys/types.h sys/stat.h dirent.h signal.h errno.h sched.h fcntl.h stdlib.h string.h sys/time.h syslog.h unistd.h asm/unistd.h])
+diff --git a/src/Makefile.am b/src/Makefile.am
+index af9b2c2..864829e 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -5,7 +5,8 @@ AM_CFLAGS = -std=gnu99 -fstack-protector -D_FORTIFY_SOURCE=2 \
+       -Wformat-security -Werror=format-security
+ sbin_PROGRAMS = \
+-      corewatcher
++      corewatcher \
++      crash-popup
+ corewatcher_SOURCES = \
+       configfile.c \
+@@ -15,8 +16,14 @@ corewatcher_SOURCES = \
+       find_file.c \
+       submit.c
++crash_popup_SOURCES = \
++      crash-popup.c
++
+ noinst_HEADERS = \
+-      corewatcher.h
++      corewatcher.h \
++      crash-popup.h
+-AM_CPPFLAGS = $(AM_CFLAGS) $(glib_CFLAGS) ${curl_CFLAGS}
+-corewatcher_LDADD = $(glib_LIBS) ${curl_LIBS}
++corewatcher_CPPFLAGS = $(AM_CFLAGS) $(glib_CFLAGS) ${curl_CFLAGS}
++crash_popup_CPPFLAGS = $(AM_CFLAGS) @ELEMENTARY_CFLAGS@
++corewatcher_LDADD = @ELEMENTARY_LIBS@
++crash_popup_LDADD = @ELEMENTARY_LIBS@
+diff --git a/src/crash-popup.c b/src/crash-popup.c
+new file mode 100644
+index 0000000..fa1f389
+--- /dev/null
++++ b/src/crash-popup.c
+@@ -0,0 +1,141 @@
++#define _GNU_SOURCE
++/*
++ * Copyright 2007, Intel Corporation
++ *
++ * This file is part of corewatcher.org
++ *
++ * This program file 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; version 2 of the License.
++ *
++ * 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 in a file named COPYING; if not, write to the
++ * Free Software Foundation, Inc.,
++ * 51 Franklin Street, Fifth Floor,
++ * Boston, MA 02110-1301 USA
++ *
++ * Authors:
++ *    Arjan van de Ven <arjan@linux.intel.com>
++ *    William Douglas <william.douglas@intel.com>
++ *    Tim Pepper <timothy.c.pepper@linux.intel.com>
++ */
++
++#include <Elementary.h>
++#include <stdlib.h>
++#include <stdio.h>
++#include <string.h>
++
++#define O_SIZE 1000000
++#define B_SIZE 4
++
++static char output[O_SIZE];
++static const char *bline = "<br>";
++
++EAPI_MAIN int elm_main(int argc, char **argv)
++{
++      Evas_Object *win, *bg, *label, *scroller;
++
++      FILE *f;
++      long flen;
++      int r;
++      unsigned long long int num_written, num_to_write;
++      void *file_contents;
++      char *fcur, *fnext;
++
++      if (argc != 2) {
++              goto main_err;
++      }
++
++      f = fopen(argv[1], "r");
++      if (!f) {
++              goto main_err;
++      }
++      r = fseek(f, 0L, SEEK_END);
++      if (r == -1) {
++              goto main_err;
++      }
++      flen = ftell(f);
++      if (flen == -1) {
++              goto main_err;
++      }
++      rewind(f);
++
++      file_contents = calloc(flen+1, 1);
++      if (file_contents == NULL) {
++              goto main_err;
++      }
++
++      r = fread(file_contents, flen, 1, f);
++      if (ferror(f) || r != flen) {
++              goto main_err;
++      }
++
++      fclose(f);
++
++      memcpy(output, bline, B_SIZE);
++      fcur = (char *)file_contents;
++      num_written = 4;
++
++      /* store the contents of file_contents with '\n' replaced with
++         "<br>" into output */
++      while ((fnext = strchr(fcur, '\n'))) {
++              /* make sure we have space at the end of output for a
++                 '\0', bytes written + bytes to write < space to
++                 write */
++              num_to_write = B_SIZE + (fnext - fcur);
++              if (num_written + num_to_write >= O_SIZE) {
++                      break;
++              }
++              memcpy(output + num_written, fcur, fnext - fcur);
++              memcpy(output + num_written + (fnext - fcur), bline, B_SIZE);
++              /* file_contents null terminated so if we found a '\n'
++                 there must be at least one more character, a '\0' */
++              fcur = fnext + 1;
++              num_written += num_to_write;
++      }
++
++      /* now grab the rest of file_contents after the last '\n' */
++      num_to_write = flen - (fcur - (char *)file_contents);
++      if (num_written + num_to_write < O_SIZE) {
++              /* the rest fits, bytes written + bytes to write was <
++               * space to write */
++              memcpy(output + num_written, fcur, num_to_write);
++              num_written += num_to_write;
++      }
++
++      output[num_written] = 0;
++
++      win = elm_win_add(NULL, "crash-popup", ELM_WIN_BASIC);
++      elm_win_title_set(win, "Crash Found");
++
++      bg = elm_bg_add(win);
++      elm_win_resize_object_add(win, bg);
++      evas_object_show(bg);
++
++      label = elm_label_add(win);
++      elm_object_text_set(label, output);
++      evas_object_show(label);
++
++      scroller = elm_scroller_add(win);
++      elm_win_resize_object_add(win, scroller);
++      evas_object_show(scroller);
++      elm_object_content_set(scroller, label);
++      elm_scroller_bounce_set(scroller, EINA_TRUE, EINA_FALSE);
++      elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_ON);
++      elm_scroller_propagate_events_set(scroller, EINA_TRUE);
++      elm_scroller_page_relative_set(scroller, 0, 1);
++      elm_scroller_region_show(scroller, 50, 50, 200, 200);
++
++      evas_object_show(win);
++
++      elm_run();
++
++main_err:
++      elm_shutdown();
++      return 0;
++}
+diff --git a/src/crash-popup.h b/src/crash-popup.h
+new file mode 100644
+index 0000000..2132282
+--- /dev/null
++++ b/src/crash-popup.h
+@@ -0,0 +1,32 @@
++/*
++ * Copyright 2007, Intel Corporation
++ *
++ * This file is part of corewatcher.org
++ *
++ * This program file 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; version 2 of the License.
++ *
++ * 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 in a file named COPYING; if not, write to the
++ * Free Software Foundation, Inc.,
++ * 51 Franklin Street, Fifth Floor,
++ * Boston, MA 02110-1301 USA
++ *
++ * Authors:
++ *    Arjan van de Ven <arjan@linux.intel.com>
++ *    William Douglas <william.douglas@intel.com>
++ *    Tim Pepper <timothy.c.pepper@linux.intel.com>
++ */
++
++#ifndef __INCLUDE_GUARD_CRASHPOPUP_H_
++#define __INCLUDE_GUARD_CRASHPOPUP_H_
++
++extern EAPI_MAIN int elm_main(int argc, char **argv);
++
++#endif
+diff --git a/src/submit.c b/src/submit.c
+index 878b7a4..adeb778 100644
+--- a/src/submit.c
++++ b/src/submit.c
+@@ -35,12 +35,14 @@
+ #include <asm/unistd.h>
+ #include <curl/curl.h>
++#include "crash-popup.h"
+ #include "corewatcher.h"
+ GMutex bt_mtx;
+ static GCond bt_work;
+ GHashTable *bt_hash;
+ static struct oops *bt_list = NULL;
++static int popup_ran = 0;
+ /*
+  * Adds an oops to the work queue if the oops
+@@ -185,6 +187,16 @@ void report_fail_send(int *failcount, struct oops *oops, struct oops *requeue_li
+       requeue_list = oops;
+ }
++gpointer popup_wrapper(gpointer filename)
++{
++      int r;
++
++      char *argv[2] = {"corewatcher", (char *)filename};
++      elm_init(2, argv);
++      r = elm_main(2, argv);
++      return NULL;
++}
++
+ /*
+  * Worker thread for submitting backtraces
+  *
+@@ -200,6 +212,8 @@ void *submit_loop(void __unused *unused)
+       CURL *handle = NULL;
+       struct curl_httppost *post;
+       struct curl_httppost *last;
++      static crash_ran = 0;
++      GThread *ui_thread;
+       fprintf(stderr, "+ Begin submit_loop()\n");
+@@ -272,6 +286,10 @@ void *submit_loop(void __unused *unused)
+                               } else {
+                                       report_fail_send(&failcount, oops, requeue_list);
+                               }
++                              if (!crash_ran) {
++                                      crash_ran = 1;
++                                      ui_thread = g_thread_new("ui", popup_wrapper, oops->filename);
++                              }
+                       }
+                       openlog("corewatcher", 0, LOG_KERN);
+@@ -284,6 +302,10 @@ void *submit_loop(void __unused *unused)
+                       break;
+               }
+               if (work_list) {
++                      if (!crash_ran) {
++                              crash_ran = 1;
++                              ui_thread = g_thread_new("ui", popup_wrapper, work_list->filename);
++                      }
+                       fprintf(stderr, "+ No urls worked, requeueing all work\n");
+                       requeue_list = work_list;
+               }
+-- 
+1.7.12.2
+
diff --git a/packaging/0002-old-glib-changes.patch b/packaging/0002-old-glib-changes.patch
new file mode 100644 (file)
index 0000000..eee5bc2
--- /dev/null
@@ -0,0 +1,407 @@
+From 71e795cfbd7d277633612ce9acc0c7cd8bf99b8b Mon Sep 17 00:00:00 2001
+From: William Douglas <william.douglas@intel.com>
+Date: Tue, 9 Oct 2012 14:51:36 -0700
+Subject: [PATCH 2/3] old glib changes
+
+Signed-off-by: William Douglas <william.douglas@intel.com>
+---
+ src/Makefile.am   |  5 ++---
+ src/coredump.c    | 22 +++++++++++-----------
+ src/corewatcher.c | 15 ++++++++++-----
+ src/corewatcher.h |  2 +-
+ src/crash-popup.c | 18 ++++++++++++++++--
+ src/crash-popup.h | 32 --------------------------------
+ src/submit.c      | 49 +++++++++++++++++++++++++++++--------------------
+ 7 files changed, 69 insertions(+), 74 deletions(-)
+ delete mode 100644 src/crash-popup.h
+
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 864829e..60d768a 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -20,10 +20,9 @@ crash_popup_SOURCES = \
+       crash-popup.c
+ noinst_HEADERS = \
+-      corewatcher.h \
+-      crash-popup.h
++      corewatcher.h
+ corewatcher_CPPFLAGS = $(AM_CFLAGS) $(glib_CFLAGS) ${curl_CFLAGS}
+ crash_popup_CPPFLAGS = $(AM_CFLAGS) @ELEMENTARY_CFLAGS@
+-corewatcher_LDADD = @ELEMENTARY_LIBS@
++corewatcher_LDADD = $(glib_LIBS) ${curl_LIBS}
+ crash_popup_LDADD = @ELEMENTARY_LIBS@
+diff --git a/src/coredump.c b/src/coredump.c
+index 46c1a6a..4eb1655 100644
+--- a/src/coredump.c
++++ b/src/coredump.c
+@@ -49,9 +49,9 @@
+  * race where the condition is set before the thread is awaiting it and
+  * thus is not woken.
+  */
+-static GMutex pq_mtx;
++static GStaticMutex pq_mtx = G_STATIC_MUTEX_INIT;
+ static gboolean pq = FALSE;
+-static GCond pq_work;
++extern GCond *pq_work;
+ static char *get_release(void)
+ {
+@@ -608,10 +608,10 @@ int scan_core_folder(void __unused *unused)
+       if (work) {
+               fprintf(stderr, "+ Found %d files, setting pq_work condition\n", work);
+-              g_mutex_lock(&pq_mtx);
+-              g_cond_signal(&pq_work);
++              g_static_mutex_lock(&pq_mtx);
++              g_cond_signal(pq_work);
+               pq = TRUE;
+-              g_mutex_unlock(&pq_mtx);
++              g_static_mutex_unlock(&pq_mtx);
+       }
+       fprintf(stderr, "+ End scanning %s...\n", core_folder);
+@@ -630,13 +630,13 @@ void *scan_processed_folder(void __unused *unused)
+       struct oops *oops = NULL;
+       while(1) {
+-              g_mutex_lock(&pq_mtx);
++              g_static_mutex_lock(&pq_mtx);
+               while (pq != TRUE) {
+                       fprintf(stderr, "+ Awaiting work in %s...\n", processed_folder);
+-                      g_cond_wait(&pq_work, &pq_mtx);
++                      g_cond_wait(pq_work, g_static_mutex_get_mutex(&pq_mtx));
+               }
+               pq = FALSE;
+-              g_mutex_unlock(&pq_mtx);
++              g_static_mutex_unlock(&pq_mtx);
+               fprintf(stderr, "+ Begin scanning %s...\n", processed_folder);
+@@ -685,10 +685,10 @@ int scan_folders(void __unused *unused)
+ {
+       scan_core_folder(NULL);
+-      g_mutex_lock(&pq_mtx);
+-      g_cond_signal(&pq_work);
++      g_static_mutex_lock(&pq_mtx);
++      g_cond_signal(pq_work);
+       pq = TRUE;
+-      g_mutex_unlock(&pq_mtx);
++      g_static_mutex_unlock(&pq_mtx);
+       return TRUE;
+ }
+diff --git a/src/corewatcher.c b/src/corewatcher.c
+index eb373b3..d1ec765 100644
+--- a/src/corewatcher.c
++++ b/src/corewatcher.c
+@@ -62,6 +62,9 @@ static struct option opts[] = {
+       { 0, 0, NULL, 0 }
+ };
++GCond *pq_work;
++GCond *bt_work;
++
+ int testmode = 0;
+ static void usage(const char *name)
+@@ -83,6 +86,8 @@ int main(int argc, char**argv)
+       GThread *processing_thread = NULL;
+       g_thread_init (NULL);
++      bt_work = g_cond_new();
++      pq_work = g_cond_new();
+ /*
+  * Signal the kernel that we're not timing critical
+@@ -163,16 +168,16 @@ int main(int argc, char**argv)
+       loop = g_main_loop_new(NULL, FALSE);
+       loop = g_main_loop_ref(loop);
+-      g_mutex_lock(&bt_mtx);
++      g_static_mutex_lock(&bt_mtx);
+       bt_hash = g_hash_table_new(g_str_hash, g_str_equal);
+-      g_mutex_unlock(&bt_mtx);
+-      submit_thread = g_thread_new("corewatcher submit", submit_loop, NULL);
++      g_static_mutex_unlock(&bt_mtx);
++      submit_thread = g_thread_create(submit_loop, NULL, FALSE, NULL);
+       if (submit_thread == NULL) {
+               fprintf(stderr, "+ Unable to start submit thread...exiting\n");
+               return EXIT_FAILURE;
+       }
+-      processing_thread = g_thread_new("corewatcher processing", scan_processed_folder, NULL);
++      processing_thread = g_thread_create(scan_processed_folder, NULL, FALSE, NULL);
+       if (processing_thread == NULL) {
+               fprintf(stderr, "+ Unable to start processing thread...exiting\n");
+               return EXIT_FAILURE;
+@@ -185,7 +190,7 @@ int main(int argc, char**argv)
+               goto out;
+       }
+-      inotify_thread = g_thread_new("corewatcher inotify", inotify_loop, NULL);
++      inotify_thread = g_thread_create(inotify_loop, NULL, FALSE, NULL);
+       if (inotify_thread == NULL)
+               fprintf(stderr, "+ Unable to start inotify thread\n");
+diff --git a/src/corewatcher.h b/src/corewatcher.h
+index 0730515..6c22601 100644
+--- a/src/corewatcher.h
++++ b/src/corewatcher.h
+@@ -56,7 +56,7 @@ struct oops {
+ extern void *inotify_loop(void __unused *unused);
+ /* submit.c */
+-extern GMutex bt_mtx;
++extern GStaticMutex bt_mtx;
+ extern GHashTable *bt_hash;
+ extern void queue_backtrace(struct oops *oops);
+ extern char *replace_name(char *filename, char *replace, char *new);
+diff --git a/src/crash-popup.c b/src/crash-popup.c
+index fa1f389..90bcf7d 100644
+--- a/src/crash-popup.c
++++ b/src/crash-popup.c
+@@ -42,38 +42,51 @@ EAPI_MAIN int elm_main(int argc, char **argv)
+       FILE *f;
+       long flen;
+-      int r;
++      int r = 0;
+       unsigned long long int num_written, num_to_write;
+       void *file_contents;
+       char *fcur, *fnext;
+       if (argc != 2) {
++              fprintf(stderr, "popup bad args\n");
++              r = -1;
+               goto main_err;
+       }
+       f = fopen(argv[1], "r");
+       if (!f) {
++              fprintf(stderr, "popup open failed\n");
++              r = -1;
+               goto main_err;
+       }
+       r = fseek(f, 0L, SEEK_END);
+       if (r == -1) {
++              fprintf(stderr, "popup seek failed\n");
++              r = -1;
+               goto main_err;
+       }
+       flen = ftell(f);
+       if (flen == -1) {
++              fprintf(stderr, "popup ftell failed\n");
++              r = -1;
+               goto main_err;
+       }
+       rewind(f);
+       file_contents = calloc(flen+1, 1);
+       if (file_contents == NULL) {
++              fprintf(stderr, "popup calloc failed\n");
++              r = -1;
+               goto main_err;
+       }
+       r = fread(file_contents, flen, 1, f);
+-      if (ferror(f) || r != flen) {
++      if (ferror(f)) {
++              fprintf(stderr, "popup fread failed\n");
++              r = -1;
+               goto main_err;
+       }
++      r = 0;
+       fclose(f);
+@@ -139,3 +152,4 @@ main_err:
+       elm_shutdown();
+       return 0;
+ }
++ELM_MAIN()
+diff --git a/src/crash-popup.h b/src/crash-popup.h
+deleted file mode 100644
+index 2132282..0000000
+--- a/src/crash-popup.h
++++ /dev/null
+@@ -1,32 +0,0 @@
+-/*
+- * Copyright 2007, Intel Corporation
+- *
+- * This file is part of corewatcher.org
+- *
+- * This program file 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; version 2 of the License.
+- *
+- * 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 in a file named COPYING; if not, write to the
+- * Free Software Foundation, Inc.,
+- * 51 Franklin Street, Fifth Floor,
+- * Boston, MA 02110-1301 USA
+- *
+- * Authors:
+- *    Arjan van de Ven <arjan@linux.intel.com>
+- *    William Douglas <william.douglas@intel.com>
+- *    Tim Pepper <timothy.c.pepper@linux.intel.com>
+- */
+-
+-#ifndef __INCLUDE_GUARD_CRASHPOPUP_H_
+-#define __INCLUDE_GUARD_CRASHPOPUP_H_
+-
+-extern EAPI_MAIN int elm_main(int argc, char **argv);
+-
+-#endif
+diff --git a/src/submit.c b/src/submit.c
+index adeb778..826485f 100644
+--- a/src/submit.c
++++ b/src/submit.c
+@@ -35,11 +35,10 @@
+ #include <asm/unistd.h>
+ #include <curl/curl.h>
+-#include "crash-popup.h"
+ #include "corewatcher.h"
+-GMutex bt_mtx;
+-static GCond bt_work;
++GStaticMutex bt_mtx = G_STATIC_MUTEX_INIT;
++extern GCond *bt_work;
+ GHashTable *bt_hash;
+ static struct oops *bt_list = NULL;
+ static int popup_ran = 0;
+@@ -53,12 +52,12 @@ void queue_backtrace(struct oops *oops)
+       if (!oops || !oops->filename)
+               return;
+-      g_mutex_lock(&bt_mtx);
++      g_static_mutex_lock(&bt_mtx);
+       /* if this is already on bt_list / bt_hash, free and done */
+       if (g_hash_table_lookup(bt_hash, oops->filename)) {
+               FREE_OOPS(oops);
+-              g_mutex_unlock(&bt_mtx);
++              g_static_mutex_unlock(&bt_mtx);
+               return;
+       }
+@@ -66,8 +65,8 @@ void queue_backtrace(struct oops *oops)
+       oops->next = bt_list;
+       bt_list = oops;
+       g_hash_table_insert(bt_hash, oops->filename, oops->filename);
+-      g_cond_signal(&bt_work);
+-      g_mutex_unlock(&bt_mtx);
++      g_cond_signal(bt_work);
++      g_static_mutex_unlock(&bt_mtx);
+ }
+ /*
+@@ -81,7 +80,7 @@ static void print_queue(void)
+       struct oops *oops = NULL, *next = NULL;
+       int count = 0;
+-      g_mutex_lock(&bt_mtx);
++      g_static_mutex_lock(&bt_mtx);
+       oops = bt_list;
+       while (oops) {
+               fprintf(stderr, "+ Submit text is:\n---[start of oops]---\n%s\n---[end of oops]---\n", oops->text);
+@@ -91,7 +90,7 @@ static void print_queue(void)
+               count++;
+       }
+       g_hash_table_remove_all(bt_hash);
+-      g_mutex_unlock(&bt_mtx);
++      g_static_mutex_unlock(&bt_mtx);
+ }
+ static size_t writefunction(void *ptr, size_t size, size_t nmemb, void __attribute((unused)) *stream)
+@@ -172,9 +171,9 @@ void report_good_send(int *sentcount, struct oops *oops)
+       rename(oops->filename, newfilename);
+       free(newfilename);
+-      g_mutex_lock(&bt_mtx);
++      g_static_mutex_lock(&bt_mtx);
+       g_hash_table_remove(bt_hash, oops->filename);
+-      g_mutex_unlock(&bt_mtx);
++      g_static_mutex_unlock(&bt_mtx);
+       FREE_OOPS(oops);
+ }
+@@ -190,10 +189,20 @@ void report_fail_send(int *failcount, struct oops *oops, struct oops *requeue_li
+ gpointer popup_wrapper(gpointer filename)
+ {
+       int r;
+-
+-      char *argv[2] = {"corewatcher", (char *)filename};
+-      elm_init(2, argv);
+-      r = elm_main(2, argv);
++      char popup_name[] = "crash-popup";
++      char *argv[3];
++
++      argv[0] = popup_name;
++      argv[1] = (char *)filename;
++      argv[2] = NULL;
++
++      printf("display file %s\n", argv[1]);
++      pid_t pid = fork();
++      if (pid == 0) {
++              printf("calling %s\n", argv[0]);
++              r = execvp(argv[0], argv);
++              printf("oops bad exec\n");
++      }
+       return NULL;
+ }
+@@ -225,7 +234,7 @@ void *submit_loop(void __unused *unused)
+       }
+       while (1) {
+-              g_mutex_lock(&bt_mtx);
++              g_static_mutex_lock(&bt_mtx);
+               while (!bt_list) {
+                       if (requeue_list) {
+                               bt_list = requeue_list;
+@@ -234,13 +243,13 @@ void *submit_loop(void __unused *unused)
+                       } else {
+                               fprintf(stderr, "+ submit_loop() queue empty, awaiting new work\n");
+                       }
+-                      g_cond_wait(&bt_work, &bt_mtx);
++                      g_cond_wait(bt_work, g_static_mutex_get_mutex(&bt_mtx));
+               }
+               fprintf(stderr, "+ submit_loop() checking for work\n");
+               /* pull out current work and release the mutex */
+               work_list = bt_list;
+               bt_list = NULL;
+-              g_mutex_unlock(&bt_mtx);
++              g_static_mutex_unlock(&bt_mtx);
+               /* net init */
+               handle = curl_easy_init();
+@@ -288,7 +297,7 @@ void *submit_loop(void __unused *unused)
+                               }
+                               if (!crash_ran) {
+                                       crash_ran = 1;
+-                                      ui_thread = g_thread_new("ui", popup_wrapper, oops->filename);
++                                      ui_thread = g_thread_create(popup_wrapper, oops->detail_filename, FALSE, NULL);
+                               }
+                       }
+@@ -304,7 +313,7 @@ void *submit_loop(void __unused *unused)
+               if (work_list) {
+                       if (!crash_ran) {
+                               crash_ran = 1;
+-                              ui_thread = g_thread_new("ui", popup_wrapper, work_list->filename);
++                              ui_thread = g_thread_create(popup_wrapper, work_list->detail_filename, FALSE, NULL);
+                       }
+                       fprintf(stderr, "+ No urls worked, requeueing all work\n");
+                       requeue_list = work_list;
+-- 
+1.7.12.2
+
diff --git a/packaging/0003-add-check-for-file-creation-time-to-show-only-new-cr.patch b/packaging/0003-add-check-for-file-creation-time-to-show-only-new-cr.patch
new file mode 100644 (file)
index 0000000..420e6da
--- /dev/null
@@ -0,0 +1,118 @@
+From dbe06f7c2ec5533a96e3e26f9f87676a0d1e0004 Mon Sep 17 00:00:00 2001
+From: William Douglas <william.douglas@intel.com>
+Date: Tue, 9 Oct 2012 16:01:22 -0700
+Subject: [PATCH 3/3] add check for file creation time to show only new
+ crashes
+
+Signed-off-by: William Douglas <william.douglas@intel.com>
+---
+ src/submit.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------
+ 1 file changed, 51 insertions(+), 6 deletions(-)
+
+diff --git a/src/submit.c b/src/submit.c
+index 826485f..8f24070 100644
+--- a/src/submit.c
++++ b/src/submit.c
+@@ -26,10 +26,13 @@
+  */
+ #include <unistd.h>
++#include <time.h>
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <syslog.h>
++#include <fcntl.h>
++#include <sys/types.h>
+ #include <sys/stat.h>
+ #include <glib.h>
+ #include <asm/unistd.h>
+@@ -191,21 +194,63 @@ gpointer popup_wrapper(gpointer filename)
+       int r;
+       char popup_name[] = "crash-popup";
+       char *argv[3];
++      pid_t pid;
+       argv[0] = popup_name;
+       argv[1] = (char *)filename;
+       argv[2] = NULL;
+-      printf("display file %s\n", argv[1]);
+-      pid_t pid = fork();
++      fprintf(stderr, "+ display file %s\n", argv[1]);
++      pid = fork();
+       if (pid == 0) {
+-              printf("calling %s\n", argv[0]);
++              fprintf(stderr, "+ calling %s\n", argv[0]);
+               r = execvp(argv[0], argv);
+-              printf("oops bad exec\n");
++              fprintf(stderr, "+ bad exec\n");
+       }
+       return NULL;
+ }
++int is_new_crash(char *filename)
++{
++      struct stat st;
++      time_t t, uptime;
++      int f, r;
++      char buf[1000], c;
++
++      r = stat(filename, &st);
++      if (r == -1) {
++              fprintf(stderr, "+ stat failed\n");
++              return 1;
++      }
++
++      f = open("/proc/uptime", O_RDONLY);
++      if (f == -1) {
++              fprintf(stderr, "+ couldn't open /proc/uptime\n");
++              return 1;
++      }
++
++      read(f, &buf, 999);
++      buf[999] = 0;
++      c = strchr(buf, '.');
++      if (!c) {
++              return 1;
++      }
++      c = 0;
++      uptime = atoll(buf);
++
++      t = time(NULL);
++
++      printf("current time = %llu\n", t);
++      printf("file modify time = %llu\n", st.st_mtime);
++      printf("uptime = %llu\n", uptime);
++
++      if (t - st.st_mtime < uptime) {
++              return 1;
++      }
++
++      return 0;
++}
++
+ /*
+  * Worker thread for submitting backtraces
+  *
+@@ -295,7 +340,7 @@ void *submit_loop(void __unused *unused)
+                               } else {
+                                       report_fail_send(&failcount, oops, requeue_list);
+                               }
+-                              if (!crash_ran) {
++                              if (!crash_ran && is_new_crash(oops->detail_filename)) {
+                                       crash_ran = 1;
+                                       ui_thread = g_thread_create(popup_wrapper, oops->detail_filename, FALSE, NULL);
+                               }
+@@ -311,7 +356,7 @@ void *submit_loop(void __unused *unused)
+                       break;
+               }
+               if (work_list) {
+-                      if (!crash_ran) {
++                      if (!crash_ran && is_new_crash(work_list->detail_filename)) {
+                               crash_ran = 1;
+                               ui_thread = g_thread_create(popup_wrapper, work_list->detail_filename, FALSE, NULL);
+                       }
+-- 
+1.7.12.2
+
index 4ce7dda..6ab6a21 100644 (file)
@@ -6,6 +6,9 @@ Group:      System/Base
 License:    GPLv2
 Source0:    corewatcher-%{version}.tar.gz
 Source1:    corewatcher
+Patch0:     0001-add-tizen-crash-popup.patch
+Patch1:     0002-old-glib-changes.patch
+Patch2:     0003-add-check-for-file-creation-time-to-show-only-new-cr.patch
 Requires:   gdb
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  curl-devel
@@ -20,6 +23,10 @@ reporting database.
 %prep
 %setup -q -n %{name}-%{version}
 
+%patch0 -p1
+%patch1 -p1
+%patch2 -p1
+
 %build
 %reconfigure