"Fossies" - the Fresh Open Source Software Archive

Member "cfengine-3.15.4/cf-serverd/cf-serverd.c" (7 Jun 2021, 2670 Bytes) of package /linux/misc/cfengine-3.15.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cf-serverd.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.15.3_vs_3.15.4.

    1 /*
    2   Copyright 2019 Northern.tech AS
    3 
    4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
    5 
    6   This program is free software; you can redistribute it and/or modify it
    7   under the terms of the GNU General Public License as published by the
    8   Free Software Foundation; version 3.
    9 
   10   This program is distributed in the hope that it will be useful,
   11   but WITHOUT ANY WARRANTY; without even the implied warranty of
   12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13   GNU General Public License for more details.
   14 
   15   You should have received a copy of the GNU General Public License
   16   along with this program; if not, write to the Free Software
   17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
   18 
   19   To the extent this program is licensed as part of the Enterprise
   20   versions of CFEngine, the applicable Commercial Open Source License
   21   (COSL) may apply to this file if you as a licensee so wish it. See
   22   included file COSL.txt.
   23 */
   24 
   25 
   26 #include <platform.h>
   27 
   28 #include <cf-serverd-functions.h>
   29 #include <cf-serverd-enterprise-stubs.h> /* CleanReportBookFilterSet() */
   30 #include <server_transform.h>
   31 #include <known_dirs.h>
   32 #include <loading.h>
   33 #include <cleanup.h>
   34 
   35 static void ThisAgentInit(void)
   36 {
   37     umask(077);
   38 }
   39 
   40 
   41 int main(int argc, char *argv[])
   42 {
   43     /* Ensure that if fd 0,1,2 are closed, we reserve them to avoid opening
   44      * the listening socket on them and closing it later when daemonising. */
   45     int fd = -1;
   46     do
   47     {
   48         fd = open(NULLFILE, O_RDWR, 0);
   49 
   50     } while (fd == STDIN_FILENO  ||
   51              fd == STDOUT_FILENO ||
   52              fd == STDERR_FILENO);
   53     close(fd);
   54 
   55     GenericAgentConfig *config = CheckOpts(argc, argv);
   56     EvalContext *ctx = EvalContextNew();
   57     GenericAgentConfigApply(ctx, config);
   58 
   59     const char *program_invocation_name = argv[0];
   60     const char *last_dir_sep = strrchr(program_invocation_name, FILE_SEPARATOR);
   61     const char *program_name = (last_dir_sep != NULL ? last_dir_sep + 1 : program_invocation_name);
   62     GenericAgentDiscoverContext(ctx, config, program_name);
   63 
   64     Policy *policy = SelectAndLoadPolicy(config, ctx, false, false);
   65 
   66     if (!policy)
   67     {
   68         Log(LOG_LEVEL_ERR, "Error reading CFEngine policy. Exiting...");
   69         DoCleanupAndExit(EXIT_FAILURE);
   70     }
   71 
   72     GenericAgentPostLoadInit(ctx);
   73     ThisAgentInit();
   74 
   75     KeepPromises(ctx, policy, config);
   76     Summarize();
   77 
   78     int threads_left = StartServer(ctx, &policy, config);
   79 
   80     if (threads_left <= 0)
   81     {
   82         PolicyDestroy(policy);
   83         GenericAgentFinalize(ctx, config);
   84         CleanReportBookFilterSet();
   85     }
   86     CallCleanupFunctions();
   87     return 0;
   88 }