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