1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dpkgpm.cc,v 1.28 2004/01/27 02:25:01 mdz Exp $
4 /* ######################################################################
6 DPKG Package Manager - Provide an interface to dpkg
8 ##################################################################### */
11 #include <apt-pkg/dpkgpm.h>
12 #include <apt-pkg/error.h>
13 #include <apt-pkg/configuration.h>
14 #include <apt-pkg/depcache.h>
15 #include <apt-pkg/pkgrecords.h>
16 #include <apt-pkg/strutl.h>
17 #include <apt-pkg/fileutl.h>
18 #include <apt-pkg/cachefile.h>
23 #include <sys/select.h>
25 #include <sys/types.h>
39 #include <sys/ioctl.h>
48 class pkgDPkgPMPrivate
51 pkgDPkgPMPrivate() : dpkgbuf_pos(0), term_out(NULL
), history_out(NULL
)
54 bool stdin_is_dev_null
;
55 // the buffer we use for the dpkg status-fd reading
65 // Maps the dpkg "processing" info to human readable names. Entry 0
66 // of each array is the key, entry 1 is the value.
67 const std::pair
<const char *, const char *> PackageProcessingOps
[] = {
68 std::make_pair("install", N_("Installing %s")),
69 std::make_pair("configure", N_("Configuring %s")),
70 std::make_pair("remove", N_("Removing %s")),
71 std::make_pair("purge", N_("Completely removing %s")),
72 std::make_pair("disappear", N_("Noting disappearance of %s")),
73 std::make_pair("trigproc", N_("Running post-installation trigger %s"))
76 const std::pair
<const char *, const char *> * const PackageProcessingOpsBegin
= PackageProcessingOps
;
77 const std::pair
<const char *, const char *> * const PackageProcessingOpsEnd
= PackageProcessingOps
+ sizeof(PackageProcessingOps
) / sizeof(PackageProcessingOps
[0]);
79 // Predicate to test whether an entry in the PackageProcessingOps
80 // array matches a string.
81 class MatchProcessingOp
86 MatchProcessingOp(const char *the_target
)
91 bool operator()(const std::pair
<const char *, const char *> &pair
) const
93 return strcmp(pair
.first
, target
) == 0;
98 /* helper function to ionice the given PID
100 there is no C header for ionice yet - just the syscall interface
101 so we use the binary from util-linux
106 if (!FileExists("/usr/bin/ionice"))
108 pid_t Process
= ExecFork();
112 snprintf(buf
, sizeof(buf
), "-p%d", PID
);
114 Args
[0] = "/usr/bin/ionice";
118 execv(Args
[0], (char **)Args
);
120 return ExecWait(Process
, "ionice");
123 // DPkgPM::pkgDPkgPM - Constructor /*{{{*/
124 // ---------------------------------------------------------------------
126 pkgDPkgPM::pkgDPkgPM(pkgDepCache
*Cache
)
127 : pkgPackageManager(Cache
), PackagesDone(0), PackagesTotal(0)
129 d
= new pkgDPkgPMPrivate();
132 // DPkgPM::pkgDPkgPM - Destructor /*{{{*/
133 // ---------------------------------------------------------------------
135 pkgDPkgPM::~pkgDPkgPM()
140 // DPkgPM::Install - Install a package /*{{{*/
141 // ---------------------------------------------------------------------
142 /* Add an install operation to the sequence list */
143 bool pkgDPkgPM::Install(PkgIterator Pkg
,string File
)
145 if (File
.empty() == true || Pkg
.end() == true)
146 return _error
->Error("Internal Error, No file name for %s",Pkg
.Name());
148 // If the filename string begins with DPkg::Chroot-Directory, return the
149 // substr that is within the chroot so dpkg can access it.
150 string
const chrootdir
= _config
->FindDir("DPkg::Chroot-Directory","/");
151 if (chrootdir
!= "/" && File
.find(chrootdir
) == 0)
153 size_t len
= chrootdir
.length();
154 if (chrootdir
.at(len
- 1) == '/')
156 List
.push_back(Item(Item::Install
,Pkg
,File
.substr(len
)));
159 List
.push_back(Item(Item::Install
,Pkg
,File
));
164 // DPkgPM::Configure - Configure a package /*{{{*/
165 // ---------------------------------------------------------------------
166 /* Add a configure operation to the sequence list */
167 bool pkgDPkgPM::Configure(PkgIterator Pkg
)
169 if (Pkg
.end() == true)
172 List
.push_back(Item(Item::Configure
, Pkg
));
174 // Use triggers for config calls if we configure "smart"
175 // as otherwise Pre-Depends will not be satisfied, see #526774
176 if (_config
->FindB("DPkg::TriggersPending", false) == true)
177 List
.push_back(Item(Item::TriggersPending
, PkgIterator()));
182 // DPkgPM::Remove - Remove a package /*{{{*/
183 // ---------------------------------------------------------------------
184 /* Add a remove operation to the sequence list */
185 bool pkgDPkgPM::Remove(PkgIterator Pkg
,bool Purge
)
187 if (Pkg
.end() == true)
191 List
.push_back(Item(Item::Purge
,Pkg
));
193 List
.push_back(Item(Item::Remove
,Pkg
));
197 // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/
198 // ---------------------------------------------------------------------
199 /* This is part of the helper script communication interface, it sends
200 very complete information down to the other end of the pipe.*/
201 bool pkgDPkgPM::SendV2Pkgs(FILE *F
)
203 fprintf(F
,"VERSION 2\n");
205 /* Write out all of the configuration directives by walking the
206 configuration tree */
207 const Configuration::Item
*Top
= _config
->Tree(0);
210 if (Top
->Value
.empty() == false)
213 QuoteString(Top
->FullTag(),"=\"\n").c_str(),
214 QuoteString(Top
->Value
,"\n").c_str());
223 while (Top
!= 0 && Top
->Next
== 0)
230 // Write out the package actions in order.
231 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end(); ++I
)
233 if(I
->Pkg
.end() == true)
236 pkgDepCache::StateCache
&S
= Cache
[I
->Pkg
];
238 fprintf(F
,"%s ",I
->Pkg
.Name());
240 if (I
->Pkg
->CurrentVer
== 0)
243 fprintf(F
,"%s ",I
->Pkg
.CurrentVer().VerStr());
245 // Show the compare operator
247 if (S
.InstallVer
!= 0)
250 if (I
->Pkg
->CurrentVer
!= 0)
251 Comp
= S
.InstVerIter(Cache
).CompareVer(I
->Pkg
.CurrentVer());
258 fprintf(F
,"%s ",S
.InstVerIter(Cache
).VerStr());
263 // Show the filename/operation
264 if (I
->Op
== Item::Install
)
267 if (I
->File
[0] != '/')
268 fprintf(F
,"**ERROR**\n");
270 fprintf(F
,"%s\n",I
->File
.c_str());
272 if (I
->Op
== Item::Configure
)
273 fprintf(F
,"**CONFIGURE**\n");
274 if (I
->Op
== Item::Remove
||
275 I
->Op
== Item::Purge
)
276 fprintf(F
,"**REMOVE**\n");
284 // DPkgPM::RunScriptsWithPkgs - Run scripts with package names on stdin /*{{{*/
285 // ---------------------------------------------------------------------
286 /* This looks for a list of scripts to run from the configuration file
287 each one is run and is fed on standard input a list of all .deb files
288 that are due to be installed. */
289 bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf
)
291 Configuration::Item
const *Opts
= _config
->Tree(Cnf
);
292 if (Opts
== 0 || Opts
->Child
== 0)
296 unsigned int Count
= 1;
297 for (; Opts
!= 0; Opts
= Opts
->Next
, Count
++)
299 if (Opts
->Value
.empty() == true)
302 // Determine the protocol version
303 string OptSec
= Opts
->Value
;
304 string::size_type Pos
;
305 if ((Pos
= OptSec
.find(' ')) == string::npos
|| Pos
== 0)
306 Pos
= OptSec
.length();
307 OptSec
= "DPkg::Tools::Options::" + string(Opts
->Value
.c_str(),Pos
);
309 unsigned int Version
= _config
->FindI(OptSec
+"::Version",1);
313 if (pipe(Pipes
) != 0)
314 return _error
->Errno("pipe","Failed to create IPC pipe to subprocess");
315 SetCloseExec(Pipes
[0],true);
316 SetCloseExec(Pipes
[1],true);
318 // Purified Fork for running the script
319 pid_t Process
= ExecFork();
323 dup2(Pipes
[0],STDIN_FILENO
);
324 SetCloseExec(STDOUT_FILENO
,false);
325 SetCloseExec(STDIN_FILENO
,false);
326 SetCloseExec(STDERR_FILENO
,false);
328 if (_config
->FindDir("DPkg::Chroot-Directory","/") != "/")
330 std::cerr
<< "Chrooting into "
331 << _config
->FindDir("DPkg::Chroot-Directory")
333 if (chroot(_config
->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
340 Args
[2] = Opts
->Value
.c_str();
342 execv(Args
[0],(char **)Args
);
346 FILE *F
= fdopen(Pipes
[1],"w");
348 return _error
->Errno("fdopen","Faild to open new FD");
350 // Feed it the filenames.
353 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end(); ++I
)
355 // Only deal with packages to be installed from .deb
356 if (I
->Op
!= Item::Install
)
360 if (I
->File
[0] != '/')
363 /* Feed the filename of each package that is pending install
365 fprintf(F
,"%s\n",I
->File
.c_str());
375 // Clean up the sub process
376 if (ExecWait(Process
,Opts
->Value
.c_str()) == false)
377 return _error
->Error("Failure running script %s",Opts
->Value
.c_str());
383 // DPkgPM::DoStdin - Read stdin and pass to slave pty /*{{{*/
384 // ---------------------------------------------------------------------
387 void pkgDPkgPM::DoStdin(int master
)
389 unsigned char input_buf
[256] = {0,};
390 ssize_t len
= read(0, input_buf
, sizeof(input_buf
));
392 write(master
, input_buf
, len
);
394 d
->stdin_is_dev_null
= true;
397 // DPkgPM::DoTerminalPty - Read the terminal pty and write log /*{{{*/
398 // ---------------------------------------------------------------------
400 * read the terminal pty and write log
402 void pkgDPkgPM::DoTerminalPty(int master
)
404 unsigned char term_buf
[1024] = {0,0, };
406 ssize_t len
=read(master
, term_buf
, sizeof(term_buf
));
407 if(len
== -1 && errno
== EIO
)
409 // this happens when the child is about to exit, we
410 // give it time to actually exit, otherwise we run
411 // into a race so we sleep for half a second.
412 struct timespec sleepfor
= { 0, 500000000 };
413 nanosleep(&sleepfor
, NULL
);
418 write(1, term_buf
, len
);
420 fwrite(term_buf
, len
, sizeof(char), d
->term_out
);
423 // DPkgPM::ProcessDpkgStatusBuf /*{{{*/
424 // ---------------------------------------------------------------------
427 void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd
, char *line
)
429 bool const Debug
= _config
->FindB("Debug::pkgDPkgProgressReporting",false);
430 // the status we output
431 ostringstream status
;
434 std::clog
<< "got from dpkg '" << line
<< "'" << std::endl
;
437 /* dpkg sends strings like this:
438 'status: <pkg>: <pkg qstate>'
439 errors look like this:
440 'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb : error : trying to overwrite `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', which is also in package krecipes-data
441 and conffile-prompt like this
442 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited
444 Newer versions of dpkg sent also:
445 'processing: install: pkg'
446 'processing: configure: pkg'
447 'processing: remove: pkg'
448 'processing: purge: pkg'
449 'processing: disappear: pkg'
450 'processing: trigproc: trigger'
454 // dpkg sends multiline error messages sometimes (see
455 // #374195 for a example. we should support this by
456 // either patching dpkg to not send multiline over the
457 // statusfd or by rewriting the code here to deal with
458 // it. for now we just ignore it and not crash
459 TokSplitString(':', line
, list
, sizeof(list
)/sizeof(list
[0]));
460 if( list
[0] == NULL
|| list
[1] == NULL
|| list
[2] == NULL
)
463 std::clog
<< "ignoring line: not enough ':'" << std::endl
;
466 const char* const pkg
= list
[1];
467 const char* action
= _strstrip(list
[2]);
469 // 'processing' from dpkg looks like
470 // 'processing: action: pkg'
471 if(strncmp(list
[0], "processing", strlen("processing")) == 0)
474 const char* const pkg_or_trigger
= _strstrip(list
[2]);
475 action
= _strstrip( list
[1]);
476 const std::pair
<const char *, const char *> * const iter
=
477 std::find_if(PackageProcessingOpsBegin
,
478 PackageProcessingOpsEnd
,
479 MatchProcessingOp(action
));
480 if(iter
== PackageProcessingOpsEnd
)
483 std::clog
<< "ignoring unknown action: " << action
<< std::endl
;
486 snprintf(s
, sizeof(s
), _(iter
->second
), pkg_or_trigger
);
488 status
<< "pmstatus:" << pkg_or_trigger
489 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
493 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
495 std::clog
<< "send: '" << status
.str() << "'" << endl
;
497 if (strncmp(action
, "disappear", strlen("disappear")) == 0)
498 handleDisappearAction(pkg_or_trigger
);
502 if(strncmp(action
,"error",strlen("error")) == 0)
504 // urgs, sometime has ":" in its error string so that we
505 // end up with the error message split between list[3]
506 // and list[4], e.g. the message:
507 // "failed in buffer_write(fd) (10, ret=-1): backend dpkg-deb ..."
509 if( list
[4] != NULL
)
510 list
[3][strlen(list
[3])] = ':';
512 status
<< "pmerror:" << list
[1]
513 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
517 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
519 std::clog
<< "send: '" << status
.str() << "'" << endl
;
521 WriteApportReport(list
[1], list
[3]);
524 else if(strncmp(action
,"conffile",strlen("conffile")) == 0)
526 status
<< "pmconffile:" << list
[1]
527 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
531 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
533 std::clog
<< "send: '" << status
.str() << "'" << endl
;
537 vector
<struct DpkgState
> const &states
= PackageOps
[pkg
];
538 const char *next_action
= NULL
;
539 if(PackageOpsDone
[pkg
] < states
.size())
540 next_action
= states
[PackageOpsDone
[pkg
]].state
;
541 // check if the package moved to the next dpkg state
542 if(next_action
&& (strcmp(action
, next_action
) == 0))
544 // only read the translation if there is actually a next
546 const char *translation
= _(states
[PackageOpsDone
[pkg
]].str
);
548 snprintf(s
, sizeof(s
), translation
, pkg
);
550 // we moved from one dpkg state to a new one, report that
551 PackageOpsDone
[pkg
]++;
553 // build the status str
554 status
<< "pmstatus:" << pkg
555 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
559 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
561 std::clog
<< "send: '" << status
.str() << "'" << endl
;
564 std::clog
<< "(parsed from dpkg) pkg: " << pkg
565 << " action: " << action
<< endl
;
568 // DPkgPM::handleDisappearAction /*{{{*/
569 void pkgDPkgPM::handleDisappearAction(string
const &pkgname
)
571 // record the package name for display and stuff later
572 disappearedPkgs
.insert(pkgname
);
574 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(pkgname
);
575 if (unlikely(Pkg
.end() == true))
577 // the disappeared package was auto-installed - nothing to do
578 if ((Cache
[Pkg
].Flags
& pkgCache::Flag::Auto
) == pkgCache::Flag::Auto
)
580 pkgCache::VerIterator PkgVer
= Cache
[Pkg
].InstVerIter(Cache
);
581 if (unlikely(PkgVer
.end() == true))
583 /* search in the list of dependencies for (Pre)Depends,
584 check if this dependency has a Replaces on our package
585 and if so transfer the manual installed flag to it */
586 for (pkgCache::DepIterator Dep
= PkgVer
.DependsList(); Dep
.end() != true; ++Dep
)
588 if (Dep
->Type
!= pkgCache::Dep::Depends
&&
589 Dep
->Type
!= pkgCache::Dep::PreDepends
)
591 pkgCache::PkgIterator Tar
= Dep
.TargetPkg();
592 if (unlikely(Tar
.end() == true))
594 // the package is already marked as manual
595 if ((Cache
[Tar
].Flags
& pkgCache::Flag::Auto
) != pkgCache::Flag::Auto
)
597 pkgCache::VerIterator TarVer
= Cache
[Tar
].InstVerIter(Cache
);
598 if (TarVer
.end() == true)
600 for (pkgCache::DepIterator Rep
= TarVer
.DependsList(); Rep
.end() != true; ++Rep
)
602 if (Rep
->Type
!= pkgCache::Dep::Replaces
)
604 if (Pkg
!= Rep
.TargetPkg())
606 // okay, they are strongly connected - transfer manual-bit
608 std::clog
<< "transfer manual-bit from disappeared »" << pkgname
<< "« to »" << Tar
.FullName() << "«" << std::endl
;
609 Cache
[Tar
].Flags
&= ~Flag::Auto
;
615 // DPkgPM::DoDpkgStatusFd /*{{{*/
616 // ---------------------------------------------------------------------
619 void pkgDPkgPM::DoDpkgStatusFd(int statusfd
, int OutStatusFd
)
624 len
=read(statusfd
, &d
->dpkgbuf
[d
->dpkgbuf_pos
], sizeof(d
->dpkgbuf
)-d
->dpkgbuf_pos
);
625 d
->dpkgbuf_pos
+= len
;
629 // process line by line if we have a buffer
631 while((q
=(char*)memchr(p
, '\n', d
->dpkgbuf
+d
->dpkgbuf_pos
-p
)) != NULL
)
634 ProcessDpkgStatusLine(OutStatusFd
, p
);
635 p
=q
+1; // continue with next line
638 // now move the unprocessed bits (after the final \n that is now a 0x0)
639 // to the start and update d->dpkgbuf_pos
640 p
= (char*)memrchr(d
->dpkgbuf
, 0, d
->dpkgbuf_pos
);
644 // we are interessted in the first char *after* 0x0
647 // move the unprocessed tail to the start and update pos
648 memmove(d
->dpkgbuf
, p
, p
-d
->dpkgbuf
);
649 d
->dpkgbuf_pos
= d
->dpkgbuf
+d
->dpkgbuf_pos
-p
;
652 // DPkgPM::WriteHistoryTag /*{{{*/
653 void pkgDPkgPM::WriteHistoryTag(string
const &tag
, string value
)
655 size_t const length
= value
.length();
658 // poor mans rstrip(", ")
659 if (value
[length
-2] == ',' && value
[length
-1] == ' ')
660 value
.erase(length
- 2, 2);
661 fprintf(d
->history_out
, "%s: %s\n", tag
.c_str(), value
.c_str());
663 // DPkgPM::OpenLog /*{{{*/
664 bool pkgDPkgPM::OpenLog()
666 string
const logdir
= _config
->FindDir("Dir::Log");
667 if(CreateAPTDirectoryIfNeeded(logdir
, logdir
) == false)
668 // FIXME: use a better string after freeze
669 return _error
->Error(_("Directory '%s' missing"), logdir
.c_str());
673 time_t const t
= time(NULL
);
674 struct tm
const * const tmp
= localtime(&t
);
675 strftime(timestr
, sizeof(timestr
), "%F %T", tmp
);
678 string
const logfile_name
= flCombine(logdir
,
679 _config
->Find("Dir::Log::Terminal"));
680 if (!logfile_name
.empty())
682 d
->term_out
= fopen(logfile_name
.c_str(),"a");
683 if (d
->term_out
== NULL
)
684 return _error
->WarningE("OpenLog", _("Could not open file '%s'"), logfile_name
.c_str());
685 setvbuf(d
->term_out
, NULL
, _IONBF
, 0);
686 SetCloseExec(fileno(d
->term_out
), true);
689 pw
= getpwnam("root");
690 gr
= getgrnam("adm");
691 if (pw
!= NULL
&& gr
!= NULL
)
692 chown(logfile_name
.c_str(), pw
->pw_uid
, gr
->gr_gid
);
693 chmod(logfile_name
.c_str(), 0644);
694 fprintf(d
->term_out
, "\nLog started: %s\n", timestr
);
697 // write your history
698 string
const history_name
= flCombine(logdir
,
699 _config
->Find("Dir::Log::History"));
700 if (!history_name
.empty())
702 d
->history_out
= fopen(history_name
.c_str(),"a");
703 if (d
->history_out
== NULL
)
704 return _error
->WarningE("OpenLog", _("Could not open file '%s'"), history_name
.c_str());
705 chmod(history_name
.c_str(), 0644);
706 fprintf(d
->history_out
, "\nStart-Date: %s\n", timestr
);
707 string remove
, purge
, install
, reinstall
, upgrade
, downgrade
;
708 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; ++I
)
710 enum { CANDIDATE
, CANDIDATE_AUTO
, CURRENT_CANDIDATE
, CURRENT
} infostring
;
712 #define HISTORYINFO(X, Y) { line = &X; infostring = Y; }
713 if (Cache
[I
].NewInstall() == true)
714 HISTORYINFO(install
, CANDIDATE_AUTO
)
715 else if (Cache
[I
].ReInstall() == true)
716 HISTORYINFO(reinstall
, CANDIDATE
)
717 else if (Cache
[I
].Upgrade() == true)
718 HISTORYINFO(upgrade
, CURRENT_CANDIDATE
)
719 else if (Cache
[I
].Downgrade() == true)
720 HISTORYINFO(downgrade
, CURRENT_CANDIDATE
)
721 else if (Cache
[I
].Delete() == true)
722 HISTORYINFO((Cache
[I
].Purge() ? purge
: remove
), CURRENT
)
726 line
->append(I
.FullName(false)).append(" (");
727 switch (infostring
) {
728 case CANDIDATE
: line
->append(Cache
[I
].CandVersion
); break;
730 line
->append(Cache
[I
].CandVersion
);
731 if ((Cache
[I
].Flags
& pkgCache::Flag::Auto
) == pkgCache::Flag::Auto
)
732 line
->append(", automatic");
734 case CURRENT_CANDIDATE
: line
->append(Cache
[I
].CurVersion
).append(", ").append(Cache
[I
].CandVersion
); break;
735 case CURRENT
: line
->append(Cache
[I
].CurVersion
); break;
739 if (_config
->Exists("Commandline::AsString") == true)
740 WriteHistoryTag("Commandline", _config
->Find("Commandline::AsString"));
741 WriteHistoryTag("Install", install
);
742 WriteHistoryTag("Reinstall", reinstall
);
743 WriteHistoryTag("Upgrade", upgrade
);
744 WriteHistoryTag("Downgrade",downgrade
);
745 WriteHistoryTag("Remove",remove
);
746 WriteHistoryTag("Purge",purge
);
747 fflush(d
->history_out
);
753 // DPkg::CloseLog /*{{{*/
754 bool pkgDPkgPM::CloseLog()
757 time_t t
= time(NULL
);
758 struct tm
*tmp
= localtime(&t
);
759 strftime(timestr
, sizeof(timestr
), "%F %T", tmp
);
763 fprintf(d
->term_out
, "Log ended: ");
764 fprintf(d
->term_out
, "%s", timestr
);
765 fprintf(d
->term_out
, "\n");
772 if (disappearedPkgs
.empty() == false)
775 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
776 d
!= disappearedPkgs
.end(); ++d
)
778 pkgCache::PkgIterator P
= Cache
.FindPkg(*d
);
779 disappear
.append(*d
);
781 disappear
.append(", ");
783 disappear
.append(" (").append(Cache
[P
].CurVersion
).append("), ");
785 WriteHistoryTag("Disappeared", disappear
);
787 if (d
->dpkg_error
.empty() == false)
788 fprintf(d
->history_out
, "Error: %s\n", d
->dpkg_error
.c_str());
789 fprintf(d
->history_out
, "End-Date: %s\n", timestr
);
790 fclose(d
->history_out
);
792 d
->history_out
= NULL
;
798 // This implements a racy version of pselect for those architectures
799 // that don't have a working implementation.
800 // FIXME: Probably can be removed on Lenny+1
801 static int racy_pselect(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
802 fd_set
*exceptfds
, const struct timespec
*timeout
,
803 const sigset_t
*sigmask
)
809 tv
.tv_sec
= timeout
->tv_sec
;
810 tv
.tv_usec
= timeout
->tv_nsec
/1000;
812 sigprocmask(SIG_SETMASK
, sigmask
, &origmask
);
813 retval
= select(nfds
, readfds
, writefds
, exceptfds
, &tv
);
814 sigprocmask(SIG_SETMASK
, &origmask
, 0);
818 // DPkgPM::Go - Run the sequence /*{{{*/
819 // ---------------------------------------------------------------------
820 /* This globs the operations and calls dpkg
822 * If it is called with "OutStatusFd" set to a valid file descriptor
823 * apt will report the install progress over this fd. It maps the
824 * dpkg states a package goes through to human readable (and i10n-able)
825 * names and calculates a percentage for each step.
827 bool pkgDPkgPM::Go(int OutStatusFd
)
832 sigset_t original_sigmask
;
834 unsigned int const MaxArgs
= _config
->FindI("Dpkg::MaxArgs",8*1024);
835 unsigned int const MaxArgBytes
= _config
->FindI("Dpkg::MaxArgBytes",32*1024);
836 bool const NoTriggers
= _config
->FindB("DPkg::NoTriggers", false);
838 if (RunScripts("DPkg::Pre-Invoke") == false)
841 if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false)
844 // support subpressing of triggers processing for special
845 // cases like d-i that runs the triggers handling manually
846 bool const SmartConf
= (_config
->Find("PackageManager::Configure", "all") != "all");
847 bool const TriggersPending
= _config
->FindB("DPkg::TriggersPending", false);
848 if (_config
->FindB("DPkg::ConfigurePending", SmartConf
) == true)
849 List
.push_back(Item(Item::ConfigurePending
, PkgIterator()));
851 // map the dpkg states to the operations that are performed
852 // (this is sorted in the same way as Item::Ops)
853 static const struct DpkgState DpkgStatesOpMap
[][7] = {
856 {"half-installed", N_("Preparing %s")},
857 {"unpacked", N_("Unpacking %s") },
860 // Configure operation
862 {"unpacked",N_("Preparing to configure %s") },
863 {"half-configured", N_("Configuring %s") },
864 { "installed", N_("Installed %s")},
869 {"half-configured", N_("Preparing for removal of %s")},
870 {"half-installed", N_("Removing %s")},
871 {"config-files", N_("Removed %s")},
876 {"config-files", N_("Preparing to completely remove %s")},
877 {"not-installed", N_("Completely removed %s")},
882 // init the PackageOps map, go over the list of packages that
883 // that will be [installed|configured|removed|purged] and add
884 // them to the PackageOps map (the dpkg states it goes through)
885 // and the PackageOpsTranslations (human readable strings)
886 for (vector
<Item
>::const_iterator I
= List
.begin(); I
!= List
.end(); ++I
)
888 if((*I
).Pkg
.end() == true)
891 string
const name
= (*I
).Pkg
.Name();
892 PackageOpsDone
[name
] = 0;
893 for(int i
=0; (DpkgStatesOpMap
[(*I
).Op
][i
]).state
!= NULL
; ++i
)
895 PackageOps
[name
].push_back(DpkgStatesOpMap
[(*I
).Op
][i
]);
900 d
->stdin_is_dev_null
= false;
905 // this loop is runs once per operation
906 for (vector
<Item
>::const_iterator I
= List
.begin(); I
!= List
.end();)
908 // Do all actions with the same Op in one run
909 vector
<Item
>::const_iterator J
= I
;
910 if (TriggersPending
== true)
911 for (; J
!= List
.end(); ++J
)
915 if (J
->Op
!= Item::TriggersPending
)
917 vector
<Item
>::const_iterator T
= J
+ 1;
918 if (T
!= List
.end() && T
->Op
== I
->Op
)
923 for (; J
!= List
.end() && J
->Op
== I
->Op
; ++J
)
926 // Generate the argument list
927 const char *Args
[MaxArgs
+ 50];
928 // keep track of allocated strings for multiarch package names
929 char *Packages
[MaxArgs
+ 50];
930 unsigned int pkgcount
= 0;
932 // Now check if we are within the MaxArgs limit
934 // this code below is problematic, because it may happen that
935 // the argument list is split in a way that A depends on B
936 // and they are in the same "--configure A B" run
937 // - with the split they may now be configured in different
939 if (J
- I
> (signed)MaxArgs
)
943 unsigned long Size
= 0;
944 string
const Tmp
= _config
->Find("Dir::Bin::dpkg","dpkg");
945 Args
[n
++] = Tmp
.c_str();
946 Size
+= strlen(Args
[n
-1]);
948 // Stick in any custom dpkg options
949 Configuration::Item
const *Opts
= _config
->Tree("DPkg::Options");
953 for (; Opts
!= 0; Opts
= Opts
->Next
)
955 if (Opts
->Value
.empty() == true)
957 Args
[n
++] = Opts
->Value
.c_str();
958 Size
+= Opts
->Value
.length();
962 char status_fd_buf
[20];
966 Args
[n
++] = "--status-fd";
967 Size
+= strlen(Args
[n
-1]);
968 snprintf(status_fd_buf
,sizeof(status_fd_buf
),"%i", fd
[1]);
969 Args
[n
++] = status_fd_buf
;
970 Size
+= strlen(Args
[n
-1]);
975 Args
[n
++] = "--force-depends";
976 Size
+= strlen(Args
[n
-1]);
977 Args
[n
++] = "--force-remove-essential";
978 Size
+= strlen(Args
[n
-1]);
979 Args
[n
++] = "--remove";
980 Size
+= strlen(Args
[n
-1]);
984 Args
[n
++] = "--force-depends";
985 Size
+= strlen(Args
[n
-1]);
986 Args
[n
++] = "--force-remove-essential";
987 Size
+= strlen(Args
[n
-1]);
988 Args
[n
++] = "--purge";
989 Size
+= strlen(Args
[n
-1]);
992 case Item::Configure
:
993 Args
[n
++] = "--configure";
994 Size
+= strlen(Args
[n
-1]);
997 case Item::ConfigurePending
:
998 Args
[n
++] = "--configure";
999 Size
+= strlen(Args
[n
-1]);
1000 Args
[n
++] = "--pending";
1001 Size
+= strlen(Args
[n
-1]);
1004 case Item::TriggersPending
:
1005 Args
[n
++] = "--triggers-only";
1006 Size
+= strlen(Args
[n
-1]);
1007 Args
[n
++] = "--pending";
1008 Size
+= strlen(Args
[n
-1]);
1012 Args
[n
++] = "--unpack";
1013 Size
+= strlen(Args
[n
-1]);
1014 Args
[n
++] = "--auto-deconfigure";
1015 Size
+= strlen(Args
[n
-1]);
1019 if (NoTriggers
== true && I
->Op
!= Item::TriggersPending
&&
1020 I
->Op
!= Item::ConfigurePending
)
1022 Args
[n
++] = "--no-triggers";
1023 Size
+= strlen(Args
[n
-1]);
1026 // Write in the file or package names
1027 if (I
->Op
== Item::Install
)
1029 for (;I
!= J
&& Size
< MaxArgBytes
; ++I
)
1031 if (I
->File
[0] != '/')
1032 return _error
->Error("Internal Error, Pathname to install is not absolute '%s'",I
->File
.c_str());
1033 Args
[n
++] = I
->File
.c_str();
1034 Size
+= strlen(Args
[n
-1]);
1039 string
const nativeArch
= _config
->Find("APT::Architecture");
1040 unsigned long const oldSize
= I
->Op
== Item::Configure
? Size
: 0;
1041 for (;I
!= J
&& Size
< MaxArgBytes
; ++I
)
1043 if((*I
).Pkg
.end() == true)
1045 if (I
->Op
== Item::Configure
&& disappearedPkgs
.find(I
->Pkg
.Name()) != disappearedPkgs
.end())
1047 if (I
->Pkg
.Arch() == nativeArch
|| !strcmp(I
->Pkg
.Arch(), "all"))
1048 Args
[n
++] = I
->Pkg
.Name();
1051 Packages
[pkgcount
] = strdup(I
->Pkg
.FullName(false).c_str());
1052 Args
[n
++] = Packages
[pkgcount
++];
1054 Size
+= strlen(Args
[n
-1]);
1056 // skip configure action if all sheduled packages disappeared
1057 if (oldSize
== Size
)
1063 if (_config
->FindB("Debug::pkgDPkgPM",false) == true)
1065 for (unsigned int k
= 0; k
!= n
; k
++)
1066 clog
<< Args
[k
] << ' ';
1075 /* Mask off sig int/quit. We do this because dpkg also does when
1076 it forks scripts. What happens is that when you hit ctrl-c it sends
1077 it to all processes in the group. Since dpkg ignores the signal
1078 it doesn't die but we do! So we must also ignore it */
1079 sighandler_t old_SIGQUIT
= signal(SIGQUIT
,SIG_IGN
);
1080 sighandler_t old_SIGINT
= signal(SIGINT
,SIG_IGN
);
1082 // ignore SIGHUP as well (debian #463030)
1083 sighandler_t old_SIGHUP
= signal(SIGHUP
,SIG_IGN
);
1090 // if tcgetattr does not return zero there was a error
1091 // and we do not do any pty magic
1092 if (tcgetattr(0, &tt
) == 0)
1094 ioctl(0, TIOCGWINSZ
, (char *)&win
);
1095 if (openpty(&master
, &slave
, NULL
, &tt
, &win
) < 0)
1097 const char *s
= _("Can not write log, openpty() "
1098 "failed (/dev/pts not mounted?)\n");
1099 fprintf(stderr
, "%s",s
);
1101 fprintf(d
->term_out
, "%s",s
);
1102 master
= slave
= -1;
1107 rtt
.c_lflag
&= ~ECHO
;
1108 rtt
.c_lflag
|= ISIG
;
1109 // block SIGTTOU during tcsetattr to prevent a hang if
1110 // the process is a member of the background process group
1111 // http://www.opengroup.org/onlinepubs/000095399/functions/tcsetattr.html
1112 sigemptyset(&sigmask
);
1113 sigaddset(&sigmask
, SIGTTOU
);
1114 sigprocmask(SIG_BLOCK
,&sigmask
, &original_sigmask
);
1115 tcsetattr(0, TCSAFLUSH
, &rtt
);
1116 sigprocmask(SIG_SETMASK
, &original_sigmask
, 0);
1122 _config
->Set("APT::Keep-Fds::",fd
[1]);
1123 // send status information that we are about to fork dpkg
1124 if(OutStatusFd
> 0) {
1125 ostringstream status
;
1126 status
<< "pmstatus:dpkg-exec:"
1127 << (PackagesDone
/float(PackagesTotal
)*100.0)
1128 << ":" << _("Running dpkg")
1130 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
1134 // This is the child
1137 if(slave
>= 0 && master
>= 0)
1140 ioctl(slave
, TIOCSCTTY
, 0);
1147 close(fd
[0]); // close the read end of the pipe
1149 if (_config
->FindDir("DPkg::Chroot-Directory","/") != "/")
1151 std::cerr
<< "Chrooting into "
1152 << _config
->FindDir("DPkg::Chroot-Directory")
1154 if (chroot(_config
->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
1158 if (chdir(_config
->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
1161 if (_config
->FindB("DPkg::FlushSTDIN",true) == true && isatty(STDIN_FILENO
))
1164 if ((Flags
= fcntl(STDIN_FILENO
,F_GETFL
,dummy
)) < 0)
1167 // Discard everything in stdin before forking dpkg
1168 if (fcntl(STDIN_FILENO
,F_SETFL
,Flags
| O_NONBLOCK
) < 0)
1171 while (read(STDIN_FILENO
,&dummy
,1) == 1);
1173 if (fcntl(STDIN_FILENO
,F_SETFL
,Flags
& (~(long)O_NONBLOCK
)) < 0)
1177 /* No Job Control Stop Env is a magic dpkg var that prevents it
1178 from using sigstop */
1179 putenv((char *)"DPKG_NO_TSTP=yes");
1180 execvp(Args
[0],(char **)Args
);
1181 cerr
<< "Could not exec dpkg!" << endl
;
1186 if (_config
->FindB("DPkg::UseIoNice", false) == true)
1189 // clear the Keep-Fd again
1190 _config
->Clear("APT::Keep-Fds",fd
[1]);
1195 // we read from dpkg here
1196 int const _dpkgin
= fd
[0];
1197 close(fd
[1]); // close the write end of the pipe
1203 sigemptyset(&sigmask
);
1204 sigprocmask(SIG_BLOCK
,&sigmask
,&original_sigmask
);
1206 /* clean up the temporary allocation for multiarch package names in
1207 the parent, so we don't leak memory when we return. */
1208 for (unsigned int i
= 0; i
< pkgcount
; i
++)
1211 // the result of the waitpid call
1214 while ((res
=waitpid(Child
,&Status
, WNOHANG
)) != Child
) {
1216 // FIXME: move this to a function or something, looks ugly here
1217 // error handling, waitpid returned -1
1220 RunScripts("DPkg::Post-Invoke");
1222 // Restore sig int/quit
1223 signal(SIGQUIT
,old_SIGQUIT
);
1224 signal(SIGINT
,old_SIGINT
);
1225 signal(SIGHUP
,old_SIGHUP
);
1226 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1229 // wait for input or output here
1231 if (master
>= 0 && !d
->stdin_is_dev_null
)
1233 FD_SET(_dpkgin
, &rfds
);
1235 FD_SET(master
, &rfds
);
1238 select_ret
= pselect(max(master
, _dpkgin
)+1, &rfds
, NULL
, NULL
,
1239 &tv
, &original_sigmask
);
1240 if (select_ret
< 0 && (errno
== EINVAL
|| errno
== ENOSYS
))
1241 select_ret
= racy_pselect(max(master
, _dpkgin
)+1, &rfds
, NULL
,
1242 NULL
, &tv
, &original_sigmask
);
1243 if (select_ret
== 0)
1245 else if (select_ret
< 0 && errno
== EINTR
)
1247 else if (select_ret
< 0)
1249 perror("select() returned error");
1253 if(master
>= 0 && FD_ISSET(master
, &rfds
))
1254 DoTerminalPty(master
);
1255 if(master
>= 0 && FD_ISSET(0, &rfds
))
1257 if(FD_ISSET(_dpkgin
, &rfds
))
1258 DoDpkgStatusFd(_dpkgin
, OutStatusFd
);
1262 // Restore sig int/quit
1263 signal(SIGQUIT
,old_SIGQUIT
);
1264 signal(SIGINT
,old_SIGINT
);
1265 signal(SIGHUP
,old_SIGHUP
);
1269 tcsetattr(0, TCSAFLUSH
, &tt
);
1273 // Check for an error code.
1274 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1276 // if it was set to "keep-dpkg-runing" then we won't return
1277 // here but keep the loop going and just report it as a error
1279 bool const stopOnError
= _config
->FindB("Dpkg::StopOnError",true);
1282 RunScripts("DPkg::Post-Invoke");
1284 if (WIFSIGNALED(Status
) != 0 && WTERMSIG(Status
) == SIGSEGV
)
1285 strprintf(d
->dpkg_error
, "Sub-process %s received a segmentation fault.",Args
[0]);
1286 else if (WIFEXITED(Status
) != 0)
1287 strprintf(d
->dpkg_error
, "Sub-process %s returned an error code (%u)",Args
[0],WEXITSTATUS(Status
));
1289 strprintf(d
->dpkg_error
, "Sub-process %s exited unexpectedly",Args
[0]);
1291 if(d
->dpkg_error
.size() > 0)
1292 _error
->Error("%s", d
->dpkg_error
.c_str());
1303 if (RunScripts("DPkg::Post-Invoke") == false)
1306 if (_config
->FindB("Debug::pkgDPkgPM",false) == false)
1308 std::string
const oldpkgcache
= _config
->FindFile("Dir::cache::pkgcache");
1309 if (oldpkgcache
.empty() == false && RealFileExists(oldpkgcache
) == true &&
1310 unlink(oldpkgcache
.c_str()) == 0)
1312 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
1313 if (srcpkgcache
.empty() == false && RealFileExists(srcpkgcache
) == true)
1315 _error
->PushToStack();
1316 pkgCacheFile CacheFile
;
1317 CacheFile
.BuildCaches(NULL
, true);
1318 _error
->RevertToStack();
1323 Cache
.writeStateFile(NULL
);
1327 // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/
1328 // ---------------------------------------------------------------------
1330 void pkgDPkgPM::Reset()
1332 List
.erase(List
.begin(),List
.end());
1335 // pkgDpkgPM::WriteApportReport - write out error report pkg failure /*{{{*/
1336 // ---------------------------------------------------------------------
1338 void pkgDPkgPM::WriteApportReport(const char *pkgpath
, const char *errormsg
)
1340 string pkgname
, reportfile
, srcpkgname
, pkgver
, arch
;
1341 string::size_type pos
;
1344 if (_config
->FindB("Dpkg::ApportFailureReport", true) == false)
1346 std::clog
<< "configured to not write apport reports" << std::endl
;
1350 // only report the first errors
1351 if(pkgFailures
> _config
->FindI("APT::Apport::MaxReports", 3))
1353 std::clog
<< _("No apport report written because MaxReports is reached already") << std::endl
;
1357 // check if its not a follow up error
1358 const char *needle
= dgettext("dpkg", "dependency problems - leaving unconfigured");
1359 if(strstr(errormsg
, needle
) != NULL
) {
1360 std::clog
<< _("No apport report written because the error message indicates its a followup error from a previous failure.") << std::endl
;
1364 // do not report disk-full failures
1365 if(strstr(errormsg
, strerror(ENOSPC
)) != NULL
) {
1366 std::clog
<< _("No apport report written because the error message indicates a disk full error") << std::endl
;
1370 // do not report out-of-memory failures
1371 if(strstr(errormsg
, strerror(ENOMEM
)) != NULL
||
1372 strstr(errormsg
, "failed to allocate memory") != NULL
) {
1373 std::clog
<< _("No apport report written because the error message indicates a out of memory error") << std::endl
;
1377 // do not report bugs regarding inaccessible local files
1378 if(strstr(errormsg
, strerror(ENOENT
)) != NULL
||
1379 strstr(errormsg
, "cannot access archive") != NULL
) {
1380 std::clog
<< _("No apport report written because the error message indicates an issue on the local system") << std::endl
;
1384 // do not report errors encountered when decompressing packages
1385 if(strstr(errormsg
, "--fsys-tarfile returned error exit status 2") != NULL
) {
1386 std::clog
<< _("No apport report written because the error message indicates an issue on the local system") << std::endl
;
1390 // do not report dpkg I/O errors, this is a format string, so we compare
1391 // the prefix and the suffix of the error with the dpkg error message
1392 vector
<string
> io_errors
;
1393 io_errors
.push_back(string("failed to read on buffer copy for %s"));
1394 io_errors
.push_back(string("failed in write on buffer copy for %s"));
1395 io_errors
.push_back(string("short read on buffer copy for %s"));
1397 for (vector
<string
>::iterator I
= io_errors
.begin(); I
!= io_errors
.end(); I
++)
1399 vector
<string
> list
= VectorizeString(dgettext("dpkg", (*I
).c_str()), '%');
1400 if (list
.size() > 1) {
1401 // we need to split %s, VectorizeString only allows char so we need
1402 // to kill the "s" manually
1403 if (list
[1].size() > 1) {
1404 list
[1].erase(0, 1);
1405 if(strstr(errormsg
, list
[0].c_str()) &&
1406 strstr(errormsg
, list
[1].c_str())) {
1407 std::clog
<< _("No apport report written because the error message indicates a dpkg I/O error") << std::endl
;
1414 // get the pkgname and reportfile
1415 pkgname
= flNotDir(pkgpath
);
1416 pos
= pkgname
.find('_');
1417 if(pos
!= string::npos
)
1418 pkgname
= pkgname
.substr(0, pos
);
1420 // find the package versin and source package name
1421 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(pkgname
);
1422 if (Pkg
.end() == true)
1424 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1425 if (Ver
.end() == true)
1427 pkgver
= Ver
.VerStr() == NULL
? "unknown" : Ver
.VerStr();
1428 pkgRecords
Recs(Cache
);
1429 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1430 srcpkgname
= Parse
.SourcePkg();
1431 if(srcpkgname
.empty())
1432 srcpkgname
= pkgname
;
1434 // if the file exists already, we check:
1435 // - if it was reported already (touched by apport).
1436 // If not, we do nothing, otherwise
1437 // we overwrite it. This is the same behaviour as apport
1438 // - if we have a report with the same pkgversion already
1440 reportfile
= flCombine("/var/crash",pkgname
+".0.crash");
1441 if(FileExists(reportfile
))
1446 // check atime/mtime
1447 stat(reportfile
.c_str(), &buf
);
1448 if(buf
.st_mtime
> buf
.st_atime
)
1451 // check if the existing report is the same version
1452 report
= fopen(reportfile
.c_str(),"r");
1453 while(fgets(strbuf
, sizeof(strbuf
), report
) != NULL
)
1455 if(strstr(strbuf
,"Package:") == strbuf
)
1457 char pkgname
[255], version
[255];
1458 if(sscanf(strbuf
, "Package: %s %s", pkgname
, version
) == 2)
1459 if(strcmp(pkgver
.c_str(), version
) == 0)
1469 // now write the report
1470 arch
= _config
->Find("APT::Architecture");
1471 report
= fopen(reportfile
.c_str(),"w");
1474 if(_config
->FindB("DPkgPM::InitialReportOnly",false) == true)
1475 chmod(reportfile
.c_str(), 0);
1477 chmod(reportfile
.c_str(), 0600);
1478 fprintf(report
, "ProblemType: Package\n");
1479 fprintf(report
, "Architecture: %s\n", arch
.c_str());
1480 time_t now
= time(NULL
);
1481 fprintf(report
, "Date: %s" , ctime(&now
));
1482 fprintf(report
, "Package: %s %s\n", pkgname
.c_str(), pkgver
.c_str());
1483 fprintf(report
, "SourcePackage: %s\n", srcpkgname
.c_str());
1484 fprintf(report
, "ErrorMessage:\n %s\n", errormsg
);
1486 // ensure that the log is flushed
1488 fflush(d
->term_out
);
1490 // attach terminal log it if we have it
1491 string logfile_name
= _config
->FindFile("Dir::Log::Terminal");
1492 if (!logfile_name
.empty())
1497 fprintf(report
, "DpkgTerminalLog:\n");
1498 log
= fopen(logfile_name
.c_str(),"r");
1501 while( fgets(buf
, sizeof(buf
), log
) != NULL
)
1502 fprintf(report
, " %s", buf
);
1503 fprintf(report
, " \n");
1508 // attach history log it if we have it
1509 string histfile_name
= _config
->FindFile("Dir::Log::History");
1510 if (!histfile_name
.empty())
1515 fprintf(report
, "DpkgHistoryLog:\n");
1516 log
= fopen(histfile_name
.c_str(),"r");
1519 while( fgets(buf
, sizeof(buf
), log
) != NULL
)
1520 fprintf(report
, " %s", buf
);
1526 const char *ops_str
[] = {"Install", "Configure","Remove","Purge"};
1527 fprintf(report
, "AptOrdering:\n");
1528 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end(); ++I
)
1529 fprintf(report
, " %s: %s\n", (*I
).Pkg
.Name(), ops_str
[(*I
).Op
]);
1531 // attach dmesg log (to learn about segfaults)
1532 if (FileExists("/bin/dmesg"))
1537 fprintf(report
, "Dmesg:\n");
1538 log
= popen("/bin/dmesg","r");
1541 while( fgets(buf
, sizeof(buf
), log
) != NULL
)
1542 fprintf(report
, " %s", buf
);
1547 // attach df -l log (to learn about filesystem status)
1548 if (FileExists("/bin/df"))
1553 fprintf(report
, "Df:\n");
1554 log
= popen("/bin/df -l","r");
1557 while( fgets(buf
, sizeof(buf
), log
) != NULL
)
1558 fprintf(report
, " %s", buf
);