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/strutl.h>
17 #include <apt-pkg/fileutl.h>
22 #include <sys/select.h>
23 #include <sys/types.h>
33 #include <sys/ioctl.h>
44 // DPkgPM::pkgDPkgPM - Constructor /*{{{*/
45 // ---------------------------------------------------------------------
47 pkgDPkgPM::pkgDPkgPM(pkgDepCache
*Cache
)
48 : pkgPackageManager(Cache
), dpkgbuf_pos(0),
49 term_out(NULL
), PackagesDone(0), PackagesTotal(0)
53 // DPkgPM::pkgDPkgPM - Destructor /*{{{*/
54 // ---------------------------------------------------------------------
56 pkgDPkgPM::~pkgDPkgPM()
60 // DPkgPM::Install - Install a package /*{{{*/
61 // ---------------------------------------------------------------------
62 /* Add an install operation to the sequence list */
63 bool pkgDPkgPM::Install(PkgIterator Pkg
,string File
)
65 if (File
.empty() == true || Pkg
.end() == true)
66 return _error
->Error("Internal Error, No file name for %s",Pkg
.Name());
68 List
.push_back(Item(Item::Install
,Pkg
,File
));
72 // DPkgPM::Configure - Configure a package /*{{{*/
73 // ---------------------------------------------------------------------
74 /* Add a configure operation to the sequence list */
75 bool pkgDPkgPM::Configure(PkgIterator Pkg
)
77 if (Pkg
.end() == true)
80 List
.push_back(Item(Item::Configure
,Pkg
));
84 // DPkgPM::Remove - Remove a package /*{{{*/
85 // ---------------------------------------------------------------------
86 /* Add a remove operation to the sequence list */
87 bool pkgDPkgPM::Remove(PkgIterator Pkg
,bool Purge
)
89 if (Pkg
.end() == true)
93 List
.push_back(Item(Item::Purge
,Pkg
));
95 List
.push_back(Item(Item::Remove
,Pkg
));
99 // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/
100 // ---------------------------------------------------------------------
101 /* This is part of the helper script communication interface, it sends
102 very complete information down to the other end of the pipe.*/
103 bool pkgDPkgPM::SendV2Pkgs(FILE *F
)
105 fprintf(F
,"VERSION 2\n");
107 /* Write out all of the configuration directives by walking the
108 configuration tree */
109 const Configuration::Item
*Top
= _config
->Tree(0);
112 if (Top
->Value
.empty() == false)
115 QuoteString(Top
->FullTag(),"=\"\n").c_str(),
116 QuoteString(Top
->Value
,"\n").c_str());
125 while (Top
!= 0 && Top
->Next
== 0)
132 // Write out the package actions in order.
133 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end(); I
++)
135 pkgDepCache::StateCache
&S
= Cache
[I
->Pkg
];
137 fprintf(F
,"%s ",I
->Pkg
.Name());
139 if (I
->Pkg
->CurrentVer
== 0)
142 fprintf(F
,"%s ",I
->Pkg
.CurrentVer().VerStr());
144 // Show the compare operator
146 if (S
.InstallVer
!= 0)
149 if (I
->Pkg
->CurrentVer
!= 0)
150 Comp
= S
.InstVerIter(Cache
).CompareVer(I
->Pkg
.CurrentVer());
157 fprintf(F
,"%s ",S
.InstVerIter(Cache
).VerStr());
162 // Show the filename/operation
163 if (I
->Op
== Item::Install
)
166 if (I
->File
[0] != '/')
167 fprintf(F
,"**ERROR**\n");
169 fprintf(F
,"%s\n",I
->File
.c_str());
171 if (I
->Op
== Item::Configure
)
172 fprintf(F
,"**CONFIGURE**\n");
173 if (I
->Op
== Item::Remove
||
174 I
->Op
== Item::Purge
)
175 fprintf(F
,"**REMOVE**\n");
183 // DPkgPM::RunScriptsWithPkgs - Run scripts with package names on stdin /*{{{*/
184 // ---------------------------------------------------------------------
185 /* This looks for a list of scripts to run from the configuration file
186 each one is run and is fed on standard input a list of all .deb files
187 that are due to be installed. */
188 bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf
)
190 Configuration::Item
const *Opts
= _config
->Tree(Cnf
);
191 if (Opts
== 0 || Opts
->Child
== 0)
195 unsigned int Count
= 1;
196 for (; Opts
!= 0; Opts
= Opts
->Next
, Count
++)
198 if (Opts
->Value
.empty() == true)
201 // Determine the protocol version
202 string OptSec
= Opts
->Value
;
203 string::size_type Pos
;
204 if ((Pos
= OptSec
.find(' ')) == string::npos
|| Pos
== 0)
205 Pos
= OptSec
.length();
206 OptSec
= "DPkg::Tools::Options::" + string(Opts
->Value
.c_str(),Pos
);
208 unsigned int Version
= _config
->FindI(OptSec
+"::Version",1);
212 if (pipe(Pipes
) != 0)
213 return _error
->Errno("pipe","Failed to create IPC pipe to subprocess");
214 SetCloseExec(Pipes
[0],true);
215 SetCloseExec(Pipes
[1],true);
217 // Purified Fork for running the script
218 pid_t Process
= ExecFork();
222 dup2(Pipes
[0],STDIN_FILENO
);
223 SetCloseExec(STDOUT_FILENO
,false);
224 SetCloseExec(STDIN_FILENO
,false);
225 SetCloseExec(STDERR_FILENO
,false);
230 Args
[2] = Opts
->Value
.c_str();
232 execv(Args
[0],(char **)Args
);
236 FILE *F
= fdopen(Pipes
[1],"w");
238 return _error
->Errno("fdopen","Faild to open new FD");
240 // Feed it the filenames.
244 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end(); I
++)
246 // Only deal with packages to be installed from .deb
247 if (I
->Op
!= Item::Install
)
251 if (I
->File
[0] != '/')
254 /* Feed the filename of each package that is pending install
256 fprintf(F
,"%s\n",I
->File
.c_str());
265 Die
= !SendV2Pkgs(F
);
269 // Clean up the sub process
270 if (ExecWait(Process
,Opts
->Value
.c_str()) == false)
271 return _error
->Error("Failure running script %s",Opts
->Value
.c_str());
278 // DPkgPM::DoStdin - Read stdin and pass to slave pty /*{{{*/
279 // ---------------------------------------------------------------------
282 void pkgDPkgPM::DoStdin(int master
)
284 unsigned char input_buf
[256] = {0,};
285 ssize_t len
= read(0, input_buf
, sizeof(input_buf
));
287 write(master
, input_buf
, len
);
289 stdin_is_dev_null
= true;
292 // DPkgPM::DoTerminalPty - Read the terminal pty and write log /*{{{*/
293 // ---------------------------------------------------------------------
295 * read the terminal pty and write log
297 void pkgDPkgPM::DoTerminalPty(int master
)
299 unsigned char term_buf
[1024] = {0,0, };
301 ssize_t len
=read(master
, term_buf
, sizeof(term_buf
));
302 if(len
== -1 && errno
== EIO
)
304 // this happens when the child is about to exit, we
305 // give it time to actually exit, otherwise we run
312 write(1, term_buf
, len
);
314 fwrite(term_buf
, len
, sizeof(char), term_out
);
317 // DPkgPM::ProcessDpkgStatusBuf /*{{{*/
318 // ---------------------------------------------------------------------
321 void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd
, char *line
)
323 // the status we output
324 ostringstream status
;
326 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
327 std::clog
<< "got from dpkg '" << line
<< "'" << std::endl
;
330 /* dpkg sends strings like this:
331 'status: <pkg>: <pkg qstate>'
332 errors look like this:
333 '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
334 and conffile-prompt like this
335 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited
337 Newer versions of dpkg sent also:
338 'processing: install: pkg'
339 'processing: configure: pkg'
340 'processing: remove: pkg'
341 'processing: trigproc: trigger'
345 // dpkg sends multiline error messages sometimes (see
346 // #374195 for a example. we should support this by
347 // either patching dpkg to not send multiline over the
348 // statusfd or by rewriting the code here to deal with
349 // it. for now we just ignore it and not crash
350 TokSplitString(':', line
, list
, sizeof(list
)/sizeof(list
[0]));
351 if( list
[0] == NULL
|| list
[1] == NULL
|| list
[2] == NULL
)
353 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
354 std::clog
<< "ignoring line: not enough ':'" << std::endl
;
358 char *action
= _strstrip(list
[2]);
360 // 'processing' from dpkg looks like
361 // 'processing: action: pkg'
362 if(strncmp(list
[0], "processing", strlen("processing")) == 0)
365 map
<string
,string
>::iterator iter
;
366 char *pkg_or_trigger
= _strstrip(list
[2]);
367 action
=_strstrip( list
[1]);
368 iter
= PackageProcessingOps
.find(action
);
369 if(iter
== PackageProcessingOps
.end())
371 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
372 std::clog
<< "ignoring unknwon action: " << action
<< std::endl
;
375 snprintf(s
, sizeof(s
), _(iter
->second
.c_str()), pkg_or_trigger
);
377 status
<< "pmstatus:" << pkg_or_trigger
378 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
382 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
383 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
384 std::clog
<< "send: '" << status
.str() << "'" << endl
;
388 if(strncmp(action
,"error",strlen("error")) == 0)
390 status
<< "pmerror:" << list
[1]
391 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
395 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
396 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
397 std::clog
<< "send: '" << status
.str() << "'" << endl
;
400 if(strncmp(action
,"conffile",strlen("conffile")) == 0)
402 status
<< "pmconffile:" << list
[1]
403 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
407 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
408 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
409 std::clog
<< "send: '" << status
.str() << "'" << endl
;
413 vector
<struct DpkgState
> &states
= PackageOps
[pkg
];
414 const char *next_action
= NULL
;
415 if(PackageOpsDone
[pkg
] < states
.size())
416 next_action
= states
[PackageOpsDone
[pkg
]].state
;
417 // check if the package moved to the next dpkg state
418 if(next_action
&& (strcmp(action
, next_action
) == 0))
420 // only read the translation if there is actually a next
422 const char *translation
= _(states
[PackageOpsDone
[pkg
]].str
);
424 snprintf(s
, sizeof(s
), translation
, pkg
);
426 // we moved from one dpkg state to a new one, report that
427 PackageOpsDone
[pkg
]++;
429 // build the status str
430 status
<< "pmstatus:" << pkg
431 << ":" << (PackagesDone
/float(PackagesTotal
)*100.0)
435 write(OutStatusFd
, status
.str().c_str(), status
.str().size());
436 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
437 std::clog
<< "send: '" << status
.str() << "'" << endl
;
439 if (_config
->FindB("Debug::pkgDPkgProgressReporting",false) == true)
440 std::clog
<< "(parsed from dpkg) pkg: " << pkg
441 << " action: " << action
<< endl
;
444 // DPkgPM::DoDpkgStatusFd /*{{{*/
445 // ---------------------------------------------------------------------
448 void pkgDPkgPM::DoDpkgStatusFd(int statusfd
, int OutStatusFd
)
453 len
=read(statusfd
, &dpkgbuf
[dpkgbuf_pos
], sizeof(dpkgbuf
)-dpkgbuf_pos
);
458 // process line by line if we have a buffer
460 while((q
=(char*)memchr(p
, '\n', dpkgbuf
+dpkgbuf_pos
-p
)) != NULL
)
463 ProcessDpkgStatusLine(OutStatusFd
, p
);
464 p
=q
+1; // continue with next line
467 // now move the unprocessed bits (after the final \n that is now a 0x0)
468 // to the start and update dpkgbuf_pos
469 p
= (char*)memrchr(dpkgbuf
, 0, dpkgbuf_pos
);
473 // we are interessted in the first char *after* 0x0
476 // move the unprocessed tail to the start and update pos
477 memmove(dpkgbuf
, p
, p
-dpkgbuf
);
478 dpkgbuf_pos
= dpkgbuf
+dpkgbuf_pos
-p
;
482 bool pkgDPkgPM::OpenLog()
484 string logdir
= _config
->FindDir("Dir::Log");
485 if(not FileExists(logdir
))
486 return _error
->Error(_("Directory '%s' missing"), logdir
.c_str());
487 string logfile_name
= flCombine(logdir
,
488 _config
->Find("Dir::Log::Terminal"));
489 if (!logfile_name
.empty())
491 term_out
= fopen(logfile_name
.c_str(),"a");
492 chmod(logfile_name
.c_str(), 0600);
493 // output current time
495 time_t t
= time(NULL
);
496 struct tm
*tmp
= localtime(&t
);
497 strftime(outstr
, sizeof(outstr
), "%F %T", tmp
);
498 fprintf(term_out
, "\nLog started: ");
499 fprintf(term_out
, outstr
);
500 fprintf(term_out
, "\n");
505 bool pkgDPkgPM::CloseLog()
510 time_t t
= time(NULL
);
511 struct tm
*tmp
= localtime(&t
);
512 strftime(outstr
, sizeof(outstr
), "%F %T", tmp
);
513 fprintf(term_out
, "Log ended: ");
514 fprintf(term_out
, outstr
);
515 fprintf(term_out
, "\n");
523 // This implements a racy version of pselect for those architectures
524 // that don't have a working implementation.
525 // FIXME: Probably can be removed on Lenny+1
526 static int racy_pselect(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
527 fd_set
*exceptfds
, const struct timespec
*timeout
,
528 const sigset_t
*sigmask
)
534 tv
.tv_sec
= timeout
->tv_sec
;
535 tv
.tv_usec
= timeout
->tv_nsec
/1000;
537 sigprocmask(SIG_SETMASK
, sigmask
, &origmask
);
538 retval
= select(nfds
, readfds
, writefds
, exceptfds
, &tv
);
539 sigprocmask(SIG_SETMASK
, &origmask
, 0);
544 // DPkgPM::Go - Run the sequence /*{{{*/
545 // ---------------------------------------------------------------------
546 /* This globs the operations and calls dpkg
548 * If it is called with "OutStatusFd" set to a valid file descriptor
549 * apt will report the install progress over this fd. It maps the
550 * dpkg states a package goes through to human readable (and i10n-able)
551 * names and calculates a percentage for each step.
553 bool pkgDPkgPM::Go(int OutStatusFd
)
555 unsigned int MaxArgs
= _config
->FindI("Dpkg::MaxArgs",8*1024);
556 unsigned int MaxArgBytes
= _config
->FindI("Dpkg::MaxArgBytes",32*1024);
558 if (RunScripts("DPkg::Pre-Invoke") == false)
561 if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false)
564 // map the dpkg states to the operations that are performed
565 // (this is sorted in the same way as Item::Ops)
566 static const struct DpkgState DpkgStatesOpMap
[][7] = {
569 {"half-installed", N_("Preparing %s")},
570 {"unpacked", N_("Unpacking %s") },
573 // Configure operation
575 {"unpacked",N_("Preparing to configure %s") },
576 {"half-configured", N_("Configuring %s") },
578 {"triggers-awaited", N_("Processing triggers for %s") },
579 {"triggers-pending", N_("Processing triggers for %s") },
581 { "installed", N_("Installed %s")},
586 {"half-configured", N_("Preparing for removal of %s")},
588 {"triggers-awaited", N_("Preparing for removal of %s")},
589 {"triggers-pending", N_("Preparing for removal of %s")},
591 {"half-installed", N_("Removing %s")},
592 {"config-files", N_("Removed %s")},
597 {"config-files", N_("Preparing to completely remove %s")},
598 {"not-installed", N_("Completely removed %s")},
603 // populate the "processing" map
604 PackageProcessingOps
.insert( make_pair("install",N_("Installing %s")) );
605 PackageProcessingOps
.insert( make_pair("configure",N_("Configuring %s")) );
606 PackageProcessingOps
.insert( make_pair("remove",N_("Removing %s")) );
607 PackageProcessingOps
.insert( make_pair("trigproc",N_("Triggering %s")) );
609 // init the PackageOps map, go over the list of packages that
610 // that will be [installed|configured|removed|purged] and add
611 // them to the PackageOps map (the dpkg states it goes through)
612 // and the PackageOpsTranslations (human readable strings)
613 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end();I
++)
615 string name
= (*I
).Pkg
.Name();
616 PackageOpsDone
[name
] = 0;
617 for(int i
=0; (DpkgStatesOpMap
[(*I
).Op
][i
]).state
!= NULL
; i
++)
619 PackageOps
[name
].push_back(DpkgStatesOpMap
[(*I
).Op
][i
]);
624 stdin_is_dev_null
= false;
629 // this loop is runs once per operation
630 for (vector
<Item
>::iterator I
= List
.begin(); I
!= List
.end();)
632 vector
<Item
>::iterator J
= I
;
633 for (; J
!= List
.end() && J
->Op
== I
->Op
; J
++);
635 // Generate the argument list
636 const char *Args
[MaxArgs
+ 50];
637 if (J
- I
> (signed)MaxArgs
)
641 unsigned long Size
= 0;
642 string Tmp
= _config
->Find("Dir::Bin::dpkg","dpkg");
643 Args
[n
++] = Tmp
.c_str();
644 Size
+= strlen(Args
[n
-1]);
646 // Stick in any custom dpkg options
647 Configuration::Item
const *Opts
= _config
->Tree("DPkg::Options");
651 for (; Opts
!= 0; Opts
= Opts
->Next
)
653 if (Opts
->Value
.empty() == true)
655 Args
[n
++] = Opts
->Value
.c_str();
656 Size
+= Opts
->Value
.length();
660 char status_fd_buf
[20];
664 Args
[n
++] = "--status-fd";
665 Size
+= strlen(Args
[n
-1]);
666 snprintf(status_fd_buf
,sizeof(status_fd_buf
),"%i", fd
[1]);
667 Args
[n
++] = status_fd_buf
;
668 Size
+= strlen(Args
[n
-1]);
673 Args
[n
++] = "--force-depends";
674 Size
+= strlen(Args
[n
-1]);
675 Args
[n
++] = "--force-remove-essential";
676 Size
+= strlen(Args
[n
-1]);
677 Args
[n
++] = "--remove";
678 Size
+= strlen(Args
[n
-1]);
682 Args
[n
++] = "--force-depends";
683 Size
+= strlen(Args
[n
-1]);
684 Args
[n
++] = "--force-remove-essential";
685 Size
+= strlen(Args
[n
-1]);
686 Args
[n
++] = "--purge";
687 Size
+= strlen(Args
[n
-1]);
690 case Item::Configure
:
691 Args
[n
++] = "--configure";
692 Size
+= strlen(Args
[n
-1]);
696 Args
[n
++] = "--unpack";
697 Size
+= strlen(Args
[n
-1]);
698 Args
[n
++] = "--auto-deconfigure";
699 Size
+= strlen(Args
[n
-1]);
703 // Write in the file or package names
704 if (I
->Op
== Item::Install
)
706 for (;I
!= J
&& Size
< MaxArgBytes
; I
++)
708 if (I
->File
[0] != '/')
709 return _error
->Error("Internal Error, Pathname to install is not absolute '%s'",I
->File
.c_str());
710 Args
[n
++] = I
->File
.c_str();
711 Size
+= strlen(Args
[n
-1]);
716 for (;I
!= J
&& Size
< MaxArgBytes
; I
++)
718 Args
[n
++] = I
->Pkg
.Name();
719 Size
+= strlen(Args
[n
-1]);
725 if (_config
->FindB("Debug::pkgDPkgPM",false) == true)
727 for (unsigned int k
= 0; k
!= n
; k
++)
728 clog
<< Args
[k
] << ' ';
737 /* Mask off sig int/quit. We do this because dpkg also does when
738 it forks scripts. What happens is that when you hit ctrl-c it sends
739 it to all processes in the group. Since dpkg ignores the signal
740 it doesn't die but we do! So we must also ignore it */
741 sighandler_t old_SIGQUIT
= signal(SIGQUIT
,SIG_IGN
);
742 sighandler_t old_SIGINT
= signal(SIGINT
,SIG_IGN
);
745 struct termios tt_out
;
750 // FIXME: setup sensible signal handling (*ick*)
752 tcgetattr(1, &tt_out
);
753 ioctl(0, TIOCGWINSZ
, (char *)&win
);
754 if (openpty(&master
, &slave
, NULL
, &tt_out
, &win
) < 0)
756 const char *s
= _("Can not write log, openpty() "
757 "failed (/dev/pts not mounted?)\n");
758 fprintf(stderr
, "%s",s
);
759 fprintf(term_out
, "%s",s
);
765 rtt
.c_lflag
&= ~ECHO
;
766 tcsetattr(0, TCSAFLUSH
, &rtt
);
771 _config
->Set("APT::Keep-Fds::",fd
[1]);
777 if(slave
>= 0 && master
>= 0)
780 ioctl(slave
, TIOCSCTTY
, 0);
787 close(fd
[0]); // close the read end of the pipe
789 if (chdir(_config
->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
792 if (_config
->FindB("DPkg::FlushSTDIN",true) == true && isatty(STDIN_FILENO
))
795 if ((Flags
= fcntl(STDIN_FILENO
,F_GETFL
,dummy
)) < 0)
798 // Discard everything in stdin before forking dpkg
799 if (fcntl(STDIN_FILENO
,F_SETFL
,Flags
| O_NONBLOCK
) < 0)
802 while (read(STDIN_FILENO
,&dummy
,1) == 1);
804 if (fcntl(STDIN_FILENO
,F_SETFL
,Flags
& (~(long)O_NONBLOCK
)) < 0)
809 /* No Job Control Stop Env is a magic dpkg var that prevents it
810 from using sigstop */
811 putenv((char *)"DPKG_NO_TSTP=yes");
812 execvp(Args
[0],(char **)Args
);
813 cerr
<< "Could not exec dpkg!" << endl
;
817 // clear the Keep-Fd again
818 _config
->Clear("APT::Keep-Fds",fd
[1]);
823 // we read from dpkg here
825 close(fd
[1]); // close the write end of the pipe
827 // the result of the waitpid call
836 sigset_t original_sigmask
;
837 sigemptyset(&sigmask
);
838 sigprocmask(SIG_BLOCK
,&sigmask
,&original_sigmask
);
841 while ((res
=waitpid(Child
,&Status
, WNOHANG
)) != Child
) {
843 // FIXME: move this to a function or something, looks ugly here
844 // error handling, waitpid returned -1
847 RunScripts("DPkg::Post-Invoke");
849 // Restore sig int/quit
850 signal(SIGQUIT
,old_SIGQUIT
);
851 signal(SIGINT
,old_SIGINT
);
852 return _error
->Errno("waitpid","Couldn't wait for subprocess");
855 // wait for input or output here
857 if (!stdin_is_dev_null
)
859 FD_SET(_dpkgin
, &rfds
);
861 FD_SET(master
, &rfds
);
864 select_ret
= pselect(max(master
, _dpkgin
)+1, &rfds
, NULL
, NULL
,
865 &tv
, &original_sigmask
);
866 if (select_ret
< 0 && (errno
== EINVAL
|| errno
== ENOSYS
))
867 select_ret
= racy_pselect(max(master
, _dpkgin
)+1, &rfds
, NULL
,
868 NULL
, &tv
, &original_sigmask
);
871 else if (select_ret
< 0 && errno
== EINTR
)
873 else if (select_ret
< 0)
875 perror("select() returned error");
879 if(master
>= 0 && FD_ISSET(master
, &rfds
))
880 DoTerminalPty(master
);
881 if(master
>= 0 && FD_ISSET(0, &rfds
))
883 if(FD_ISSET(_dpkgin
, &rfds
))
884 DoDpkgStatusFd(_dpkgin
, OutStatusFd
);
888 // Restore sig int/quit
889 signal(SIGQUIT
,old_SIGQUIT
);
890 signal(SIGINT
,old_SIGINT
);
894 tcsetattr(0, TCSAFLUSH
, &tt
);
898 // Check for an error code.
899 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
901 // if it was set to "keep-dpkg-runing" then we won't return
902 // here but keep the loop going and just report it as a error
904 bool stopOnError
= _config
->FindB("Dpkg::StopOnError",true);
907 RunScripts("DPkg::Post-Invoke");
909 if (WIFSIGNALED(Status
) != 0 && WTERMSIG(Status
) == SIGSEGV
)
910 _error
->Error("Sub-process %s received a segmentation fault.",Args
[0]);
911 else if (WIFEXITED(Status
) != 0)
912 _error
->Error("Sub-process %s returned an error code (%u)",Args
[0],WEXITSTATUS(Status
));
914 _error
->Error("Sub-process %s exited unexpectedly",Args
[0]);
925 if (RunScripts("DPkg::Post-Invoke") == false)
930 // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/
931 // ---------------------------------------------------------------------
933 void pkgDPkgPM::Reset()
935 List
.erase(List
.begin(),List
.end());