From dbc7d4e32743cbfe14f0043a613c0e937d7d2992 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 29 Nov 2018 16:50:42 -0500 Subject: [PATCH] 2018-11-29 Fred Gleason * Fixed a bug in the 'RDTextFile()' function that caused zombification of client programs. --- ChangeLog | 3 +++ lib/rdapplication.cpp | 17 +++++++++++++++++ lib/rdapplication.h | 2 ++ lib/rdtextfile.cpp | 24 ++++++++++++++---------- lib/rdtextfile.h | 2 +- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4fd68275..3d8156c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18070,3 +18070,6 @@ * Incremented the database version to 301. * Added an 'Inlcude Import Markers in Finished Logs' checkbox to the 'Edit Service' dialog in rdadmin(1). +2018-11-29 Fred Gleason + * Fixed a bug in the 'RDTextFile()' function that caused zombification + of client programs. diff --git a/lib/rdapplication.cpp b/lib/rdapplication.cpp index 0b6509df..5a056d06 100644 --- a/lib/rdapplication.cpp +++ b/lib/rdapplication.cpp @@ -28,6 +28,15 @@ #include "rdcmd_switch.h" RDApplication *rda=NULL; +QStringList __rdapplication_temp_files; + +void __RDApplication_ExitCallback() +{ + for(int i=0;i<__rdapplication_temp_files.size();i++) { + unlink(__rdapplication_temp_files.at(i).toUtf8()); + } +} + RDApplication::RDApplication(const QString &module_name,const QString &cmdname, const QString &usage,QObject *parent) @@ -49,6 +58,8 @@ RDApplication::RDApplication(const QString &module_name,const QString &cmdname, app_station=NULL; app_system=NULL; app_user=NULL; + + atexit(__RDApplication_ExitCallback); } @@ -260,6 +271,12 @@ bool RDApplication::dropTable(const QString &tbl_name) } +void RDApplication::addTempFile(const QString &pathname) +{ + __rdapplication_temp_files.push_back(pathname); +} + + void RDApplication::userChangedData() { app_user->setName(app_ripc->user()); diff --git a/lib/rdapplication.h b/lib/rdapplication.h index de03e4ba..8b391ad0 100644 --- a/lib/rdapplication.h +++ b/lib/rdapplication.h @@ -22,6 +22,7 @@ #define RDAPPLICATION_H #include +#include #include #include @@ -58,6 +59,7 @@ class RDApplication : public QObject RDUser *user(); void log(RDConfig::LogPriority prio,const QString &msg); bool dropTable(const QString &tbl_name); + void addTempFile(const QString &pathname); private slots: void userChangedData(); diff --git a/lib/rdtextfile.cpp b/lib/rdtextfile.cpp index 93d9b4a7..aebb273e 100644 --- a/lib/rdtextfile.cpp +++ b/lib/rdtextfile.cpp @@ -18,30 +18,30 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include -#include #include +#include +#include #include #include -#include +#include "rdapplication.h" #include "rdconf.h" #include "rd.h" #include "rdtempdirectory.h" #include -bool RDTextFile(const QString &data) +bool RDTextFile(const QString &data,bool delete_on_exit) { char tmpfile[256]; - QString editor; + char editor[256]; if(getenv("VISUAL")==NULL) { - editor=RD_LINUX_EDITOR; + strncpy(editor,RD_LINUX_EDITOR,256); } else { - editor=getenv("VISUAL"); + strncpy(editor,getenv("VISUAL"),256); } strcpy(tmpfile,RDTempDirectory::basePath()+"/rdreportXXXXXX"); int fd=mkstemp(tmpfile); @@ -51,10 +51,14 @@ bool RDTextFile(const QString &data) } write(fd,data.utf8(),data.utf8().length()); ::close(fd); + if(delete_on_exit) { + rda->addTempFile(tmpfile); + } + + char *args[]={editor,tmpfile,(char *)NULL}; if(fork()==0) { - system(editor+" "+QString(tmpfile)); - unlink(tmpfile); - exit(0); + execvp(editor,args); + exit(1); } return true; } diff --git a/lib/rdtextfile.h b/lib/rdtextfile.h index b4178246..3a1c8047 100644 --- a/lib/rdtextfile.h +++ b/lib/rdtextfile.h @@ -23,7 +23,7 @@ #include -bool RDTextFile(const QString &data); +bool RDTextFile(const QString &data,bool delete_on_exit=true); #endif // RDTEXTFILE_H