Skip to content

Commit

Permalink
osx breakpad, start the script, allow it to potentially look nice by
Browse files Browse the repository at this point in the history
breaking out the html into 'webinterface' and using handlebars type
stuff to insert the content. The crash reporter python script will
also go away after 2 minutes of having no fontforge process running.
  • Loading branch information
monkeyiq committed Mar 13, 2015
1 parent 70f5745 commit fd4931a
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 13 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -717,6 +717,7 @@ osx/FontForge.app/Contents/Resources/opt/local/Makefile
osx/FontForge.app/Contents/Resources/opt/local/etc/Makefile
osx/FontForge.app/Contents/Resources/opt/local/etc/fonts/Makefile
osx/FontForge.app/Contents/Resources/breakpad/Makefile
osx/FontForge.app/Contents/Resources/breakpad/webinterface/Makefile
osx/FontForge.app/Contents/MacOS/Makefile
osx/FontForge.app/Contents/MacOS/CocoaDialog.app/Makefile
osx/FontForge.app/Contents/MacOS/CocoaDialog.app/Contents/Makefile
Expand Down
3 changes: 3 additions & 0 deletions osx/FontForge.app/Contents/MacOS/FontForge
Expand Up @@ -119,6 +119,9 @@ $scriptdir/fcprogress.pl >|/tmp/zz 2>&1
# This ensures that File Open and File Save (etc) dialogs open in Home
cd ~/ || true

# starting more than one does nothing, and it will close itself.
/Applications/FontForge.app/Contents/MacOS/fontforge-crash-reporter.py &

export PATH="$PATH:$bundle_bin"
echo $WRAPPER $bundle_bin/fontforge -new "$@" > /tmp/oo
$WRAPPER $bundle_bin/fontforge -new "$@" &
87 changes: 74 additions & 13 deletions osx/FontForge.app/Contents/MacOS/fontforge-crash-reporter.py
Expand Up @@ -8,6 +8,8 @@
import json
import urllib
import re
import sys
import time, threading

PORT = 8000 # this must match up to the port used by the following files:
# osx/FontForge.app/Contents/Resources/breakpad/localhost-8000.webloc
Expand All @@ -17,26 +19,84 @@
symbolPath = FFBP_DIR + "/symbols/x86_64/"
dumpFilePath = "/tmp/fontforge.dmp"


def getNumberOfRunningFontForges():
stdout = subprocess.check_output(['ps', '-eo' ,'pid,args'])
count = 0
for line in stdout.splitlines():
pid, cmdline = line.split(' ', 1)
if cmdline.startswith('/Applications/FontForge.app/Contents/Resources/opt/local/bin/fontforge'):
count += 1
return(count)


#
# if there is no fontforge process around for
# 2 minutes then we should probably call it a day too
#
shouldWeDiePreviousCount = 1
def shouldWeDie():
global shouldWeDiePreviousCount
print(time.ctime())
count = getNumberOfRunningFontForges()
print(count)
if shouldWeDiePreviousCount==0 and count==0:
sys.exit()
shouldWeDiePreviousCount = count
threading.Timer(60, shouldWeDie).start()

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

def fileToString(self, filename):
ret = ""
with open( filename, 'r') as f:
ret = f.read()
f.closed
return ret


def do_GET(self):
logging.error(self.headers)


# allow css, js, and png files to get out to make the web interface
# more appealing.
logging.error(self.path)
if re.match( '^/[-a-zA-Z. _]+$', self.path ) is not None:
ct = "image/png"
if self.path.endswith(".css"):
ct = "text/css"
if self.path.endswith(".js"):
ct = "text/javascript"
self.send_response(200)
self.send_header('Content-type', ct)
self.end_headers()
data = self.fileToString( FFBP_DIR + "/webinterface/" + self.path )
self.wfile.write( data )
return

#
# those nasty hackers might be trying to trick us
#
if self.path != "/":
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write("nice try")
return

#
# OK, just the base index.html file then, load and merge.
#
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
bt = self.fileToString( "/tmp/fontforge.dmp.backtrace.4" )
data = self.fileToString( FFBP_DIR + "/webinterface/index.html" )
data = re.sub( '{{report}}', bt, data )
data = re.sub( '{{title}}', 'FontForge%20Breakpad%20Report', data )
self.wfile.write( data )

bt = ""
with open( "/tmp/fontforge.dmp.backtrace.4", 'r') as f:
bt = f.read()
f.closed

self.wfile.write("<html><body>")
self.wfile.write("<p>Please report this crash so we can try to stop it happening for everybody.")
self.wfile.write("<p>If you are a github user, clicking the below link will let you easily submit the backtrace to github and then you can keep an eye on the issue in case the developers need some more information to fix it.<br/>")
self.wfile.write('<p>Report with <a href="https://github.com/fontforge/fontforge/issues/new?title=FontForge%20Breakpad%20Report&body=' + bt + '">github</a>')

self.wfile.write("</body></html>")
#SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

# This gets the raw minidump from the osx crash reporter
# we then create a backtrace using the local breakpad symbols
Expand Down Expand Up @@ -111,7 +171,7 @@ def do_POST(self):
fin.close

#
# Open a browser at ourselves
# Open a browser at ourselves to activate the above GET method
#
subprocess.call(["open", FFBP_DIR + "/localhost-8000.webloc" ])

Expand All @@ -124,6 +184,7 @@ def do_POST(self):

httpd = SocketServer.TCPServer(("127.0.0.1", PORT), Handler)

shouldWeDie()
print "serving at port", PORT
httpd.serve_forever()

2 changes: 2 additions & 0 deletions osx/FontForge.app/Contents/Resources/breakpad/Makefile.am
Expand Up @@ -26,6 +26,8 @@

include $(top_srcdir)/mk/layout.am

SUBDIRS = webinterface

FFBP_FILES = localhost-8000.webloc
FFAPP_FILES = minidump_stackwalk
EXTRA_DIST = $(FFBP_FILES) $(FFAPP_FILES)
Expand Down
@@ -0,0 +1,37 @@
# Copyright (C) 2015 by Ben Martin
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include $(top_srcdir)/mk/layout.am

WEBINTERFACE_FILES = index.html test.png
EXTRA_DIST = $(WEBINTERFACE_FILES)

if PLATFORM_OSX
webinterfacedir = $(pkgdatadir)/osx/FontForge.app/Contents/Resources/breakpad/webinterface
webinterface_DATA = $(WEBINTERFACE_FILES)
endif

-include $(top_srcdir)/git.mk
@@ -0,0 +1,23 @@
<!-- images, css, and js come from this directory only and have a limited name
of normal a-z, the dot, and numbers, and some other characters. Simpler is safer.
-->
<html>
<body>

<p>
Please report this crash so we can try to stop it happening for everybody.

<p>
If you are a github user, clicking the below link will let you easily submit
the backtrace to github and then you can keep an eye on the issue in case
the developers need some more information to fix it.
<br/>
<p>
Report with <a href="https://github.com/fontforge/fontforge/issues/new?title={{title}}&body={{report}}">github</a>

<br/>

<img src="test.png" />
</body>
</html>

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd4931a

Please sign in to comment.