summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/dpkgpm.cc65
-rw-r--r--apt-pkg/deb/dpkgpm.h4
2 files changed, 47 insertions, 22 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 8e1d7c85a..ce4d4b44b 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -503,6 +503,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 /*{{{*/
// ---------------------------------------------------------------------
@@ -579,24 +619,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();)
@@ -881,14 +904,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 448091626..b7f45b978 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -66,6 +66,10 @@ class pkgDPkgPM : public pkgPackageManager
bool RunScriptsWithPkgs(const char *Cnf);
bool SendV2Pkgs(FILE *F);
+ // dpkg log
+ bool OpenLog();
+ bool CloseLog();
+
// input processing
void DoStdin(int master);
void DoTerminalPty(int master);