summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2022-01-06 19:56:23 +0000
committerJulian Andres Klode <jak@debian.org>2022-01-06 19:56:23 +0000
commit64205c6850cf4323af317eff371c131c1bb7ebfc (patch)
tree7167da96a18c6f4efc501c00756a41d3675d9752
parent0ce8ea6f1920a700a088ab9815cf63197fcf4dfb (diff)
parentec27853181d898f738ad20fed00f37a00d1d09c3 (diff)
Merge branch 'main' into 'main'
Fix incorrect SIGWINCH handling See merge request apt-team/apt!204
-rw-r--r--apt-pkg/install-progress.cc34
-rw-r--r--apt-pkg/install-progress.h8
2 files changed, 32 insertions, 10 deletions
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index aadd28e51..8a6d87cd2 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -222,22 +222,42 @@ PackageManagerFancy::PackageManagerFancy()
: d(NULL), child_pty(-1)
{
// setup terminal size
- old_SIGWINCH = signal(SIGWINCH, PackageManagerFancy::staticSIGWINCH);
+ if (instances.empty())
+ SIGWINCH_orig = signal(SIGWINCH, PackageManagerFancy::staticSIGWINCH);
instances.push_back(this);
}
std::vector<PackageManagerFancy*> PackageManagerFancy::instances;
+sighandler_t PackageManagerFancy::SIGWINCH_orig;
+volatile sig_atomic_t PackageManagerFancy::SIGWINCH_flag = 0;
PackageManagerFancy::~PackageManagerFancy()
{
instances.erase(find(instances.begin(), instances.end(), this));
- signal(SIGWINCH, old_SIGWINCH);
+ if (instances.empty())
+ signal(SIGWINCH, SIGWINCH_orig);
}
void PackageManagerFancy::staticSIGWINCH(int signum)
{
- std::vector<PackageManagerFancy *>::const_iterator I;
- for(I = instances.begin(); I != instances.end(); ++I)
- (*I)->HandleSIGWINCH(signum);
+ SIGWINCH_flag = 1;
+}
+
+void PackageManagerFancy::CheckSIGWINCH()
+{
+ if (SIGWINCH_flag)
+ {
+ SIGWINCH_flag = 0;
+ int errsv = errno;
+ int const nr_terminal_rows = GetTerminalSize().rows;
+ SetupTerminalScrollArea(nr_terminal_rows);
+ DrawStatusLine();
+ errno = errsv;
+ }
+}
+
+void PackageManagerFancy::Pulse()
+{
+ CheckSIGWINCH();
}
PackageManagerFancy::TermSize
@@ -296,9 +316,7 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
void PackageManagerFancy::HandleSIGWINCH(int)
{
- int const nr_terminal_rows = GetTerminalSize().rows;
- SetupTerminalScrollArea(nr_terminal_rows);
- DrawStatusLine();
+ // for abi compatibility, do not use
}
void PackageManagerFancy::Start(int a_child_pty)
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index 94b66ed9b..617ce2a35 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -126,11 +126,14 @@ namespace Progress {
private:
APT_HIDDEN static void staticSIGWINCH(int);
static std::vector<PackageManagerFancy*> instances;
+ static sighandler_t SIGWINCH_orig;
+ static volatile sig_atomic_t SIGWINCH_flag;
+ APT_HIDDEN void CheckSIGWINCH();
APT_HIDDEN bool DrawStatusLine();
protected:
void SetupTerminalScrollArea(int nr_rows);
- void HandleSIGWINCH(int);
+ void HandleSIGWINCH(int); // for abi compatibility, do not use
typedef struct {
int rows;
@@ -138,12 +141,13 @@ namespace Progress {
} TermSize;
TermSize GetTerminalSize();
- sighandler_t old_SIGWINCH;
+ sighandler_t old_SIGWINCH; // for abi compatibility, do not use
int child_pty;
public:
PackageManagerFancy();
virtual ~PackageManagerFancy();
+ virtual void Pulse() APT_OVERRIDE;
virtual void Start(int child_pty=-1) APT_OVERRIDE;
virtual void Stop() APT_OVERRIDE;
virtual bool StatusChanged(std::string PackageName,