dpkgpm.cc 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: dpkgpm.cc,v 1.28 2004/01/27 02:25:01 mdz Exp $
  4. /* ######################################################################
  5. DPKG Package Manager - Provide an interface to dpkg
  6. ##################################################################### */
  7. /*}}}*/
  8. // Includes /*{{{*/
  9. #include <apt-pkg/dpkgpm.h>
  10. #include <apt-pkg/error.h>
  11. #include <apt-pkg/configuration.h>
  12. #include <apt-pkg/depcache.h>
  13. #include <apt-pkg/strutl.h>
  14. #include <apti18n.h>
  15. #include <apt-pkg/fileutl.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <fcntl.h>
  19. #include <sys/select.h>
  20. #include <sys/types.h>
  21. #include <sys/wait.h>
  22. #include <signal.h>
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <algorithm>
  27. #include <sstream>
  28. #include <map>
  29. #include <termios.h>
  30. #include <unistd.h>
  31. #include <sys/ioctl.h>
  32. #include <pty.h>
  33. #include <config.h>
  34. #include <apti18n.h>
  35. /*}}}*/
  36. using namespace std;
  37. namespace
  38. {
  39. // Maps the dpkg "processing" info to human readable names. Entry 0
  40. // of each array is the key, entry 1 is the value.
  41. const std::pair<const char *, const char *> PackageProcessingOps[] = {
  42. std::make_pair("install", N_("Installing %s")),
  43. std::make_pair("configure", N_("Configuring %s")),
  44. std::make_pair("remove", N_("Removing %s")),
  45. std::make_pair("purge", N_("Completely removing %s")),
  46. std::make_pair("disappear", N_("Noting disappearance of %s")),
  47. std::make_pair("trigproc", N_("Running post-installation trigger %s"))
  48. };
  49. const std::pair<const char *, const char *> * const PackageProcessingOpsBegin = PackageProcessingOps;
  50. const std::pair<const char *, const char *> * const PackageProcessingOpsEnd = PackageProcessingOps + sizeof(PackageProcessingOps) / sizeof(PackageProcessingOps[0]);
  51. // Predicate to test whether an entry in the PackageProcessingOps
  52. // array matches a string.
  53. class MatchProcessingOp
  54. {
  55. const char *target;
  56. public:
  57. MatchProcessingOp(const char *the_target)
  58. : target(the_target)
  59. {
  60. }
  61. bool operator()(const std::pair<const char *, const char *> &pair) const
  62. {
  63. return strcmp(pair.first, target) == 0;
  64. }
  65. };
  66. }
  67. /* helper function to ionice the given PID
  68. there is no C header for ionice yet - just the syscall interface
  69. so we use the binary from util-linux
  70. */
  71. static bool
  72. ionice(int PID)
  73. {
  74. if (!FileExists("/usr/bin/ionice"))
  75. return false;
  76. pid_t Process = ExecFork();
  77. if (Process == 0)
  78. {
  79. char buf[32];
  80. snprintf(buf, sizeof(buf), "-p%d", PID);
  81. const char *Args[4];
  82. Args[0] = "/usr/bin/ionice";
  83. Args[1] = "-c3";
  84. Args[2] = buf;
  85. Args[3] = 0;
  86. execv(Args[0], (char **)Args);
  87. }
  88. return ExecWait(Process, "ionice");
  89. }
  90. // DPkgPM::pkgDPkgPM - Constructor /*{{{*/
  91. // ---------------------------------------------------------------------
  92. /* */
  93. pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache)
  94. : pkgPackageManager(Cache), dpkgbuf_pos(0),
  95. term_out(NULL), history_out(NULL), PackagesDone(0), PackagesTotal(0)
  96. {
  97. }
  98. /*}}}*/
  99. // DPkgPM::pkgDPkgPM - Destructor /*{{{*/
  100. // ---------------------------------------------------------------------
  101. /* */
  102. pkgDPkgPM::~pkgDPkgPM()
  103. {
  104. }
  105. /*}}}*/
  106. // DPkgPM::Install - Install a package /*{{{*/
  107. // ---------------------------------------------------------------------
  108. /* Add an install operation to the sequence list */
  109. bool pkgDPkgPM::Install(PkgIterator Pkg,string File)
  110. {
  111. if (File.empty() == true || Pkg.end() == true)
  112. return _error->Error("Internal Error, No file name for %s",Pkg.Name());
  113. // If the filename string begins with DPkg::Chroot-Directory, return the
  114. // substr that is within the chroot so dpkg can access it.
  115. string const chrootdir = _config->FindDir("DPkg::Chroot-Directory","/");
  116. if (chrootdir != "/" && File.find(chrootdir) == 0)
  117. {
  118. size_t len = chrootdir.length();
  119. if (chrootdir.at(len - 1) == '/')
  120. len--;
  121. List.push_back(Item(Item::Install,Pkg,File.substr(len)));
  122. }
  123. else
  124. List.push_back(Item(Item::Install,Pkg,File));
  125. return true;
  126. }
  127. /*}}}*/
  128. // DPkgPM::Configure - Configure a package /*{{{*/
  129. // ---------------------------------------------------------------------
  130. /* Add a configure operation to the sequence list */
  131. bool pkgDPkgPM::Configure(PkgIterator Pkg)
  132. {
  133. if (Pkg.end() == true)
  134. return false;
  135. List.push_back(Item(Item::Configure, Pkg));
  136. // Use triggers for config calls if we configure "smart"
  137. // as otherwise Pre-Depends will not be satisfied, see #526774
  138. if (_config->FindB("DPkg::TriggersPending", false) == true)
  139. List.push_back(Item(Item::TriggersPending, PkgIterator()));
  140. return true;
  141. }
  142. /*}}}*/
  143. // DPkgPM::Remove - Remove a package /*{{{*/
  144. // ---------------------------------------------------------------------
  145. /* Add a remove operation to the sequence list */
  146. bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge)
  147. {
  148. if (Pkg.end() == true)
  149. return false;
  150. if (Purge == true)
  151. List.push_back(Item(Item::Purge,Pkg));
  152. else
  153. List.push_back(Item(Item::Remove,Pkg));
  154. return true;
  155. }
  156. /*}}}*/
  157. // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/
  158. // ---------------------------------------------------------------------
  159. /* This is part of the helper script communication interface, it sends
  160. very complete information down to the other end of the pipe.*/
  161. bool pkgDPkgPM::SendV2Pkgs(FILE *F)
  162. {
  163. fprintf(F,"VERSION 2\n");
  164. /* Write out all of the configuration directives by walking the
  165. configuration tree */
  166. const Configuration::Item *Top = _config->Tree(0);
  167. for (; Top != 0;)
  168. {
  169. if (Top->Value.empty() == false)
  170. {
  171. fprintf(F,"%s=%s\n",
  172. QuoteString(Top->FullTag(),"=\"\n").c_str(),
  173. QuoteString(Top->Value,"\n").c_str());
  174. }
  175. if (Top->Child != 0)
  176. {
  177. Top = Top->Child;
  178. continue;
  179. }
  180. while (Top != 0 && Top->Next == 0)
  181. Top = Top->Parent;
  182. if (Top != 0)
  183. Top = Top->Next;
  184. }
  185. fprintf(F,"\n");
  186. // Write out the package actions in order.
  187. for (vector<Item>::iterator I = List.begin(); I != List.end(); I++)
  188. {
  189. if(I->Pkg.end() == true)
  190. continue;
  191. pkgDepCache::StateCache &S = Cache[I->Pkg];
  192. fprintf(F,"%s ",I->Pkg.Name());
  193. // Current version
  194. if (I->Pkg->CurrentVer == 0)
  195. fprintf(F,"- ");
  196. else
  197. fprintf(F,"%s ",I->Pkg.CurrentVer().VerStr());
  198. // Show the compare operator
  199. // Target version
  200. if (S.InstallVer != 0)
  201. {
  202. int Comp = 2;
  203. if (I->Pkg->CurrentVer != 0)
  204. Comp = S.InstVerIter(Cache).CompareVer(I->Pkg.CurrentVer());
  205. if (Comp < 0)
  206. fprintf(F,"> ");
  207. if (Comp == 0)
  208. fprintf(F,"= ");
  209. if (Comp > 0)
  210. fprintf(F,"< ");
  211. fprintf(F,"%s ",S.InstVerIter(Cache).VerStr());
  212. }
  213. else
  214. fprintf(F,"> - ");
  215. // Show the filename/operation
  216. if (I->Op == Item::Install)
  217. {
  218. // No errors here..
  219. if (I->File[0] != '/')
  220. fprintf(F,"**ERROR**\n");
  221. else
  222. fprintf(F,"%s\n",I->File.c_str());
  223. }
  224. if (I->Op == Item::Configure)
  225. fprintf(F,"**CONFIGURE**\n");
  226. if (I->Op == Item::Remove ||
  227. I->Op == Item::Purge)
  228. fprintf(F,"**REMOVE**\n");
  229. if (ferror(F) != 0)
  230. return false;
  231. }
  232. return true;
  233. }
  234. /*}}}*/
  235. // DPkgPM::RunScriptsWithPkgs - Run scripts with package names on stdin /*{{{*/
  236. // ---------------------------------------------------------------------
  237. /* This looks for a list of scripts to run from the configuration file
  238. each one is run and is fed on standard input a list of all .deb files
  239. that are due to be installed. */
  240. bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
  241. {
  242. Configuration::Item const *Opts = _config->Tree(Cnf);
  243. if (Opts == 0 || Opts->Child == 0)
  244. return true;
  245. Opts = Opts->Child;
  246. unsigned int Count = 1;
  247. for (; Opts != 0; Opts = Opts->Next, Count++)
  248. {
  249. if (Opts->Value.empty() == true)
  250. continue;
  251. // Determine the protocol version
  252. string OptSec = Opts->Value;
  253. string::size_type Pos;
  254. if ((Pos = OptSec.find(' ')) == string::npos || Pos == 0)
  255. Pos = OptSec.length();
  256. OptSec = "DPkg::Tools::Options::" + string(Opts->Value.c_str(),Pos);
  257. unsigned int Version = _config->FindI(OptSec+"::Version",1);
  258. // Create the pipes
  259. int Pipes[2];
  260. if (pipe(Pipes) != 0)
  261. return _error->Errno("pipe","Failed to create IPC pipe to subprocess");
  262. SetCloseExec(Pipes[0],true);
  263. SetCloseExec(Pipes[1],true);
  264. // Purified Fork for running the script
  265. pid_t Process = ExecFork();
  266. if (Process == 0)
  267. {
  268. // Setup the FDs
  269. dup2(Pipes[0],STDIN_FILENO);
  270. SetCloseExec(STDOUT_FILENO,false);
  271. SetCloseExec(STDIN_FILENO,false);
  272. SetCloseExec(STDERR_FILENO,false);
  273. const char *Args[4];
  274. Args[0] = "/bin/sh";
  275. Args[1] = "-c";
  276. Args[2] = Opts->Value.c_str();
  277. Args[3] = 0;
  278. execv(Args[0],(char **)Args);
  279. _exit(100);
  280. }
  281. close(Pipes[0]);
  282. FILE *F = fdopen(Pipes[1],"w");
  283. if (F == 0)
  284. return _error->Errno("fdopen","Faild to open new FD");
  285. // Feed it the filenames.
  286. bool Die = false;
  287. if (Version <= 1)
  288. {
  289. for (vector<Item>::iterator I = List.begin(); I != List.end(); I++)
  290. {
  291. // Only deal with packages to be installed from .deb
  292. if (I->Op != Item::Install)
  293. continue;
  294. // No errors here..
  295. if (I->File[0] != '/')
  296. continue;
  297. /* Feed the filename of each package that is pending install
  298. into the pipe. */
  299. fprintf(F,"%s\n",I->File.c_str());
  300. if (ferror(F) != 0)
  301. {
  302. Die = true;
  303. break;
  304. }
  305. }
  306. }
  307. else
  308. Die = !SendV2Pkgs(F);
  309. fclose(F);
  310. // Clean up the sub process
  311. if (ExecWait(Process,Opts->Value.c_str()) == false)
  312. return _error->Error("Failure running script %s",Opts->Value.c_str());
  313. }
  314. return true;
  315. }
  316. /*}}}*/
  317. // DPkgPM::DoStdin - Read stdin and pass to slave pty /*{{{*/
  318. // ---------------------------------------------------------------------
  319. /*
  320. */
  321. void pkgDPkgPM::DoStdin(int master)
  322. {
  323. unsigned char input_buf[256] = {0,};
  324. ssize_t len = read(0, input_buf, sizeof(input_buf));
  325. if (len)
  326. write(master, input_buf, len);
  327. else
  328. stdin_is_dev_null = true;
  329. }
  330. /*}}}*/
  331. // DPkgPM::DoTerminalPty - Read the terminal pty and write log /*{{{*/
  332. // ---------------------------------------------------------------------
  333. /*
  334. * read the terminal pty and write log
  335. */
  336. void pkgDPkgPM::DoTerminalPty(int master)
  337. {
  338. unsigned char term_buf[1024] = {0,0, };
  339. ssize_t len=read(master, term_buf, sizeof(term_buf));
  340. if(len == -1 && errno == EIO)
  341. {
  342. // this happens when the child is about to exit, we
  343. // give it time to actually exit, otherwise we run
  344. // into a race
  345. usleep(500000);
  346. return;
  347. }
  348. if(len <= 0)
  349. return;
  350. write(1, term_buf, len);
  351. if(term_out)
  352. fwrite(term_buf, len, sizeof(char), term_out);
  353. }
  354. /*}}}*/
  355. // DPkgPM::ProcessDpkgStatusBuf /*{{{*/
  356. // ---------------------------------------------------------------------
  357. /*
  358. */
  359. void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
  360. {
  361. bool const Debug = _config->FindB("Debug::pkgDPkgProgressReporting",false);
  362. // the status we output
  363. ostringstream status;
  364. if (Debug == true)
  365. std::clog << "got from dpkg '" << line << "'" << std::endl;
  366. /* dpkg sends strings like this:
  367. 'status: <pkg>: <pkg qstate>'
  368. errors look like this:
  369. '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
  370. and conffile-prompt like this
  371. 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited
  372. Newer versions of dpkg sent also:
  373. 'processing: install: pkg'
  374. 'processing: configure: pkg'
  375. 'processing: remove: pkg'
  376. 'processing: purge: pkg'
  377. 'processing: disappear: pkg'
  378. 'processing: trigproc: trigger'
  379. */
  380. char* list[5];
  381. // dpkg sends multiline error messages sometimes (see
  382. // #374195 for a example. we should support this by
  383. // either patching dpkg to not send multiline over the
  384. // statusfd or by rewriting the code here to deal with
  385. // it. for now we just ignore it and not crash
  386. TokSplitString(':', line, list, sizeof(list)/sizeof(list[0]));
  387. if( list[0] == NULL || list[1] == NULL || list[2] == NULL)
  388. {
  389. if (Debug == true)
  390. std::clog << "ignoring line: not enough ':'" << std::endl;
  391. return;
  392. }
  393. const char* const pkg = list[1];
  394. const char* action = _strstrip(list[2]);
  395. // 'processing' from dpkg looks like
  396. // 'processing: action: pkg'
  397. if(strncmp(list[0], "processing", strlen("processing")) == 0)
  398. {
  399. char s[200];
  400. const char* const pkg_or_trigger = _strstrip(list[2]);
  401. action = _strstrip( list[1]);
  402. const std::pair<const char *, const char *> * const iter =
  403. std::find_if(PackageProcessingOpsBegin,
  404. PackageProcessingOpsEnd,
  405. MatchProcessingOp(action));
  406. if(iter == PackageProcessingOpsEnd)
  407. {
  408. if (Debug == true)
  409. std::clog << "ignoring unknown action: " << action << std::endl;
  410. return;
  411. }
  412. snprintf(s, sizeof(s), _(iter->second), pkg_or_trigger);
  413. status << "pmstatus:" << pkg_or_trigger
  414. << ":" << (PackagesDone/float(PackagesTotal)*100.0)
  415. << ":" << s
  416. << endl;
  417. if(OutStatusFd > 0)
  418. write(OutStatusFd, status.str().c_str(), status.str().size());
  419. if (Debug == true)
  420. std::clog << "send: '" << status.str() << "'" << endl;
  421. if (strncmp(action, "disappear", strlen("disappear")) == 0)
  422. handleDisappearAction(pkg_or_trigger);
  423. return;
  424. }
  425. if(strncmp(action,"error",strlen("error")) == 0)
  426. {
  427. status << "pmerror:" << list[1]
  428. << ":" << (PackagesDone/float(PackagesTotal)*100.0)
  429. << ":" << list[3]
  430. << endl;
  431. if(OutStatusFd > 0)
  432. write(OutStatusFd, status.str().c_str(), status.str().size());
  433. if (Debug == true)
  434. std::clog << "send: '" << status.str() << "'" << endl;
  435. return;
  436. }
  437. else if(strncmp(action,"conffile",strlen("conffile")) == 0)
  438. {
  439. status << "pmconffile:" << list[1]
  440. << ":" << (PackagesDone/float(PackagesTotal)*100.0)
  441. << ":" << list[3]
  442. << endl;
  443. if(OutStatusFd > 0)
  444. write(OutStatusFd, status.str().c_str(), status.str().size());
  445. if (Debug == true)
  446. std::clog << "send: '" << status.str() << "'" << endl;
  447. return;
  448. }
  449. vector<struct DpkgState> const &states = PackageOps[pkg];
  450. const char *next_action = NULL;
  451. if(PackageOpsDone[pkg] < states.size())
  452. next_action = states[PackageOpsDone[pkg]].state;
  453. // check if the package moved to the next dpkg state
  454. if(next_action && (strcmp(action, next_action) == 0))
  455. {
  456. // only read the translation if there is actually a next
  457. // action
  458. const char *translation = _(states[PackageOpsDone[pkg]].str);
  459. char s[200];
  460. snprintf(s, sizeof(s), translation, pkg);
  461. // we moved from one dpkg state to a new one, report that
  462. PackageOpsDone[pkg]++;
  463. PackagesDone++;
  464. // build the status str
  465. status << "pmstatus:" << pkg
  466. << ":" << (PackagesDone/float(PackagesTotal)*100.0)
  467. << ":" << s
  468. << endl;
  469. if(OutStatusFd > 0)
  470. write(OutStatusFd, status.str().c_str(), status.str().size());
  471. if (Debug == true)
  472. std::clog << "send: '" << status.str() << "'" << endl;
  473. }
  474. if (Debug == true)
  475. std::clog << "(parsed from dpkg) pkg: " << pkg
  476. << " action: " << action << endl;
  477. }
  478. /*}}}*/
  479. // DPkgPM::handleDisappearAction /*{{{*/
  480. void pkgDPkgPM::handleDisappearAction(string const &pkgname)
  481. {
  482. // record the package name for display and stuff later
  483. disappearedPkgs.insert(pkgname);
  484. pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname);
  485. if (unlikely(Pkg.end() == true))
  486. return;
  487. // the disappeared package was auto-installed - nothing to do
  488. if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
  489. return;
  490. pkgCache::VerIterator PkgVer = Pkg.CurrentVer();
  491. if (unlikely(PkgVer.end() == true))
  492. return;
  493. /* search in the list of dependencies for (Pre)Depends,
  494. check if this dependency has a Replaces on our package
  495. and if so transfer the manual installed flag to it */
  496. for (pkgCache::DepIterator Dep = PkgVer.DependsList(); Dep.end() != true; ++Dep)
  497. {
  498. if (Dep->Type != pkgCache::Dep::Depends &&
  499. Dep->Type != pkgCache::Dep::PreDepends)
  500. continue;
  501. pkgCache::PkgIterator Tar = Dep.TargetPkg();
  502. if (unlikely(Tar.end() == true))
  503. continue;
  504. // the package is already marked as manual
  505. if ((Cache[Tar].Flags & pkgCache::Flag::Auto) != pkgCache::Flag::Auto)
  506. continue;
  507. pkgCache::VerIterator TarVer = Tar.CurrentVer();
  508. for (pkgCache::DepIterator Rep = TarVer.DependsList(); Rep.end() != true; ++Rep)
  509. {
  510. if (Rep->Type != pkgCache::Dep::Replaces)
  511. continue;
  512. if (Pkg != Rep.TargetPkg())
  513. continue;
  514. // okay, they are strongly connected - transfer manual-bit
  515. if (Debug == true)
  516. std::clog << "transfer manual-bit from disappeared »" << pkgname << "« to »" << Tar.FullName() << "«" << std::endl;
  517. Cache[Tar].Flags &= ~Flag::Auto;
  518. break;
  519. }
  520. }
  521. }
  522. /*}}}*/
  523. // DPkgPM::DoDpkgStatusFd /*{{{*/
  524. // ---------------------------------------------------------------------
  525. /*
  526. */
  527. void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
  528. {
  529. char *p, *q;
  530. int len;
  531. len=read(statusfd, &dpkgbuf[dpkgbuf_pos], sizeof(dpkgbuf)-dpkgbuf_pos);
  532. dpkgbuf_pos += len;
  533. if(len <= 0)
  534. return;
  535. // process line by line if we have a buffer
  536. p = q = dpkgbuf;
  537. while((q=(char*)memchr(p, '\n', dpkgbuf+dpkgbuf_pos-p)) != NULL)
  538. {
  539. *q = 0;
  540. ProcessDpkgStatusLine(OutStatusFd, p);
  541. p=q+1; // continue with next line
  542. }
  543. // now move the unprocessed bits (after the final \n that is now a 0x0)
  544. // to the start and update dpkgbuf_pos
  545. p = (char*)memrchr(dpkgbuf, 0, dpkgbuf_pos);
  546. if(p == NULL)
  547. return;
  548. // we are interessted in the first char *after* 0x0
  549. p++;
  550. // move the unprocessed tail to the start and update pos
  551. memmove(dpkgbuf, p, p-dpkgbuf);
  552. dpkgbuf_pos = dpkgbuf+dpkgbuf_pos-p;
  553. }
  554. /*}}}*/
  555. // DPkgPM::WriteHistoryTag /*{{{*/
  556. void pkgDPkgPM::WriteHistoryTag(string const &tag, string value)
  557. {
  558. size_t const length = value.length();
  559. if (length == 0)
  560. return;
  561. // poor mans rstrip(", ")
  562. if (value[length-2] == ',' && value[length-1] == ' ')
  563. value.erase(length - 2, 2);
  564. fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str());
  565. } /*}}}*/
  566. // DPkgPM::OpenLog /*{{{*/
  567. bool pkgDPkgPM::OpenLog()
  568. {
  569. string const logdir = _config->FindDir("Dir::Log");
  570. if(not FileExists(logdir))
  571. return _error->Error(_("Directory '%s' missing"), logdir.c_str());
  572. // get current time
  573. char timestr[200];
  574. time_t const t = time(NULL);
  575. struct tm const * const tmp = localtime(&t);
  576. strftime(timestr, sizeof(timestr), "%F %T", tmp);
  577. // open terminal log
  578. string const logfile_name = flCombine(logdir,
  579. _config->Find("Dir::Log::Terminal"));
  580. if (!logfile_name.empty())
  581. {
  582. term_out = fopen(logfile_name.c_str(),"a");
  583. if (term_out == NULL)
  584. return _error->WarningE("OpenLog", _("Could not open file '%s'"), logfile_name.c_str());
  585. chmod(logfile_name.c_str(), 0600);
  586. fprintf(term_out, "\nLog started: %s\n", timestr);
  587. }
  588. // write your history
  589. string const history_name = flCombine(logdir,
  590. _config->Find("Dir::Log::History"));
  591. if (!history_name.empty())
  592. {
  593. history_out = fopen(history_name.c_str(),"a");
  594. if (history_out == NULL)
  595. return _error->WarningE("OpenLog", _("Could not open file '%s'"), history_name.c_str());
  596. chmod(history_name.c_str(), 0644);
  597. fprintf(history_out, "\nStart-Date: %s\n", timestr);
  598. string remove, purge, install, upgrade, downgrade;
  599. for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
  600. {
  601. if (Cache[I].NewInstall())
  602. install += I.Name() + string(" (") + Cache[I].CandVersion + string("), ");
  603. else if (Cache[I].Upgrade())
  604. upgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
  605. else if (Cache[I].Downgrade())
  606. downgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
  607. else if (Cache[I].Delete())
  608. {
  609. if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
  610. purge += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");
  611. else
  612. remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");
  613. }
  614. }
  615. if (_config->Exists("Commandline::AsString") == true)
  616. WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
  617. WriteHistoryTag("Install", install);
  618. WriteHistoryTag("Upgrade", upgrade);
  619. WriteHistoryTag("Downgrade",downgrade);
  620. WriteHistoryTag("Remove",remove);
  621. WriteHistoryTag("Purge",purge);
  622. fflush(history_out);
  623. }
  624. return true;
  625. }
  626. /*}}}*/
  627. // DPkg::CloseLog /*{{{*/
  628. bool pkgDPkgPM::CloseLog()
  629. {
  630. char timestr[200];
  631. time_t t = time(NULL);
  632. struct tm *tmp = localtime(&t);
  633. strftime(timestr, sizeof(timestr), "%F %T", tmp);
  634. if(term_out)
  635. {
  636. fprintf(term_out, "Log ended: ");
  637. fprintf(term_out, "%s", timestr);
  638. fprintf(term_out, "\n");
  639. fclose(term_out);
  640. }
  641. term_out = NULL;
  642. if(history_out)
  643. {
  644. if (disappearedPkgs.empty() == false)
  645. {
  646. string disappear;
  647. for (std::set<std::string>::const_iterator d = disappearedPkgs.begin();
  648. d != disappearedPkgs.end(); ++d)
  649. {
  650. pkgCache::PkgIterator P = Cache.FindPkg(*d);
  651. disappear.append(*d);
  652. if (P.end() == true)
  653. disappear.append(", ");
  654. else
  655. disappear.append(" (").append(Cache[P].CurVersion).append("), ");
  656. }
  657. WriteHistoryTag("Disappeared", disappear);
  658. }
  659. if (dpkg_error.empty() == false)
  660. fprintf(history_out, "Error: %s\n", dpkg_error.c_str());
  661. fprintf(history_out, "End-Date: %s\n", timestr);
  662. fclose(history_out);
  663. }
  664. history_out = NULL;
  665. return true;
  666. }
  667. /*}}}*/
  668. /*{{{*/
  669. // This implements a racy version of pselect for those architectures
  670. // that don't have a working implementation.
  671. // FIXME: Probably can be removed on Lenny+1
  672. static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds,
  673. fd_set *exceptfds, const struct timespec *timeout,
  674. const sigset_t *sigmask)
  675. {
  676. sigset_t origmask;
  677. struct timeval tv;
  678. int retval;
  679. tv.tv_sec = timeout->tv_sec;
  680. tv.tv_usec = timeout->tv_nsec/1000;
  681. sigprocmask(SIG_SETMASK, sigmask, &origmask);
  682. retval = select(nfds, readfds, writefds, exceptfds, &tv);
  683. sigprocmask(SIG_SETMASK, &origmask, 0);
  684. return retval;
  685. }
  686. /*}}}*/
  687. // DPkgPM::Go - Run the sequence /*{{{*/
  688. // ---------------------------------------------------------------------
  689. /* This globs the operations and calls dpkg
  690. *
  691. * If it is called with "OutStatusFd" set to a valid file descriptor
  692. * apt will report the install progress over this fd. It maps the
  693. * dpkg states a package goes through to human readable (and i10n-able)
  694. * names and calculates a percentage for each step.
  695. */
  696. bool pkgDPkgPM::Go(int OutStatusFd)
  697. {
  698. fd_set rfds;
  699. struct timespec tv;
  700. sigset_t sigmask;
  701. sigset_t original_sigmask;
  702. unsigned int const MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024);
  703. unsigned int const MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024);
  704. bool const NoTriggers = _config->FindB("DPkg::NoTriggers", false);
  705. if (RunScripts("DPkg::Pre-Invoke") == false)
  706. return false;
  707. if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false)
  708. return false;
  709. // support subpressing of triggers processing for special
  710. // cases like d-i that runs the triggers handling manually
  711. bool const SmartConf = (_config->Find("PackageManager::Configure", "all") != "all");
  712. bool const TriggersPending = _config->FindB("DPkg::TriggersPending", false);
  713. if (_config->FindB("DPkg::ConfigurePending", SmartConf) == true)
  714. List.push_back(Item(Item::ConfigurePending, PkgIterator()));
  715. // map the dpkg states to the operations that are performed
  716. // (this is sorted in the same way as Item::Ops)
  717. static const struct DpkgState DpkgStatesOpMap[][7] = {
  718. // Install operation
  719. {
  720. {"half-installed", N_("Preparing %s")},
  721. {"unpacked", N_("Unpacking %s") },
  722. {NULL, NULL}
  723. },
  724. // Configure operation
  725. {
  726. {"unpacked",N_("Preparing to configure %s") },
  727. {"half-configured", N_("Configuring %s") },
  728. { "installed", N_("Installed %s")},
  729. {NULL, NULL}
  730. },
  731. // Remove operation
  732. {
  733. {"half-configured", N_("Preparing for removal of %s")},
  734. {"half-installed", N_("Removing %s")},
  735. {"config-files", N_("Removed %s")},
  736. {NULL, NULL}
  737. },
  738. // Purge operation
  739. {
  740. {"config-files", N_("Preparing to completely remove %s")},
  741. {"not-installed", N_("Completely removed %s")},
  742. {NULL, NULL}
  743. },
  744. };
  745. // init the PackageOps map, go over the list of packages that
  746. // that will be [installed|configured|removed|purged] and add
  747. // them to the PackageOps map (the dpkg states it goes through)
  748. // and the PackageOpsTranslations (human readable strings)
  749. for (vector<Item>::const_iterator I = List.begin(); I != List.end();I++)
  750. {
  751. if((*I).Pkg.end() == true)
  752. continue;
  753. string const name = (*I).Pkg.Name();
  754. PackageOpsDone[name] = 0;
  755. for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; i++)
  756. {
  757. PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]);
  758. PackagesTotal++;
  759. }
  760. }
  761. stdin_is_dev_null = false;
  762. // create log
  763. OpenLog();
  764. // this loop is runs once per operation
  765. for (vector<Item>::const_iterator I = List.begin(); I != List.end();)
  766. {
  767. // Do all actions with the same Op in one run
  768. vector<Item>::const_iterator J = I;
  769. if (TriggersPending == true)
  770. for (; J != List.end(); J++)
  771. {
  772. if (J->Op == I->Op)
  773. continue;
  774. if (J->Op != Item::TriggersPending)
  775. break;
  776. vector<Item>::const_iterator T = J + 1;
  777. if (T != List.end() && T->Op == I->Op)
  778. continue;
  779. break;
  780. }
  781. else
  782. for (; J != List.end() && J->Op == I->Op; J++)
  783. /* nothing */;
  784. // Generate the argument list
  785. const char *Args[MaxArgs + 50];
  786. // Now check if we are within the MaxArgs limit
  787. //
  788. // this code below is problematic, because it may happen that
  789. // the argument list is split in a way that A depends on B
  790. // and they are in the same "--configure A B" run
  791. // - with the split they may now be configured in different
  792. // runs
  793. if (J - I > (signed)MaxArgs)
  794. J = I + MaxArgs;
  795. unsigned int n = 0;
  796. unsigned long Size = 0;
  797. string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg");
  798. Args[n++] = Tmp.c_str();
  799. Size += strlen(Args[n-1]);
  800. // Stick in any custom dpkg options
  801. Configuration::Item const *Opts = _config->Tree("DPkg::Options");
  802. if (Opts != 0)
  803. {
  804. Opts = Opts->Child;
  805. for (; Opts != 0; Opts = Opts->Next)
  806. {
  807. if (Opts->Value.empty() == true)
  808. continue;
  809. Args[n++] = Opts->Value.c_str();
  810. Size += Opts->Value.length();
  811. }
  812. }
  813. char status_fd_buf[20];
  814. int fd[2];
  815. pipe(fd);
  816. Args[n++] = "--status-fd";
  817. Size += strlen(Args[n-1]);
  818. snprintf(status_fd_buf,sizeof(status_fd_buf),"%i", fd[1]);
  819. Args[n++] = status_fd_buf;
  820. Size += strlen(Args[n-1]);
  821. switch (I->Op)
  822. {
  823. case Item::Remove:
  824. Args[n++] = "--force-depends";
  825. Size += strlen(Args[n-1]);
  826. Args[n++] = "--force-remove-essential";
  827. Size += strlen(Args[n-1]);
  828. Args[n++] = "--remove";
  829. Size += strlen(Args[n-1]);
  830. break;
  831. case Item::Purge:
  832. Args[n++] = "--force-depends";
  833. Size += strlen(Args[n-1]);
  834. Args[n++] = "--force-remove-essential";
  835. Size += strlen(Args[n-1]);
  836. Args[n++] = "--purge";
  837. Size += strlen(Args[n-1]);
  838. break;
  839. case Item::Configure:
  840. Args[n++] = "--configure";
  841. Size += strlen(Args[n-1]);
  842. break;
  843. case Item::ConfigurePending:
  844. Args[n++] = "--configure";
  845. Size += strlen(Args[n-1]);
  846. Args[n++] = "--pending";
  847. Size += strlen(Args[n-1]);
  848. break;
  849. case Item::TriggersPending:
  850. Args[n++] = "--triggers-only";
  851. Size += strlen(Args[n-1]);
  852. Args[n++] = "--pending";
  853. Size += strlen(Args[n-1]);
  854. break;
  855. case Item::Install:
  856. Args[n++] = "--unpack";
  857. Size += strlen(Args[n-1]);
  858. Args[n++] = "--auto-deconfigure";
  859. Size += strlen(Args[n-1]);
  860. break;
  861. }
  862. if (NoTriggers == true && I->Op != Item::TriggersPending &&
  863. I->Op != Item::ConfigurePending)
  864. {
  865. Args[n++] = "--no-triggers";
  866. Size += strlen(Args[n-1]);
  867. }
  868. // Write in the file or package names
  869. if (I->Op == Item::Install)
  870. {
  871. for (;I != J && Size < MaxArgBytes; I++)
  872. {
  873. if (I->File[0] != '/')
  874. return _error->Error("Internal Error, Pathname to install is not absolute '%s'",I->File.c_str());
  875. Args[n++] = I->File.c_str();
  876. Size += strlen(Args[n-1]);
  877. }
  878. }
  879. else
  880. {
  881. for (;I != J && Size < MaxArgBytes; I++)
  882. {
  883. if((*I).Pkg.end() == true)
  884. continue;
  885. if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end())
  886. continue;
  887. Args[n++] = I->Pkg.Name();
  888. Size += strlen(Args[n-1]);
  889. }
  890. }
  891. Args[n] = 0;
  892. J = I;
  893. if (_config->FindB("Debug::pkgDPkgPM",false) == true)
  894. {
  895. for (unsigned int k = 0; k != n; k++)
  896. clog << Args[k] << ' ';
  897. clog << endl;
  898. continue;
  899. }
  900. cout << flush;
  901. clog << flush;
  902. cerr << flush;
  903. /* Mask off sig int/quit. We do this because dpkg also does when
  904. it forks scripts. What happens is that when you hit ctrl-c it sends
  905. it to all processes in the group. Since dpkg ignores the signal
  906. it doesn't die but we do! So we must also ignore it */
  907. sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN);
  908. sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN);
  909. // ignore SIGHUP as well (debian #463030)
  910. sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN);
  911. struct termios tt;
  912. struct winsize win;
  913. int master = -1;
  914. int slave = -1;
  915. // if tcgetattr does not return zero there was a error
  916. // and we do not do any pty magic
  917. if (tcgetattr(0, &tt) == 0)
  918. {
  919. ioctl(0, TIOCGWINSZ, (char *)&win);
  920. if (openpty(&master, &slave, NULL, &tt, &win) < 0)
  921. {
  922. const char *s = _("Can not write log, openpty() "
  923. "failed (/dev/pts not mounted?)\n");
  924. fprintf(stderr, "%s",s);
  925. if(term_out)
  926. fprintf(term_out, "%s",s);
  927. master = slave = -1;
  928. } else {
  929. struct termios rtt;
  930. rtt = tt;
  931. cfmakeraw(&rtt);
  932. rtt.c_lflag &= ~ECHO;
  933. rtt.c_lflag |= ISIG;
  934. // block SIGTTOU during tcsetattr to prevent a hang if
  935. // the process is a member of the background process group
  936. // http://www.opengroup.org/onlinepubs/000095399/functions/tcsetattr.html
  937. sigemptyset(&sigmask);
  938. sigaddset(&sigmask, SIGTTOU);
  939. sigprocmask(SIG_BLOCK,&sigmask, &original_sigmask);
  940. tcsetattr(0, TCSAFLUSH, &rtt);
  941. sigprocmask(SIG_SETMASK, &original_sigmask, 0);
  942. }
  943. }
  944. // Fork dpkg
  945. pid_t Child;
  946. _config->Set("APT::Keep-Fds::",fd[1]);
  947. // send status information that we are about to fork dpkg
  948. if(OutStatusFd > 0) {
  949. ostringstream status;
  950. status << "pmstatus:dpkg-exec:"
  951. << (PackagesDone/float(PackagesTotal)*100.0)
  952. << ":" << _("Running dpkg")
  953. << endl;
  954. write(OutStatusFd, status.str().c_str(), status.str().size());
  955. }
  956. Child = ExecFork();
  957. // This is the child
  958. if (Child == 0)
  959. {
  960. if(slave >= 0 && master >= 0)
  961. {
  962. setsid();
  963. ioctl(slave, TIOCSCTTY, 0);
  964. close(master);
  965. dup2(slave, 0);
  966. dup2(slave, 1);
  967. dup2(slave, 2);
  968. close(slave);
  969. }
  970. close(fd[0]); // close the read end of the pipe
  971. if (_config->FindDir("DPkg::Chroot-Directory","/") != "/")
  972. {
  973. std::cerr << "Chrooting into "
  974. << _config->FindDir("DPkg::Chroot-Directory")
  975. << std::endl;
  976. if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
  977. _exit(100);
  978. }
  979. if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
  980. _exit(100);
  981. if (_config->FindB("DPkg::FlushSTDIN",true) == true && isatty(STDIN_FILENO))
  982. {
  983. int Flags,dummy;
  984. if ((Flags = fcntl(STDIN_FILENO,F_GETFL,dummy)) < 0)
  985. _exit(100);
  986. // Discard everything in stdin before forking dpkg
  987. if (fcntl(STDIN_FILENO,F_SETFL,Flags | O_NONBLOCK) < 0)
  988. _exit(100);
  989. while (read(STDIN_FILENO,&dummy,1) == 1);
  990. if (fcntl(STDIN_FILENO,F_SETFL,Flags & (~(long)O_NONBLOCK)) < 0)
  991. _exit(100);
  992. }
  993. /* No Job Control Stop Env is a magic dpkg var that prevents it
  994. from using sigstop */
  995. putenv((char *)"DPKG_NO_TSTP=yes");
  996. execvp(Args[0],(char **)Args);
  997. cerr << "Could not exec dpkg!" << endl;
  998. _exit(100);
  999. }
  1000. // apply ionice
  1001. if (_config->FindB("DPkg::UseIoNice", false) == true)
  1002. ionice(Child);
  1003. // clear the Keep-Fd again
  1004. _config->Clear("APT::Keep-Fds",fd[1]);
  1005. // Wait for dpkg
  1006. int Status = 0;
  1007. // we read from dpkg here
  1008. int const _dpkgin = fd[0];
  1009. close(fd[1]); // close the write end of the pipe
  1010. if(slave > 0)
  1011. close(slave);
  1012. // setups fds
  1013. sigemptyset(&sigmask);
  1014. sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
  1015. // the result of the waitpid call
  1016. int res;
  1017. int select_ret;
  1018. while ((res=waitpid(Child,&Status, WNOHANG)) != Child) {
  1019. if(res < 0) {
  1020. // FIXME: move this to a function or something, looks ugly here
  1021. // error handling, waitpid returned -1
  1022. if (errno == EINTR)
  1023. continue;
  1024. RunScripts("DPkg::Post-Invoke");
  1025. // Restore sig int/quit
  1026. signal(SIGQUIT,old_SIGQUIT);
  1027. signal(SIGINT,old_SIGINT);
  1028. signal(SIGHUP,old_SIGHUP);
  1029. return _error->Errno("waitpid","Couldn't wait for subprocess");
  1030. }
  1031. // wait for input or output here
  1032. FD_ZERO(&rfds);
  1033. if (master >= 0 && !stdin_is_dev_null)
  1034. FD_SET(0, &rfds);
  1035. FD_SET(_dpkgin, &rfds);
  1036. if(master >= 0)
  1037. FD_SET(master, &rfds);
  1038. tv.tv_sec = 1;
  1039. tv.tv_nsec = 0;
  1040. select_ret = pselect(max(master, _dpkgin)+1, &rfds, NULL, NULL,
  1041. &tv, &original_sigmask);
  1042. if (select_ret < 0 && (errno == EINVAL || errno == ENOSYS))
  1043. select_ret = racy_pselect(max(master, _dpkgin)+1, &rfds, NULL,
  1044. NULL, &tv, &original_sigmask);
  1045. if (select_ret == 0)
  1046. continue;
  1047. else if (select_ret < 0 && errno == EINTR)
  1048. continue;
  1049. else if (select_ret < 0)
  1050. {
  1051. perror("select() returned error");
  1052. continue;
  1053. }
  1054. if(master >= 0 && FD_ISSET(master, &rfds))
  1055. DoTerminalPty(master);
  1056. if(master >= 0 && FD_ISSET(0, &rfds))
  1057. DoStdin(master);
  1058. if(FD_ISSET(_dpkgin, &rfds))
  1059. DoDpkgStatusFd(_dpkgin, OutStatusFd);
  1060. }
  1061. close(_dpkgin);
  1062. // Restore sig int/quit
  1063. signal(SIGQUIT,old_SIGQUIT);
  1064. signal(SIGINT,old_SIGINT);
  1065. signal(SIGHUP,old_SIGHUP);
  1066. if(master >= 0)
  1067. {
  1068. tcsetattr(0, TCSAFLUSH, &tt);
  1069. close(master);
  1070. }
  1071. // Check for an error code.
  1072. if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
  1073. {
  1074. // if it was set to "keep-dpkg-runing" then we won't return
  1075. // here but keep the loop going and just report it as a error
  1076. // for later
  1077. bool const stopOnError = _config->FindB("Dpkg::StopOnError",true);
  1078. if(stopOnError)
  1079. RunScripts("DPkg::Post-Invoke");
  1080. if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
  1081. strprintf(dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]);
  1082. else if (WIFEXITED(Status) != 0)
  1083. strprintf(dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
  1084. else
  1085. strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
  1086. if(dpkg_error.size() > 0)
  1087. _error->Error(dpkg_error.c_str());
  1088. if(stopOnError)
  1089. {
  1090. CloseLog();
  1091. return false;
  1092. }
  1093. }
  1094. }
  1095. CloseLog();
  1096. if (RunScripts("DPkg::Post-Invoke") == false)
  1097. return false;
  1098. Cache.writeStateFile(NULL);
  1099. return true;
  1100. }
  1101. /*}}}*/
  1102. // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/
  1103. // ---------------------------------------------------------------------
  1104. /* */
  1105. void pkgDPkgPM::Reset()
  1106. {
  1107. List.erase(List.begin(),List.end());
  1108. }
  1109. /*}}}*/