Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3379

Logic in executing commands in background seems to be wrong

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.15.3, 3.17.0
    • Component/s: cf-agent
    • Labels:
      None
    • Found in version (details):
      3.16.0

      Description

      The code in verify_exec.c seems to be wrong:

          if (a->transaction.background)                                                                                                                                                                 
          {                                                                                                                                                                                              
      #ifdef __MINGW32__                                                                                                                                                                                 
              outsourced = true;                                                                                                                                                                         
      #else                                                                                                                                                                                              
              Log(LOG_LEVEL_VERBOSE, "Backgrounding job '%s'", cmdline);                                                                                                                                 
              outsourced = fork();                                                                                                                                                                       
      #endif                                                                                                                                                                                             
          }                                                                                                                                                                                              
          else                                                                                                                                                                                           
          {                                                                                                                                                                                              
              outsourced = false;                                                                                                                                                                        
          }
          if (outsourced || (!a->transaction.background))    // work done here: either by child or non-background parent
      ...
      

      fork() returns non-zero (true) value to the parent process. So the work seems to be done in the parent process!

      Moreover, further down in that code there is this:

              /* exit() OK since this is a forked process and no functions are
                 registered for cleanup */
              exit(EXIT_SUCCESS);
      

      where man:atexit(3) explicitly says:

      When a child process is created via fork(2), it inherits copies of its parent's registrations.

      So again, WTH?

        Attachments

          Activity

            People

            • Assignee:
              olehermanse Ole Herman Schumacher Elgesem
              Reporter:
              vpodzime Vratislav Podzimek
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel