diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2007-09-05 15:10:55 +0200 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2007-09-05 15:10:55 +0200 |
commit | 5d053270a275d1c825c793151f50bf3b680f55ec (patch) | |
tree | 90542eb6ed661286d3f9bc15682ba9e12c2957fd | |
parent | 394957744d64b13473bfeea5403a7a11284510dc (diff) |
* apt-pkg/deb/dpkgpm.{cc,h}:
- fix bug in dpkg log writing when a signal is caught during
select() (LP: #134858)
- write end marker in the log as well
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 78 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.h | 4 | ||||
-rw-r--r-- | debian/changelog | 9 |
3 files changed, 65 insertions, 26 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c386e4b24..90ae413f4 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -498,6 +498,46 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd) } /*}}}*/ +bool pkgDPkgPM::OpenLog() +{ + string logdir = _config->FindDir("Dir::Log"); + if(not FileExists(logdir)) + return _error->Error(_("Directory '%s' missing"), logdir.c_str()); + string logfile_name = flCombine(logdir, + _config->Find("Dir::Log::Terminal")); + if (!logfile_name.empty()) + { + term_out = fopen(logfile_name.c_str(),"a"); + chmod(logfile_name.c_str(), 0600); + // output current time + char outstr[200]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + strftime(outstr, sizeof(outstr), "%F %T", tmp); + fprintf(term_out, "\nLog started: "); + fprintf(term_out, outstr); + fprintf(term_out, "\n"); + } + return true; +} + +bool pkgDPkgPM::CloseLog() +{ + if(term_out) + { + char outstr[200]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + strftime(outstr, sizeof(outstr), "%F %T", tmp); + fprintf(term_out, "Log ended: "); + fprintf(term_out, outstr); + fprintf(term_out, "\n"); + fclose(term_out); + } + term_out = NULL; + return true; +} + // DPkgPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- @@ -571,24 +611,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) } // create log - string logdir = _config->FindDir("Dir::Log"); - if(not FileExists(logdir)) - return _error->Error(_("Directory '%s' missing"), logdir.c_str()); - string logfile_name = flCombine(logdir, - _config->Find("Dir::Log::Terminal")); - if (!logfile_name.empty()) - { - term_out = fopen(logfile_name.c_str(),"a"); - chmod(logfile_name.c_str(), 0600); - // output current time - char outstr[200]; - time_t t = time(NULL); - struct tm *tmp = localtime(&t); - strftime(outstr, sizeof(outstr), "%F %T", tmp); - fprintf(term_out, "\nLog started: "); - fprintf(term_out, outstr); - fprintf(term_out, "\n"); - } + OpenLog(); // this loop is runs once per operation for (vector<Item>::iterator I = List.begin(); I != List.end();) @@ -818,10 +841,15 @@ bool pkgDPkgPM::Go(int OutStatusFd) tv.tv_sec = 1; tv.tv_usec = 0; select_ret = select(max(master, _dpkgin)+1, &rfds, NULL, NULL, &tv); - if (select_ret < 0) - std::cerr << "Error in select()" << std::endl; - else if (select_ret == 0) - continue; + if (select_ret == 0) + continue; + else if (select_ret < 0 && errno == EINTR) + continue; + else if (select_ret < 0) + { + perror("select() returned error"); + continue; + } if(master >= 0 && FD_ISSET(master, &rfds)) DoTerminalPty(master); @@ -859,14 +887,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) if(stopOnError) { - if(term_out) - fclose(term_out); + CloseLog(); return false; } } } - if(term_out) - fclose(term_out); + CloseLog(); if (RunScripts("DPkg::Post-Invoke") == false) return false; diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index debde36a3..e5f197405 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -70,6 +70,10 @@ class pkgDPkgPM : public pkgPackageManager // apport integration void WriteApportReport(const char *pkgpath, const char *errormsg); + // dpkg log + bool OpenLog(); + bool CloseLog(); + // input processing void DoStdin(int master); void DoTerminalPty(int master); diff --git a/debian/changelog b/debian/changelog index 304588fab..b0f414126 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +apt (0.7.6ubuntu8) gutsy; urgency=low + + * apt-pkg/deb/dpkgpm.{cc,h}: + - fix bug in dpkg log writing when a signal is caught during + select() (LP: #134858) + - write end marker in the log as well + + -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 05 Sep 2007 15:03:46 +0200 + apt (0.7.6ubuntu7) gutsy; urgency=low * reupload to fix FTBFS |