Implementing temporary file handling via TempFile.

Made ede-about and ede-bug-report resizeable
This commit is contained in:
Sanel Zukan 2009-07-09 12:04:19 +00:00
parent be2cb085b9
commit f137dc9f2d
7 changed files with 85 additions and 117 deletions

View File

@ -133,14 +133,17 @@ int main(int argc, char **argv) {
Fl_Box* image_box = new Fl_Box(5, 5, 60, 55);
image_box->image(image_ede);
Fl_Box* ede_label_box = new Fl_Box(70, 10, 365, 25, "Equinox Deskop Environment " PACKAGE_VERSION);
Fl_Box* ede_label_box = new Fl_Box(70, 10, 300, 25, "Equinox Deskop Environment " PACKAGE_VERSION);
ede_label_box->labelfont(1);
ede_label_box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
Fl_Box* ede_copy_box = new Fl_Box(70, 35, 365, 25, "Copyright (c) by EDE Authors 2000-2009");
Fl_Box* ede_copy_box = new Fl_Box(70, 35, 300, 25, "Copyright (c) by EDE Authors 2000-2009");
ede_copy_box->labelsize(11);
ede_copy_box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_TOP);
// resizable box
Fl_Box* rbox1 = new Fl_Box(385, 10, 40, 50);
Fl_Group::current()->resizable(rbox1);
title_group->end();
Fl_Text_Display* txt_display = new Fl_Text_Display(10, 78, 420, 212);
@ -163,9 +166,13 @@ int main(int argc, char **argv) {
txt_display->highlight_data(stylebuff, style_table,
sizeof(style_table) / sizeof(style_table[0]), 'A', 0, 0);
// resizable box
Fl_Box* rbox2 = new Fl_Box(270, 238, 50, 37);
Fl_Button* close_button = new Fl_Button(340, 300, 90, 25, _("&Close"));
close_button->callback(close_cb);
Fl_Group::current()->resizable(rbox2);
win->end();
win->show(argc, argv);
return Fl::run();

View File

@ -5,8 +5,8 @@ code_name {.cxx}
Function {} {open
} {
Fl_Window {} {
label {About EDE} open selected
xywh {292 190 440 335} type Double visible
label {About EDE} open
xywh {393 141 440 335} type Double resizable visible
} {
Fl_Group {} {open
xywh {0 0 440 65} box FLAT_BOX color 7 labelsize 14
@ -16,16 +16,23 @@ Function {} {open
}
Fl_Box {} {
label {Equinox Desktop Environment}
xywh {70 10 365 25} labelfont 1 align 20
xywh {70 10 300 25} labelfont 1 align 20
}
Fl_Box {} {
label {Copyright (c) by EDE Authors 2000-2008}
xywh {70 35 365 25} labelsize 11 align 21
xywh {70 35 300 25} labelsize 11 align 21
}
Fl_Box {} {
xywh {385 10 40 50} labelsize 14 resizable
}
}
Fl_Text_Display {} {
xywh {10 78 420 212} labelsize 14 textsize 14
}
Fl_Box {} {selected
xywh {270 238 50 37} labelsize 14 resizable
code0 {/* resizable box */}
}
Fl_Button {} {
label {&Close}
xywh {340 300 90 25}

View File

@ -10,7 +10,7 @@
* See COPYING for details.
*/
#ifndef HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -32,10 +32,9 @@
#include <edelib/Debug.h>
#ifdef HAVE_CURL
#include "BugzillaSender.h"
#include "BugImage.h"
#include "icons/bug.xpm"
# include "BugzillaSender.h"
# include "BugImage.h"
# include "icons/bug.xpm"
#endif
EDELIB_NS_USING(String)
@ -181,12 +180,16 @@ int main(int argc, char** argv) {
E_WARNING(E_STRLOC ": Unable to read '%s' as debugger output. Continuing...\n");
}
/* resizable box */
Fl_Box *rbox = new Fl_Box(180, 273, 55, 37);
Fl_Button *send = new Fl_Button(285, 330, 90, 25, _("&Send"));
send->callback(send_cb, win);
Fl_Button *close = new Fl_Button(380, 330, 90, 25, _("&Close"));
close->callback(close_cb, win);
Fl_Group::current()->resizable(rbox);
win->window_icon(bug_xpm);
/* win->show(argc, argv); */
win->show();

View File

@ -6,9 +6,9 @@ Function {} {open
} {
Fl_Window {} {
label {EDE Bug Reporting Tool} open
xywh {369 205 480 365} type Double visible
xywh {357 193 480 365} type Double resizable visible
} {
Fl_Box {} {selected
Fl_Box {} {
image {../icons/bug.png} xywh {10 10 60 59}
}
Fl_Box {} {
@ -41,5 +41,9 @@ Note: valid email address is required, so developers could contact you for more
label {&Cancel}
xywh {380 330 90 25}
}
Fl_Box {} {selected
xywh {180 273 55 37} labelsize 14 resizable
code0 {/* resizable box */}
}
}
}

View File

@ -34,6 +34,7 @@
#include <edelib/MessageBox.h>
#include <edelib/Run.h>
#include <edelib/File.h>
#include <edelib/TempFile.h>
#include "CrashDialog.h"
#include "GdbOutput.h"
@ -44,6 +45,7 @@
#define WIN_H_EXPANDED 340
EDELIB_NS_USING(String)
EDELIB_NS_USING(TempFile)
EDELIB_NS_USING(alert)
EDELIB_NS_USING(run_async)
EDELIB_NS_USING(file_remove)
@ -54,7 +56,6 @@ static Fl_Text_Display *txt_display;
static Fl_Text_Buffer *txt_buf;
static Fl_Button *save_as;
static Fl_Button *show_details;
static GdbOutput *gdb;
static bool info_was_collected;
static const ProgramDetails *pdetails;
@ -121,8 +122,11 @@ static void collect_info_once(void) {
write_host_info();
if(gdb->fds_opened() && gdb->run())
txt_buf->appendfile(gdb->output_path());
TempFile tmp;
tmp.set_auto_delete(true);
if(gdb_output_generate(pdetails->path, tmp))
txt_buf->appendfile(tmp.name());
info_was_collected = true;
}
@ -154,33 +158,30 @@ static void report_cb(Fl_Widget*, void*) {
collect_info_once();
errno = 0;
int fd;
char tmp[] = "/tmp/.ecrash-dump.XXXXXX";
if((fd = mkstemp(tmp)) == -1) {
alert(_("Unable to create temporary file: (%i) %s"), errno, strerror(errno));
TempFile tmp;
if(!tmp.create("/tmp/.ecrash-dump")) {
alert(_("Unable to create temporary file: (%i) %s"), tmp.status(), strerror(tmp.status()));
return;
}
close(fd);
txt_buf->savefile(tmp);
/* close it since we need the file name */
tmp.close();
run_async("%s --gdb-dump %s", bug_tool.c_str(), tmp);
txt_buf->savefile(tmp.name());
run_async("%s --gdb-dump %s", bug_tool.c_str(), tmp.name());
/* wait some time until the file was read; dumb, I know :( */
sleep(1);
file_remove(tmp);
/* remove it */
tmp.unlink();
}
int crash_dialog_show(const ProgramDetails& p) {
info_was_collected = false;
pdetails = &p;
gdb = new GdbOutput();
gdb->set_program_path(p.path);
gdb->fds_open();
win = new edelib::Window(380, WIN_H_NORMAL, _("EDE Crash Handler"));
win->begin();
Fl_Box* image_box = new Fl_Box(10, 10, 65, 60);
@ -224,7 +225,5 @@ int crash_dialog_show(const ProgramDetails& p) {
win->window_icon(core_xpm);
win->show();
int ret = Fl::run();
delete gdb;
return ret;
return Fl::run();
}

View File

@ -10,21 +10,15 @@
* See COPYING for details.
*/
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <edelib/Missing.h>
#include <edelib/File.h>
#include <edelib/Debug.h>
#include <edelib/File.h>
#include <edelib/FileTest.h>
#include <edelib/TempFile.h>
#include "GdbOutput.h"
@ -32,79 +26,53 @@
#define CORE_FILE "core"
EDELIB_NS_USING(String)
EDELIB_NS_USING(TempFile)
EDELIB_NS_USING(file_path)
EDELIB_NS_USING(file_test)
EDELIB_NS_USING(file_remove)
EDELIB_NS_USING(FILE_TEST_IS_REGULAR)
static void close_and_invalidate(int &fd) {
if(fd != -1) {
::close(fd);
fd = -1;
}
}
static int write_str(int fd, const char *str) {
int len = strlen(str);
return ::write(fd, str, len);
}
GdbOutput::~GdbOutput() {
close_and_invalidate(sfd);
close_and_invalidate(ofd);
bool gdb_output_generate(const char *path, TempFile &t) {
E_RETURN_VAL_IF_FAIL(path != NULL, false);
if(!gdb_script_path.empty())
file_remove(gdb_script_path.c_str());
if(!gdb_output_path.empty())
file_remove(gdb_output_path.c_str());
int tfd = -1;
TempFile scr;
file_remove(CORE_FILE);
}
bool GdbOutput::fds_open(void) {
errno = 0;
char sp[] = "/tmp/.ecrash-script.XXXXXX";
char op[] = "/tmp/.ecrash-output.XXXXXX";
sfd = mkstemp(sp);
if(sfd == -1) {
E_WARNING(E_STRLOC ": Unable to open script file: (%i), %s\n", errno, strerror(errno));
if(!scr.create("/tmp/.ecrash-script")) {
E_WARNING(E_STRLOC ": Unable to create temporary file for debugger script: (%i) %s",
scr.status(), strerror(scr.status()));
return false;
}
/* copy it as fast as possible */
gdb_script_path = sp;
ofd = mkstemp(op);
if(ofd == -1) {
E_WARNING(E_STRLOC ": Unable to open output file: (%i), %s\n", errno, strerror(errno));
if(!t.create("/tmp/.ecrash-output")) {
E_WARNING(E_STRLOC ": Unable to create temporary file for debugger output: (%i) %s",
t.status(), strerror(t.status()));
return false;
}
/* copy it as fast as possible */
gdb_output_path = op;
return true;
}
bool GdbOutput::run(void) {
E_RETURN_VAL_IF_FAIL(fds_opened(), false);
tfd = t.handle();
/* write script */
::write(sfd, "bt\nquit\n", 8);
close_and_invalidate(sfd);
::write(scr.handle(), "bt\nquit\n", 8);
scr.set_auto_delete(true);
scr.close();
String gdb_path = file_path("gdb");
if(gdb_path.empty()) {
/* write straight to the file, so dialog could show it */
write_str(ofd, "Unable to find gdb. Please install it first");
write_str(tfd, "Unable to find gdb. Please install it first");
/* see it as valid, so dialog could be shown */
return true;
}
if(!file_test(CORE_FILE, FILE_TEST_IS_REGULAR)) {
write_str(ofd, "Unable to find '"CORE_FILE"'. Backtrace will not be done.");
write_str(tfd, "Unable to find '"CORE_FILE"'. Backtrace will not be done.");
/* see it as valid, so dialog could be shown */
return true;
}
@ -112,20 +80,22 @@ bool GdbOutput::run(void) {
pid_t pid = fork();
if(pid == -1) {
close_and_invalidate(ofd);
E_WARNING(E_STRLOC ": Unable to fork the process\n");
return false;
} else if(pid == 0) {
dup2(ofd, 1);
close_and_invalidate(ofd);
/* child; redirect to the file */
dup2(tfd, 1);
t.close();
::write(1, " ", 1);
char* argv[8];
argv[0] = (char*)gdb_path.c_str();
argv[1] = "--quiet";
argv[2] = "--batch";
argv[3] = "-x";
argv[4] = (char*)gdb_script_path.c_str();
argv[5] = (char*)program_path;
argv[4] = (char*)scr.name();
argv[5] = (char*)path;
argv[6] = (char*)CORE_FILE;
argv[7] = 0;
@ -140,5 +110,6 @@ bool GdbOutput::run(void) {
}
}
file_remove(CORE_FILE);
return true;
}

View File

@ -13,30 +13,7 @@
#ifndef __GDBOUTPUT_H__
#define __GDBOUTPUT_H__
#ifndef PATH_MAX
# define PATH_MAX 256
#endif
#include <edelib/String.h>
class GdbOutput {
private:
int sfd, ofd;
const char *program_path;
edelib::String gdb_output_path;
edelib::String gdb_script_path;
public:
GdbOutput() : sfd(-1), ofd(-1), program_path(NULL) { }
~GdbOutput();
void set_program_path(const char *p) { program_path = p; }
bool fds_open(void);
bool fds_opened(void) { return (sfd != 1 && ofd != -1); }
bool run(void);
const char *output_path(void) { return (gdb_output_path.empty() ? NULL : gdb_output_path.c_str()); }
};
class edelib::TempFile;
bool gdb_output_generate(const char *path, edelib::TempFile &t);
#endif