Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83686

Bug in sample for Unix signal handler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Done
    • Affects Version/s: 5.14.2
    • Fix Version/s: 5.15.0 RC
    • Component/s: Documentation
    • Labels:
      None
    • Commits:
      7cbe7f97ad7585c72b18f786b83122840f7159cc (qt/qtdoc/5.15.0)
    • Story Points:
      1
    • Sprint:
      Da Vinci sprint 7

      Description

      In the documentation at address https://doc.qt.io/qt-5/unix-signals.html in the sample for the 
      setup_unix_signal_handlers() function there is a bug:

      static int setup_unix_signal_handlers()
      {
          struct sigaction hup, term;
      
          hup.sa_handler = MyDaemon::hupSignalHandler;
          sigemptyset(&hup.sa_mask);
          hup.sa_flags = 0;
          hup.sa_flags |= SA_RESTART;
      
          if (sigaction(SIGHUP, &hup, 0))
             return 1;
      
          term.sa_handler = MyDaemon::termSignalHandler;
          sigemptyset(&term.sa_mask);
          term.sa_flags |= SA_RESTART;
      
          if (sigaction(SIGTERM, &term, 0))
             return 2;
      
          return 0;
      }
      

      The field sa_flags of the structure term is not initialized to zero, so SA_RESTART is in OR with whatever value was in the memory. It should be set to zero as already done for the structure hup:

      static int setup_unix_signal_handlers()
      {
          struct sigaction hup, term;
      
          hup.sa_handler = MyDaemon::hupSignalHandler;
          sigemptyset(&hup.sa_mask);
          hup.sa_flags = 0;
          hup.sa_flags |= SA_RESTART;
      
          if (sigaction(SIGHUP, &hup, 0))
             return 1;
      
          term.sa_handler = MyDaemon::termSignalHandler;
          sigemptyset(&term.sa_mask);
          term.sa_flags = 0;
          term.sa_flags |= SA_RESTART;
      
          if (sigaction(SIGTERM, &term, 0))
             return 2;
      
          return 0;
      }
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            paulwicking Paul Wicking
            Reporter:
            lornova Lorenzo Novara
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes