clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name rfctl.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="daq" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ daq/rfarm/manager/tools/rfctl.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <ctype.h> |
| 20 | #include <stdarg.h> |
| 21 | #include <time.h> |
| 22 | #include <sys/time.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include "nsm2/belle2nsm.h" |
| 25 | |
| 26 | extern "C" { |
| 27 | #ifdef USE_READLINE |
| 28 | #include <readline/readline.h> |
| 29 | #undef CTRL /* also defined in sys/ioctl.h in solaris */ |
| 30 | extern int add_history(char*); |
| 31 | #endif |
| 32 | } |
| 33 | |
| 34 | |
| 35 | const char* master_logdir = "."; |
| 36 | FILE* master_logfp = 0; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | void |
| 42 | xreopenlog() |
| 43 | { |
| 44 | static char logprefix[1024]; |
| 45 | char logfile[2048]; |
| 46 | time_t now = time(0); |
| 47 | tm* cur = localtime(&now); |
| 48 | struct stat statbuf; |
| 49 | |
| 50 | if (! logprefix[0]) { |
| 51 | strcpy(logprefix, master_logdir); |
| 52 | if (! logprefix[0]) strcpy(logprefix, "."); |
| 53 | if (logprefix[strlen(logprefix) - 1] == '/') { |
| 54 | logprefix[strlen(logprefix) - 1] = 0; |
| 55 | } |
| 56 | if (stat(logprefix, &statbuf) >= 0 && S_ISDIR(statbuf.st_mode)) { |
| 57 | strcat(logprefix, "/master"); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | sprintf(logfile, "%s.%04d%02d%02d.log", logprefix, |
| 62 | cur->tm_year + 1900, cur->tm_mon + 1, cur->tm_mday); |
| 63 | if (master_logfp != stdout) { |
| 64 | if (master_logfp) fclose(master_logfp); |
| 65 | if (!(master_logfp = fopen(logfile, "a"))) { |
| 66 | printf("cannot open logfile %s\n", logfile); |
| 67 | exit(1); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | |
| 74 | void |
| 75 | xprintlog(const char* fmt, ...) |
| 76 | { |
| 77 | void xlogtime(char* buf); |
| 78 | |
| 79 | if (master_logfp) { |
| 80 | va_list ap; |
| 81 | va_start(ap, fmt); |
| 82 | char datebuf[32]; |
| 83 | xlogtime(datebuf); |
| 84 | fputs(datebuf, master_logfp); |
| 85 | vfprintf(master_logfp, fmt, ap); |
| 86 | fputc('\n', master_logfp); |
| 87 | va_end(ap); |
| 88 | |
| 89 | fflush(master_logfp); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | void |
| 96 | xlogtime(char* buf) |
| 97 | { |
| 98 | timeval now; |
| 99 | tm* cur; |
| 100 | |
| 101 | gettimeofday(&now, 0); |
| 102 | cur = localtime((time_t*)&now.tv_sec); |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | sprintf(buf, "%02d:%02d:%02d.%03d ", |
| 117 | cur->tm_hour, cur->tm_min, cur->tm_sec, (int)now.tv_usec / 1000); |
| 118 | } |
| 119 | |
| 120 | int |
| 121 | xgetargs(char* buf, char* argv[]) |
| 122 | { |
| 123 | int argc = 0, inword = 0, inquote = 0; |
| 124 | char* p = buf; |
| 15 | | 'p' initialized to a null pointer value | |
|
| 125 | |
| 126 | while (*p) { |
| 16 | | Dereference of null pointer (loaded from variable 'p') |
|
| 127 | if (*p == '\\') { |
| 128 | if (*(p + 1) == 'n') { |
| 129 | memmove(p, p + 1, strlen(p)); |
| 130 | *p = '\n'; |
| 131 | } else { |
| 132 | memmove(p, p + 1, strlen(p)); |
| 133 | } |
| 134 | } else if (*p == '"') { |
| 135 | inquote = !inquote; |
| 136 | memmove(p, p + 1, strlen(p)); |
| 137 | if (! inword) { |
| 138 | argc++; |
| 139 | *argv++ = p; |
| 140 | inword = 1; |
| 141 | } |
| 142 | p--; |
| 143 | } else if (isspace(*p) && !inquote && inword) { |
| 144 | *p = 0; |
| 145 | inword = 0; |
| 146 | } else if (! isspace(*p) && !inword) { |
| 147 | inword = 1; |
| 148 | argc++; |
| 149 | *argv++ = p; |
| 150 | } |
| 151 | p++; |
| 152 | } |
| 153 | if (inquote) return -1; |
| 154 | return argc; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | void |
| 160 | ok_handler(NSMmsg* , NSMcontext*) |
| 161 | { |
| 162 | xprintlog("OK received"); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | |
| 167 | void |
| 168 | error_handler(NSMmsg* , NSMcontext*) |
| 169 | { |
| 170 | xprintlog("ERROR received"); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | void |
| 177 | msg_handler(NSMmsg* , NSMcontext*) |
| 178 | { |
| 179 | xprintlog("MSG received"); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | |
| 184 | int |
| 185 | main(int argc, const char** argv) |
| 186 | { |
| 187 | const char* program = argv[0]; |
| 188 | const char* nodename = argv[1]; |
| 189 | const char myname[] = "rfctl"; |
| 190 | |
| 191 | char* buf = 0; |
| 1 | 'buf' initialized to a null pointer value | |
|
| 192 | char* av[128]; |
| 193 | char* prompt; |
| 194 | |
| 195 | |
| 196 | master_logfp = stdout; |
| 197 | |
| 198 | |
| 199 | if (argc < 2) { |
| |
| |
| 200 | nodename = myname; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | if (! b2nsm_init(nodename)) { |
| 4 | | Assuming the condition is false | |
|
| |
| 205 | xprintlog("%s: INIT %s", program, b2nsm_strerror()); |
| 206 | return 1; |
| 207 | } |
| 208 | xprintlog("%s: INIT", program); |
| 209 | b2nsm_logging(master_logfp); |
| 210 | |
| 211 | |
| 212 | if (b2nsm_callback("OK", ok_handler) < 0) { |
| 6 | | Assuming the condition is false | |
|
| |
| 213 | xprintlog("%s: CALLBACK(OK) %s", program, b2nsm_strerror()); |
| 214 | return 1; |
| 215 | } |
| 216 | if (b2nsm_callback("ERROR", ok_handler) < 0) { |
| 8 | | Assuming the condition is false | |
|
| |
| 217 | xprintlog("%s: CALLBACK(ERROR) %s", program, b2nsm_strerror()); |
| 218 | return 1; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | prompt = (char*)malloc(strlen(nodename) + 2); |
| 228 | strcpy(prompt, nodename); |
| 229 | strcat(prompt, ">"); |
| 230 | |
| 231 | |
| 232 | #ifdef USE_READLINE |
| 233 | char* input = 0; |
| 234 | char* prev = 0; |
| 235 | #endif |
| 236 | |
| 237 | |
| 238 | while (1) { |
| 10 | | Loop condition is true. Entering loop body | |
|
| 239 | #ifdef USE_READLINE |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | if (buf) free(buf); |
| 245 | if (input) free(input); |
| 246 | if (!(input = readline(prompt))) |
| 247 | exit(1); |
| 248 | buf = (char*)malloc(strlen(input) + 1); |
| 249 | strcpy(buf, input); |
| 250 | |
| 251 | if (!prev || (*input && strcmp(prev, input) != 0)) { |
| 252 | add_history(input); |
| 253 | if (prev) free(prev); |
| 254 | prev = (char*)malloc(strlen(input) + 1); |
| 255 | strcpy(prev, input); |
| 256 | } |
| 257 | #else |
| 258 | static char buffer[1024]; |
| 259 | buffer[0] = 0; |
| 260 | printf("%s", prompt); |
| 261 | do { |
| 12 | | Loop condition is false. Exiting loop | |
|
| 262 | fgets(buffer, sizeof(buffer), stdin); |
| 263 | } while (! buffer[0]); |
| 11 | | Assuming the condition is false | |
|
| 264 | #endif |
| 265 | |
| 266 | int ac; |
| 267 | if ((ac = xgetargs(buf, av)) <= 0) |
| 13 | | Passing null pointer value via 1st parameter 'buf' | |
|
| |
| 268 | continue; |
| 269 | printf("ac=%d av[0]=%s\n", ac, av[0]); |
| 270 | |
| 271 | if (strcasecmp(av[0], "q") == 0 || strcasecmp(av[0], "quit") == 0) { |
| 272 | break; |
| 273 | } else if (strcasecmp(av[0], "start") == 0) { |
| 274 | if (ac < 4 || ! isdigit(av[2][0])) { |
| 275 | printf("usage: start <node> <exp-number> <run-number>\n"); |
| 276 | } else { |
| 277 | int pars[2]; |
| 278 | pars[0] = atoi(av[2]); |
| 279 | pars[1] = atoi(av[3]); |
| 280 | b2nsm_sendreq(av[1], "RC_START", 2, pars); |
| 281 | } |
| 282 | } else if (strcasecmp(av[0], "stop") == 0) { |
| 283 | if (ac < 4) { |
| 284 | printf("usage: start <node> <exp-number> <run-number>\n"); |
| 285 | } else { |
| 286 | int pars[10]; |
| 287 | pars[0] = atoi(av[2]); |
| 288 | pars[1] = atoi(av[3]); |
| 289 | b2nsm_sendreq(av[1], "RC_STOP", 2, pars); |
| 290 | } |
| 291 | } else if (strcasecmp(av[0], "config") == 0) { |
| 292 | if (ac < 2) { |
| 293 | printf("usage: config <node>\n"); |
| 294 | } else { |
| 295 | |
| 296 | char scrfile[256]; |
| 297 | strcpy(scrfile, "run_processor.py"); |
| 298 | b2nsm_sendany(av[1], "RC_LOAD", 0, 0, sizeof(scrfile) + 1, scrfile, "sendreq"); |
| 299 | } |
| 300 | } else if (strcasecmp(av[0], "unconfig") == 0) { |
| 301 | if (ac < 2) { |
| 302 | printf("usage: unconfig <node>\n"); |
| 303 | } else { |
| 304 | b2nsm_sendreq(av[1], "RC_ABORT", 0, 0); |
| 305 | } |
| 306 | } else if (strcasecmp(av[0], "restart") == 0) { |
| 307 | if (ac < 2) { |
| 308 | printf("usage: restart <node>\n"); |
| 309 | } else { |
| 310 | b2nsm_sendreq(av[1], "RC_RECOVER", 0, 0); |
| 311 | } |
| 312 | } else { |
| 313 | printf("unknown request %s\n", av[0]); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |