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 RFNSM.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 -fhalf-no-semantic-interposition -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/src/RFNSM.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include "daq/rfarm/manager/RFNSM.h" |
| 10 | |
| 11 | extern "C" { |
| 12 | #include <nsm2/nsm2.h> |
| 13 | #include <nsm2/nsmlib2.h> |
| 14 | #include <nsm2/belle2nsm.h> |
| 15 | } |
| 16 | |
| 17 | #include <iostream> |
| 18 | |
| 19 | #define RFNSMOUT stdout |
| 20 | |
| 21 | using namespace std; |
| 22 | using namespace Belle2; |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | RFServerBase* g_nsmserver = 0; |
| 28 | |
| 29 | RFNSM_Status* RFNSM_Status::s_instance = 0; |
| 30 | |
| 31 | NSMcontext* RFNSM::g_context = 0; |
| 32 | |
| 33 | |
| 34 | RFNSM::RFNSM(char* nodename, RFServerBase* server) |
| 35 | { |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | if (!(g_context = b2nsm_init2(nodename, 0, 0, 0, 0))) { |
| 42 | |
| 43 | fprintf(RFNSMOUT, "RFNSM : %s initialization failure, %s\n", |
| 44 | nodename, b2nsm_strerror()); |
| 45 | g_context = 0; |
| 46 | } |
| 47 | nsmlib_usesig(g_context, 0); |
| 48 | m_nodename = nodename; |
| 49 | |
| 50 | |
| 51 | b2nsm_logging(RFNSMOUT); |
| 52 | |
| 53 | |
| 54 | nsmlib_debuglevel(0); |
| 55 | |
| 56 | |
| 57 | g_nsmserver = server; |
| 58 | |
| 59 | |
| 60 | |
| 61 | if (b2nsm_callback("RC_LOAD", m_Configure) < 0) { |
| 62 | fprintf(stderr, "RFNSM : %s hooking CONFIGURE failed, %s\n", |
| 63 | m_nodename.c_str(), b2nsm_strerror()); |
| 64 | } |
| 65 | |
| 66 | if (b2nsm_callback("RC_ABORT", m_UnConfigure) < 0) { |
| 67 | fprintf(stderr, "RFNSM : %s hooking UNCONFIGURE failed, %s\n", |
| 68 | m_nodename.c_str(), b2nsm_strerror()); |
| 69 | } |
| 70 | |
| 71 | if (b2nsm_callback("RC_START", m_Start) < 0) { |
| 72 | fprintf(stderr, "RFNSM : %s hooking START failed, %s\n", |
| 73 | m_nodename.c_str(), b2nsm_strerror()); |
| 74 | } |
| 75 | |
| 76 | if (b2nsm_callback("RC_STOP", m_Stop) < 0) { |
| 77 | fprintf(stderr, "RFNSM : %s hooking STOP failed, %s\n", |
| 78 | m_nodename.c_str(), b2nsm_strerror()); |
| 79 | } |
| 80 | |
| 81 | if (b2nsm_callback("RC_PAUSE", m_Pause) < 0) { |
| 82 | fprintf(stderr, "RFNSM : %s hooking PAUSE failed, %s\n", |
| 83 | m_nodename.c_str(), b2nsm_strerror()); |
| 84 | } |
| 85 | |
| 86 | if (b2nsm_callback("RC_RESUME", m_Resume) < 0) { |
| 87 | fprintf(stderr, "RFNSM : %s hooking RESUME failed, %s\n", |
| 88 | m_nodename.c_str(), b2nsm_strerror()); |
| 89 | } |
| 90 | |
| 91 | if (b2nsm_callback("RC_RECOVER", m_Restart) < 0) { |
| 92 | fprintf(stderr, "RFNSM : %s hooking RESTART failed, %s\n", |
| 93 | m_nodename.c_str(), b2nsm_strerror()); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | if (b2nsm_callback("RC_STATUS", m_Status) < 0) { |
| 98 | fprintf(stderr, "RFNSM : %s hooking STATUS failed, %s\n", |
| 99 | m_nodename.c_str(), b2nsm_strerror()); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | if (b2nsm_callback("OK", m_OK) < 0) { |
| 104 | fprintf(stderr, "RFNSM : %s hooking OK failed, %s\n", |
| 105 | m_nodename.c_str(), b2nsm_strerror()); |
| 106 | } |
| 107 | if (b2nsm_callback("ERROR", m_ERROR) < 0) { |
| 108 | fprintf(stderr, "RFNSM : %s hooking ERROR failed, %s\n", |
| 109 | m_nodename.c_str(), b2nsm_strerror()); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED); |
| 114 | } |
| 115 | |
| 116 | RFNSM::~RFNSM() |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | |
| 121 | void RFNSM::AllocMem(char* format) |
| 122 | { |
| 123 | printf("AllocMem : format file = %s\n", format); |
| 124 | |
| 125 | m_info = (RfNodeInfo*)b2nsm_allocmem(m_nodename.c_str(), format, |
| 126 | 1, 3); |
| 127 | if (!m_info) { |
| 128 | fprintf(RFNSMOUT, "RFNSM : %s allocmem failure, %s\n", |
| 129 | m_nodename.c_str(), b2nsm_strerror()); |
| 130 | } |
| 131 | |
| 132 | m_formatfile = string(format); |
| 133 | |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void RFNSM::m_Configure(NSMmsg* msg, NSMcontext* ctx) |
| 138 | { |
| 139 | fflush(stdout); |
| 140 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 141 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 142 | int stat = g_nsmserver->Configure(msg, ctx); |
| 143 | fflush(stdout); |
| 144 | if (stat == 0) { |
| 145 | RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED); |
| 146 | b2nsm_ok(msg, "Configured", NULL); |
| 147 | } else { |
| 148 | RFNSM_Status::Instance().set_state(nsmstate); |
| 149 | b2nsm_error(msg, NULL); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void RFNSM::m_UnConfigure(NSMmsg* msg, NSMcontext* ctx) |
| 154 | { |
| 155 | fflush(stdout); |
| 156 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 157 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 158 | int stat = g_nsmserver->UnConfigure(msg, ctx); |
| 159 | fflush(stdout); |
| 160 | if (stat == 0) { |
| 161 | RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED); |
| 162 | b2nsm_ok(msg, "Unconfigured", NULL); |
| 163 | } else { |
| 164 | RFNSM_Status::Instance().set_state(nsmstate); |
| 165 | b2nsm_error(msg, NULL); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void RFNSM::m_Start(NSMmsg* msg, NSMcontext* ctx) |
| 170 | { |
| 171 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 172 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 173 | int stat = g_nsmserver->Start(msg, ctx); |
| 174 | if (stat == 0) { |
| 175 | RFNSM_Status::Instance().set_state(RFSTATE_RUNNING); |
| 176 | b2nsm_ok(msg, "Running", NULL); |
| 177 | } else { |
| 178 | RFNSM_Status::Instance().set_state(nsmstate); |
| 179 | b2nsm_error(msg, NULL); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void RFNSM::m_Stop(NSMmsg* msg, NSMcontext* ctx) |
| 184 | { |
| 185 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 186 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 187 | int stat = g_nsmserver->Stop(msg, ctx); |
| 188 | if (stat == 0) { |
| 189 | RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED); |
| 190 | b2nsm_ok(msg, "Stopped", NULL); |
| 191 | } else { |
| 192 | RFNSM_Status::Instance().set_state(nsmstate); |
| 193 | b2nsm_error(msg, NULL); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | void RFNSM::m_Pause(NSMmsg* msg, NSMcontext* ctx) |
| 198 | { |
| 199 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 200 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 201 | int stat = g_nsmserver->Pause(msg, ctx); |
| 202 | if (stat == 0) { |
| 203 | RFNSM_Status::Instance().set_state(RFSTATE_IDLE); |
| 204 | b2nsm_ok(msg, "Idle", NULL); |
| 205 | } else { |
| 206 | RFNSM_Status::Instance().set_state(nsmstate); |
| 207 | b2nsm_error(msg, NULL); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | void RFNSM::m_Resume(NSMmsg* msg, NSMcontext* ctx) |
| 212 | { |
| 213 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 214 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 215 | int stat = g_nsmserver->Resume(msg, ctx); |
| 216 | if (stat == 0) { |
| 217 | RFNSM_Status::Instance().set_state(RFSTATE_RUNNING); |
| 218 | b2nsm_ok(msg, "Running", NULL); |
| 219 | } else { |
| 220 | RFNSM_Status::Instance().set_state(nsmstate); |
| 221 | b2nsm_error(msg, NULL); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void RFNSM::m_Restart(NSMmsg* msg, NSMcontext* ctx) |
| 226 | { |
| 227 | int nsmstate = RFNSM_Status::Instance().get_state(); |
| 228 | RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION); |
| 229 | int stat = g_nsmserver->Restart(msg, ctx); |
| 230 | if (stat == 0) { |
| 231 | RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED); |
| 232 | b2nsm_ok(msg, "Configured", NULL); |
| 233 | } else { |
| 234 | RFNSM_Status::Instance().set_state(nsmstate); |
| 235 | b2nsm_error(msg, NULL); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | void RFNSM::m_Status(NSMmsg* msg, NSMcontext* ) |
| 240 | { |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | int curstate = RFNSM_Status::Instance().get_state(); |
| 1 | Calling 'RFNSM_Status::Instance' | |
|
| 5 | | Returning from 'RFNSM_Status::Instance' | |
|
| 6 | | Calling 'RFNSM_Status::get_state' | |
|
| 249 | b2nsm_ok(msg, RFSTATE[curstate].c_str(), NULL); |
| 250 | |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void RFNSM::m_OK(NSMmsg* , NSMcontext* ) |
| 255 | { |
| 256 | RFNSM_Status& rfs = RFNSM_Status::Instance(); |
| 257 | int flag = rfs.get_flag(); |
| 258 | flag++; |
| 259 | rfs.set_flag(flag); |
| 260 | |
| 261 | } |
| 262 | |
| 263 | void RFNSM::m_ERROR(NSMmsg* , NSMcontext* ) |
| 264 | { |
| 265 | RFNSM_Status::Instance().set_flag(-1); |
| 266 | |
| 267 | } |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | RfNodeInfo* RFNSM::GetNodeInfo() |
| 273 | { |
| 274 | return m_info; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | |
| 279 | RFNSM_Status::RFNSM_Status() |
| 280 | { |
| 281 | } |
| 282 | |
| 283 | RFNSM_Status::~RFNSM_Status() |
| 284 | { |
| 285 | } |
| 286 | |
| 287 | RFNSM_Status& RFNSM_Status::Instance() |
| 288 | { |
| 289 | if (!s_instance) { |
| 2 | | Assuming 's_instance' is null | |
|
| |
| 290 | s_instance = new RFNSM_Status; |
| 4 | | Uninitialized value stored to field 'm_state' | |
|
| 291 | } |
| 292 | return *s_instance; |
| 293 | } |
| 294 | |
| 295 | void RFNSM_Status::set_flag(int val) |
| 296 | { |
| 297 | m_flag = val; |
| 298 | } |
| 299 | |
| 300 | int RFNSM_Status::get_flag() |
| 301 | { |
| 302 | return m_flag; |
| 303 | } |
| 304 | |
| 305 | void RFNSM_Status::set_state(int val) |
| 306 | { |
| 307 | m_state = val; |
| 308 | } |
| 309 | |
| 310 | int RFNSM_Status::get_state() |
| 311 | { |
| 312 | return m_state; |
| 7 | | Undefined or garbage value returned to caller |
|
| 313 | } |