docs: def master_config(path, env_var='SALT_MASTER_CONFIG', defaults=None, exit_on_config_errors=False):
      '''
      Reads in the master configuration file and sets up default options
  
      This is useful for running the actual master daemon. For running
      Master-side client interfaces that need the master opts see
      :py:func:`salt.client.client_config`.
      '''
      if defaults is None:
          defaults = DEFAULT_MASTER_OPTS.copy()
  
      if not os.environ.get(env_var, None):
          # No valid setting was given using the configuration variable.
          # Lets see is SALT_CONFIG_DIR is of any use
          salt_config_dir = os.environ.get('SALT_CONFIG_DIR', None)
          if salt_config_dir:
              env_config_file_path = os.path.join(salt_config_dir, 'master')
              if salt_config_dir and os.path.isfile(env_config_file_path):
                  # We can get a configuration file using SALT_CONFIG_DIR, let's
                  # update the environment with this information
                  os.environ[env_var] = env_config_file_path
  
      overrides = load_config(path, env_var, DEFAULT_MASTER_OPTS['conf_file'])
      default_include = overrides.get('default_include',
                                      defaults['default_include'])
      include = overrides.get('include', [])
  
      overrides.update(include_config(default_include, path, verbose=False,
                       exit_on_config_errors=exit_on_config_errors))
      overrides.update(include_config(include, path, verbose=True,
                       exit_on_config_errors=exit_on_config_errors))
      opts = apply_master_config(overrides, defaults)
      _validate_ssh_minion_opts(opts)
      _validate_opts(opts)
      # If 'nodegroups:' is uncommented in the master config file, and there are
      # no nodegroups defined, opts['nodegroups'] will be None. Fix this by
      # reverting this value to the default, as if 'nodegroups:' was commented
      # out or not present.
      if opts.get('nodegroups') is None:
          opts['nodegroups'] = DEFAULT_MASTER_OPTS.get('nodegroups', {})
      if salt.utils.data.is_dictlist(opts['nodegroups']):
          opts['nodegroups'] = salt.utils.data.repack_dictlist(opts['nodegroups'])
      apply_sdb(opts)
      return opts