ソースを参照

dselect: Refactor SIGWINCH signal blocking and unblocking

This way we can move the sigset_t sigwinchset declaration into the
new sigwinch_mask() member function instead of having it as a member
variable.
Guillem Jover 10 年 前
コミット
21e982448e
共有4 個のファイルを変更した24 個の追加12 個の削除を含む
  1. 18 3
      dselect/baselist.cc
  2. 2 1
      dselect/dselect.h
  3. 2 4
      dselect/methlist.cc
  4. 2 4
      dselect/pkglist.cc

+ 18 - 3
dselect/baselist.cc

@@ -76,10 +76,25 @@ static void cu_sigwinch(int, void **argv) {
   delete oblockedp;
 }
 
-void baselist::setupsigwinch() {
+void
+baselist::sigwinch_mask(int how)
+{
+  sigset_t sigwinchset;
   sigemptyset(&sigwinchset);
   sigaddset(&sigwinchset,SIGWINCH);
 
+  int rc = sigprocmask(how, &sigwinchset, nullptr);
+  if (rc < 0) {
+    if (how == SIG_UNBLOCK)
+      ohshite(_("failed to unblock SIGWINCH"));
+    else
+      ohshite(_("failed to block SIGWINCH"));
+  }
+}
+
+void
+baselist::setupsigwinch()
+{
   osigactp= new(struct sigaction);
   oblockedp= new(sigset_t);
   if (sigprocmask(0, nullptr, oblockedp))
@@ -89,8 +104,8 @@ void baselist::setupsigwinch() {
 
   push_cleanup(cu_sigwinch, ~0, nullptr, 0, 2, osigactp, oblockedp);
 
-  if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
-    ohshite(_("failed to block SIGWINCH"));
+  sigwinch_mask(SIG_BLOCK);
+
   memset(&nsigact,0,sizeof(nsigact));
   nsigact.sa_handler= sigwinchhandler;
   sigemptyset(&nsigact.sa_mask);

+ 2 - 1
dselect/dselect.h

@@ -99,7 +99,8 @@ protected:
 
   // SIGWINCH handling
   struct sigaction *osigactp, nsigact;
-  sigset_t *oblockedp, sigwinchset;
+  sigset_t *oblockedp;
+  void sigwinch_mask(int how);
   void setupsigwinch();
 
   static baselist *signallist;

+ 2 - 4
dselect/methlist.cc

@@ -160,13 +160,11 @@ quitaction methodlist::display() {
     if (whatinfo_height) wcursyncup(whatinfowin);
     if (doupdate() == ERR) ohshite(_("doupdate failed"));
     signallist= this;
-    if (sigprocmask(SIG_UNBLOCK, &sigwinchset, nullptr))
-      ohshite(_("failed to unblock SIGWINCH"));
+    sigwinch_mask(SIG_UNBLOCK);
     do
     response= getch();
     while (response == ERR && errno == EINTR);
-    if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
-      ohshite(_("failed to re-block SIGWINCH"));
+    sigwinch_mask(SIG_BLOCK);
     if (response == ERR) ohshite(_("getch failed"));
     interp= (*bindings)(response);
     debug(dbg_general, "methodlist[%p]::display() response=%d interp=%s",

+ 2 - 4
dselect/pkglist.cc

@@ -586,13 +586,11 @@ pkginfo **packagelist::display() {
     if (doupdate() == ERR)
       ohshite(_("doupdate failed"));
     signallist= this;
-    if (sigprocmask(SIG_UNBLOCK, &sigwinchset, nullptr))
-      ohshite(_("failed to unblock SIGWINCH"));
+    sigwinch_mask(SIG_UNBLOCK);
     do
     response= getch();
     while (response == ERR && errno == EINTR);
-    if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
-      ohshite(_("failed to re-block SIGWINCH"));
+    sigwinch_mask(SIG_BLOCK);
     if (response == ERR)
       ohshite(_("getch failed"));
     interp= (*bindings)(response);