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

Bug in sample for Unix signal handler

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.15.0 RC
    • 5.14.2
    • Documentation
    • None
    • 1
    • 7cbe7f97ad7585c72b18f786b83122840f7159cc (qt/qtdoc/5.15.0)
    • 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

            paulwicking Paul Wicking
            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