Parent Directory
|
Revision Log
Revision 16 - (view) (download) (as text)
| 1 : | mark | 16 | /* |
| 2 : | |||
| 3 : | Copyright (C) 1994- | ||
| 4 : | Free Software Foundation, Inc. | ||
| 5 : | |||
| 6 : | This file is part of GNU cfengine - written and maintained | ||
| 7 : | by Mark Burgess, Dept of Computing and Engineering, Oslo College, | ||
| 8 : | Dept. of Theoretical physics, University of Oslo | ||
| 9 : | |||
| 10 : | This program is free software; you can redistribute it and/or modify it | ||
| 11 : | under the terms of the GNU General Public License as published by the | ||
| 12 : | Free Software Foundation; either version 3, or (at your option) any | ||
| 13 : | later version. | ||
| 14 : | This program is distributed in the hope that it will be useful, | ||
| 15 : | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 : | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 : | GNU General Public License for more details. | ||
| 18 : | |||
| 19 : | You should have received a copy of the GNU General Public License | ||
| 20 : | along with this program; if not, write to the Free Software | ||
| 21 : | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
| 22 : | |||
| 23 : | */ | ||
| 24 : | |||
| 25 : | /*****************************************************************************/ | ||
| 26 : | /* */ | ||
| 27 : | /* File: generic_agent.c */ | ||
| 28 : | /* */ | ||
| 29 : | /*****************************************************************************/ | ||
| 30 : | |||
| 31 : | #include "cf3.defs.h" | ||
| 32 : | #include "cf3.extern.h" | ||
| 33 : | |||
| 34 : | extern struct option OPTIONS[]; | ||
| 35 : | |||
| 36 : | /*****************************************************************************/ | ||
| 37 : | |||
| 38 : | void GenericInitialize(int argc,char **argv) | ||
| 39 : | |||
| 40 : | { | ||
| 41 : | Initialize(argc,argv); | ||
| 42 : | SetReferenceTime(true); | ||
| 43 : | SetStartTime(false); | ||
| 44 : | |||
| 45 : | if (! NOHARDCLASSES) | ||
| 46 : | { | ||
| 47 : | SetNewScope("system"); | ||
| 48 : | GetNameInfo3(); | ||
| 49 : | GetInterfaceInfo3(); | ||
| 50 : | GetV6InterfaceInfo(); | ||
| 51 : | GetEnvironment(); | ||
| 52 : | } | ||
| 53 : | } | ||
| 54 : | |||
| 55 : | /*******************************************************************/ | ||
| 56 : | /* Level 1 */ | ||
| 57 : | /*******************************************************************/ | ||
| 58 : | |||
| 59 : | void Initialize(int argc,char *argv[]) | ||
| 60 : | |||
| 61 : | { char *sp, **cfargv;; | ||
| 62 : | int i,j, cfargc, seed; | ||
| 63 : | struct stat statbuf; | ||
| 64 : | unsigned char s[16]; | ||
| 65 : | char ebuff[CF_EXPANDSIZE]; | ||
| 66 : | |||
| 67 : | PreLockState(); | ||
| 68 : | |||
| 69 : | #ifndef HAVE_REGCOMP | ||
| 70 : | re_syntax_options |= RE_INTERVALS; | ||
| 71 : | #endif | ||
| 72 : | |||
| 73 : | OpenSSL_add_all_algorithms(); | ||
| 74 : | ERR_load_crypto_strings(); | ||
| 75 : | CheckWorkDirectories(); | ||
| 76 : | RandomSeed(); | ||
| 77 : | |||
| 78 : | RAND_bytes(s,16); | ||
| 79 : | s[15] = '\0'; | ||
| 80 : | seed = ElfHash(s); | ||
| 81 : | srand48((long)seed); | ||
| 82 : | |||
| 83 : | /* Note we need to fix the options since the argv mechanism doesn't */ | ||
| 84 : | /* work when the shell #!/bla/cfengine -v -f notation is used. */ | ||
| 85 : | /* Everything ends up inside a single argument! Here's the fix */ | ||
| 86 : | |||
| 87 : | cfargc = 1; | ||
| 88 : | |||
| 89 : | /* Pass 1: Find how many arguments there are. */ | ||
| 90 : | for (i = 1, j = 1; i < argc; i++) | ||
| 91 : | { | ||
| 92 : | sp = argv[i]; | ||
| 93 : | |||
| 94 : | while (*sp != '\0') | ||
| 95 : | { | ||
| 96 : | while (*sp == ' ' && *sp != '\0') /* Skip to arg */ | ||
| 97 : | { | ||
| 98 : | sp++; | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | cfargc++; | ||
| 102 : | |||
| 103 : | while (*sp != ' ' && *sp != '\0') /* Skip to white space */ | ||
| 104 : | { | ||
| 105 : | sp++; | ||
| 106 : | } | ||
| 107 : | } | ||
| 108 : | } | ||
| 109 : | |||
| 110 : | /* Allocate memory for cfargv. */ | ||
| 111 : | |||
| 112 : | cfargv = (char **) malloc(sizeof(char *) * cfargc + 1); | ||
| 113 : | |||
| 114 : | if (!cfargv) | ||
| 115 : | { | ||
| 116 : | FatalError("cfagent: Out of memory parsing arguments\n"); | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | /* Pass 2: Parse the arguments. */ | ||
| 120 : | |||
| 121 : | cfargv[0] = "cfagent"; | ||
| 122 : | |||
| 123 : | for (i = 1, j = 1; i < argc; i++) | ||
| 124 : | { | ||
| 125 : | sp = argv[i]; | ||
| 126 : | |||
| 127 : | while (*sp != '\0') | ||
| 128 : | { | ||
| 129 : | while (*sp == ' ' && *sp != '\0') /* Skip to arg */ | ||
| 130 : | { | ||
| 131 : | if (*sp == ' ') | ||
| 132 : | { | ||
| 133 : | *sp = '\0'; /* Break argv string */ | ||
| 134 : | } | ||
| 135 : | sp++; | ||
| 136 : | } | ||
| 137 : | |||
| 138 : | cfargv[j++] = sp; | ||
| 139 : | |||
| 140 : | while (*sp != ' ' && *sp != '\0') /* Skip to white space */ | ||
| 141 : | { | ||
| 142 : | sp++; | ||
| 143 : | } | ||
| 144 : | } | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | cfargv[j] = NULL; | ||
| 148 : | |||
| 149 : | CheckOpts(argc,argv); | ||
| 150 : | |||
| 151 : | if (!MINUSF) | ||
| 152 : | { | ||
| 153 : | strcpy(VINPUTFILE,"../tests/promises.cf"); | ||
| 154 : | } | ||
| 155 : | |||
| 156 : | CfenginePort(); | ||
| 157 : | StrCfenginePort(); | ||
| 158 : | FOUT = stdout; | ||
| 159 : | AddClassToHeap("any"); | ||
| 160 : | strcpy(VPREFIX,"cfengine3"); | ||
| 161 : | } | ||
| 162 : | |||
| 163 : | |||
| 164 : | /*******************************************************************/ | ||
| 165 : | /* Level 2 */ | ||
| 166 : | /*******************************************************************/ | ||
| 167 : | |||
| 168 : | void Syntax(char *component) | ||
| 169 : | |||
| 170 : | { int i; | ||
| 171 : | |||
| 172 : | Version(component); | ||
| 173 : | printf("\n"); | ||
| 174 : | printf("Options:\n\n"); | ||
| 175 : | |||
| 176 : | for (i=0; OPTIONS[i].name != NULL; i++) | ||
| 177 : | { | ||
| 178 : | printf("--%-20s (-%c)\n",OPTIONS[i].name,(char)OPTIONS[i].val); | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | printf("\nDebug levels: 1=parsing, 2=running, 3=summary, 4=expression eval\n"); | ||
| 182 : | |||
| 183 : | printf("\nBug reports to bug-cfengine@cfengine.org\n"); | ||
| 184 : | printf("General help to help-cfengine@cfengine.org\n"); | ||
| 185 : | printf("Info & fixes at http://www.cfengine.org\n"); | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | /*******************************************************************/ | ||
| 189 : | |||
| 190 : | void Version(char *component) | ||
| 191 : | |||
| 192 : | { | ||
| 193 : | printf("Cfengine: %s\n%s\n%s\n",component,VERSION,COPYRIGHT); | ||
| 194 : | } |
| Administrator | ViewVC Help |
| Powered by ViewVC 1.0.3 |