| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/log.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | static LogLevel log_level = SYSLOG_LEVEL_INFO; | - | ||||||||||||
| 12 | static int log_on_stderr = 1; | - | ||||||||||||
| 13 | static int log_stderr_fd = | - | ||||||||||||
| 14 | 2 | - | ||||||||||||
| 15 | ; | - | ||||||||||||
| 16 | static int log_facility = | - | ||||||||||||
| 17 | (4<<3) | - | ||||||||||||
| 18 | ; | - | ||||||||||||
| 19 | static char *argv0; | - | ||||||||||||
| 20 | static log_handler_fn *log_handler; | - | ||||||||||||
| 21 | static void *log_handler_ctx; | - | ||||||||||||
| 22 | - | |||||||||||||
| 23 | extern char *__progname; | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | - | |||||||||||||
| 26 | - | |||||||||||||
| 27 | - | |||||||||||||
| 28 | - | |||||||||||||
| 29 | - | |||||||||||||
| 30 | static struct { | - | ||||||||||||
| 31 | const char *name; | - | ||||||||||||
| 32 | SyslogFacility val; | - | ||||||||||||
| 33 | } log_facilities[] = { | - | ||||||||||||
| 34 | { "DAEMON", SYSLOG_FACILITY_DAEMON }, | - | ||||||||||||
| 35 | { "USER", SYSLOG_FACILITY_USER }, | - | ||||||||||||
| 36 | { "AUTH", SYSLOG_FACILITY_AUTH }, | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | { "AUTHPRIV", SYSLOG_FACILITY_AUTHPRIV }, | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | { "LOCAL0", SYSLOG_FACILITY_LOCAL0 }, | - | ||||||||||||
| 41 | { "LOCAL1", SYSLOG_FACILITY_LOCAL1 }, | - | ||||||||||||
| 42 | { "LOCAL2", SYSLOG_FACILITY_LOCAL2 }, | - | ||||||||||||
| 43 | { "LOCAL3", SYSLOG_FACILITY_LOCAL3 }, | - | ||||||||||||
| 44 | { "LOCAL4", SYSLOG_FACILITY_LOCAL4 }, | - | ||||||||||||
| 45 | { "LOCAL5", SYSLOG_FACILITY_LOCAL5 }, | - | ||||||||||||
| 46 | { "LOCAL6", SYSLOG_FACILITY_LOCAL6 }, | - | ||||||||||||
| 47 | { "LOCAL7", SYSLOG_FACILITY_LOCAL7 }, | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | ((void *)0) | - | ||||||||||||
| 50 | , SYSLOG_FACILITY_NOT_SET } | - | ||||||||||||
| 51 | }; | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | static struct { | - | ||||||||||||
| 54 | const char *name; | - | ||||||||||||
| 55 | LogLevel val; | - | ||||||||||||
| 56 | } log_levels[] = | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | { "QUIET", SYSLOG_LEVEL_QUIET }, | - | ||||||||||||
| 59 | { "FATAL", SYSLOG_LEVEL_FATAL }, | - | ||||||||||||
| 60 | { "ERROR", SYSLOG_LEVEL_ERROR }, | - | ||||||||||||
| 61 | { "INFO", SYSLOG_LEVEL_INFO }, | - | ||||||||||||
| 62 | { "VERBOSE", SYSLOG_LEVEL_VERBOSE }, | - | ||||||||||||
| 63 | { "DEBUG", SYSLOG_LEVEL_DEBUG1 }, | - | ||||||||||||
| 64 | { "DEBUG1", SYSLOG_LEVEL_DEBUG1 }, | - | ||||||||||||
| 65 | { "DEBUG2", SYSLOG_LEVEL_DEBUG2 }, | - | ||||||||||||
| 66 | { "DEBUG3", SYSLOG_LEVEL_DEBUG3 }, | - | ||||||||||||
| 67 | { | - | ||||||||||||
| 68 | ((void *)0) | - | ||||||||||||
| 69 | , SYSLOG_LEVEL_NOT_SET } | - | ||||||||||||
| 70 | }; | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | LogLevel | - | ||||||||||||
| 73 | log_level_get(void) | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | return never executed: log_level;return log_level;never executed: return log_level; | 0 | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | SyslogFacility | - | ||||||||||||
| 79 | log_facility_number(char *name) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | int i; | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | if (name !=
| 0 | ||||||||||||
| 84 | ((void *)0)
| 0 | ||||||||||||
| 85 | ) | - | ||||||||||||
| 86 | for (i = 0; log_facilities[i].name
| 0 | ||||||||||||
| 87 | if (strcasecmp(log_facilities[i].name, name) == 0
| 0 | ||||||||||||
| 88 | return never executed: log_facilities[i].val;return log_facilities[i].val;never executed: return log_facilities[i].val; | 0 | ||||||||||||
| 89 | return never executed: SYSLOG_FACILITY_NOT_SET;return SYSLOG_FACILITY_NOT_SET;never executed: return SYSLOG_FACILITY_NOT_SET; | 0 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | const char * | - | ||||||||||||
| 93 | log_facility_name(SyslogFacility facility) | - | ||||||||||||
| 94 | { | - | ||||||||||||
| 95 | u_int i; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | for (i = 0; log_facilities[i].name
| 0 | ||||||||||||
| 98 | if (log_facilities[i].val == facility
| 0 | ||||||||||||
| 99 | return never executed: log_facilities[i].name;return log_facilities[i].name;never executed: return log_facilities[i].name; | 0 | ||||||||||||
| 100 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 101 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 102 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | LogLevel | - | ||||||||||||
| 106 | log_level_number(char *name) | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | int i; | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | if (name !=
| 0-2 | ||||||||||||
| 111 | ((void *)0)
| 0-2 | ||||||||||||
| 112 | ) | - | ||||||||||||
| 113 | for (i = 0; log_levels[i].name
| 0-18 | ||||||||||||
| 114 | if (strcasecmp(log_levels[i].name, name) == 0
| 2-16 | ||||||||||||
| 115 | return executed 2 times by 1 test: log_levels[i].val;return log_levels[i].val;Executed by:
executed 2 times by 1 test: return log_levels[i].val;Executed by:
| 2 | ||||||||||||
| 116 | return never executed: SYSLOG_LEVEL_NOT_SET;return SYSLOG_LEVEL_NOT_SET;never executed: return SYSLOG_LEVEL_NOT_SET; | 0 | ||||||||||||
| 117 | } | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | const char * | - | ||||||||||||
| 120 | log_level_name(LogLevel level) | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | u_int i; | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | for (i = 0; log_levels[i].name !=
| 0 | ||||||||||||
| 125 | ((void *)0)
| 0 | ||||||||||||
| 126 | ; i++) | - | ||||||||||||
| 127 | if (log_levels[i].val == level
| 0 | ||||||||||||
| 128 | return never executed: log_levels[i].name;return log_levels[i].name;never executed: return log_levels[i].name; | 0 | ||||||||||||
| 129 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 130 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 131 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 132 | } | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | - | |||||||||||||
| 135 | - | |||||||||||||
| 136 | void | - | ||||||||||||
| 137 | error(const char *fmt,...) | - | ||||||||||||
| 138 | { | - | ||||||||||||
| 139 | va_list args; | - | ||||||||||||
| 140 | - | |||||||||||||
| 141 | - | |||||||||||||
| 142 | __builtin_va_start( | - | ||||||||||||
| 143 | args | - | ||||||||||||
| 144 | , | - | ||||||||||||
| 145 | fmt | - | ||||||||||||
| 146 | ) | - | ||||||||||||
| 147 | ; | - | ||||||||||||
| 148 | do_log(SYSLOG_LEVEL_ERROR, fmt, args); | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | __builtin_va_end( | - | ||||||||||||
| 151 | args | - | ||||||||||||
| 152 | ) | - | ||||||||||||
| 153 | ; | - | ||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||
| 155 | - | |||||||||||||
| 156 | void | - | ||||||||||||
| 157 | sigdie(const char *fmt,...) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | - | |||||||||||||
| 161 | - | |||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | - | |||||||||||||
| 165 | - | |||||||||||||
| 166 | _exit(1); | - | ||||||||||||
| 167 | } never executed: end of block | 0 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | void | - | ||||||||||||
| 170 | logdie(const char *fmt,...) | - | ||||||||||||
| 171 | { | - | ||||||||||||
| 172 | va_list args; | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | - | |||||||||||||
| 175 | __builtin_va_start( | - | ||||||||||||
| 176 | args | - | ||||||||||||
| 177 | , | - | ||||||||||||
| 178 | fmt | - | ||||||||||||
| 179 | ) | - | ||||||||||||
| 180 | ; | - | ||||||||||||
| 181 | do_log(SYSLOG_LEVEL_INFO, fmt, args); | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | __builtin_va_end( | - | ||||||||||||
| 184 | args | - | ||||||||||||
| 185 | ) | - | ||||||||||||
| 186 | ; | - | ||||||||||||
| 187 | cleanup_exit(255); | - | ||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | - | |||||||||||||
| 191 | - | |||||||||||||
| 192 | void | - | ||||||||||||
| 193 | logit(const char *fmt,...) | - | ||||||||||||
| 194 | { | - | ||||||||||||
| 195 | va_list args; | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | - | |||||||||||||
| 198 | __builtin_va_start( | - | ||||||||||||
| 199 | args | - | ||||||||||||
| 200 | , | - | ||||||||||||
| 201 | fmt | - | ||||||||||||
| 202 | ) | - | ||||||||||||
| 203 | ; | - | ||||||||||||
| 204 | do_log(SYSLOG_LEVEL_INFO, fmt, args); | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | __builtin_va_end( | - | ||||||||||||
| 207 | args | - | ||||||||||||
| 208 | ) | - | ||||||||||||
| 209 | ; | - | ||||||||||||
| 210 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||
| 211 | - | |||||||||||||
| 212 | - | |||||||||||||
| 213 | - | |||||||||||||
| 214 | void | - | ||||||||||||
| 215 | verbose(const char *fmt,...) | - | ||||||||||||
| 216 | { | - | ||||||||||||
| 217 | va_list args; | - | ||||||||||||
| 218 | - | |||||||||||||
| 219 | - | |||||||||||||
| 220 | __builtin_va_start( | - | ||||||||||||
| 221 | args | - | ||||||||||||
| 222 | , | - | ||||||||||||
| 223 | fmt | - | ||||||||||||
| 224 | ) | - | ||||||||||||
| 225 | ; | - | ||||||||||||
| 226 | do_log(SYSLOG_LEVEL_VERBOSE, fmt, args); | - | ||||||||||||
| 227 | - | |||||||||||||
| 228 | __builtin_va_end( | - | ||||||||||||
| 229 | args | - | ||||||||||||
| 230 | ) | - | ||||||||||||
| 231 | ; | - | ||||||||||||
| 232 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | - | |||||||||||||
| 235 | - | |||||||||||||
| 236 | void | - | ||||||||||||
| 237 | debug(const char *fmt,...) | - | ||||||||||||
| 238 | { | - | ||||||||||||
| 239 | va_list args; | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | - | |||||||||||||
| 242 | __builtin_va_start( | - | ||||||||||||
| 243 | args | - | ||||||||||||
| 244 | , | - | ||||||||||||
| 245 | fmt | - | ||||||||||||
| 246 | ) | - | ||||||||||||
| 247 | ; | - | ||||||||||||
| 248 | do_log(SYSLOG_LEVEL_DEBUG1, fmt, args); | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | __builtin_va_end( | - | ||||||||||||
| 251 | args | - | ||||||||||||
| 252 | ) | - | ||||||||||||
| 253 | ; | - | ||||||||||||
| 254 | } executed 5063 times by 3 tests: end of blockExecuted by:
| 5063 | ||||||||||||
| 255 | - | |||||||||||||
| 256 | void | - | ||||||||||||
| 257 | debug2(const char *fmt,...) | - | ||||||||||||
| 258 | { | - | ||||||||||||
| 259 | va_list args; | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | - | |||||||||||||
| 262 | __builtin_va_start( | - | ||||||||||||
| 263 | args | - | ||||||||||||
| 264 | , | - | ||||||||||||
| 265 | fmt | - | ||||||||||||
| 266 | ) | - | ||||||||||||
| 267 | ; | - | ||||||||||||
| 268 | do_log(SYSLOG_LEVEL_DEBUG2, fmt, args); | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | __builtin_va_end( | - | ||||||||||||
| 271 | args | - | ||||||||||||
| 272 | ) | - | ||||||||||||
| 273 | ; | - | ||||||||||||
| 274 | } executed 24594 times by 5 tests: end of blockExecuted by:
| 24594 | ||||||||||||
| 275 | - | |||||||||||||
| 276 | void | - | ||||||||||||
| 277 | debug3(const char *fmt,...) | - | ||||||||||||
| 278 | { | - | ||||||||||||
| 279 | va_list args; | - | ||||||||||||
| 280 | - | |||||||||||||
| 281 | - | |||||||||||||
| 282 | __builtin_va_start( | - | ||||||||||||
| 283 | args | - | ||||||||||||
| 284 | , | - | ||||||||||||
| 285 | fmt | - | ||||||||||||
| 286 | ) | - | ||||||||||||
| 287 | ; | - | ||||||||||||
| 288 | do_log(SYSLOG_LEVEL_DEBUG3, fmt, args); | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | __builtin_va_end( | - | ||||||||||||
| 291 | args | - | ||||||||||||
| 292 | ) | - | ||||||||||||
| 293 | ; | - | ||||||||||||
| 294 | } executed 3195 times by 3 tests: end of blockExecuted by:
| 3195 | ||||||||||||
| 295 | - | |||||||||||||
| 296 | - | |||||||||||||
| 297 | - | |||||||||||||
| 298 | - | |||||||||||||
| 299 | - | |||||||||||||
| 300 | void | - | ||||||||||||
| 301 | log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr) | - | ||||||||||||
| 302 | { | - | ||||||||||||
| 303 | - | |||||||||||||
| 304 | - | |||||||||||||
| 305 | - | |||||||||||||
| 306 | - | |||||||||||||
| 307 | argv0 = av0; | - | ||||||||||||
| 308 | - | |||||||||||||
| 309 | if (log_change_level(level) != 0
| 0-58 | ||||||||||||
| 310 | fprintf( | - | ||||||||||||
| 311 | stderr | - | ||||||||||||
| 312 | , "Unrecognized internal syslog level code %d\n", | - | ||||||||||||
| 313 | (int) level); | - | ||||||||||||
| 314 | exit(1); never executed: exit(1); | 0 | ||||||||||||
| 315 | } | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | log_handler = | - | ||||||||||||
| 318 | ((void *)0) | - | ||||||||||||
| 319 | ; | - | ||||||||||||
| 320 | log_handler_ctx = | - | ||||||||||||
| 321 | ((void *)0) | - | ||||||||||||
| 322 | ; | - | ||||||||||||
| 323 | - | |||||||||||||
| 324 | log_on_stderr = on_stderr; | - | ||||||||||||
| 325 | if (on_stderr
| 0-58 | ||||||||||||
| 326 | return; executed 58 times by 2 tests: return;Executed by:
| 58 | ||||||||||||
| 327 | - | |||||||||||||
| 328 | switch (facility) { | - | ||||||||||||
| 329 | case never executed: SYSLOG_FACILITY_DAEMON:case SYSLOG_FACILITY_DAEMON:never executed: case SYSLOG_FACILITY_DAEMON: | 0 | ||||||||||||
| 330 | log_facility = | - | ||||||||||||
| 331 | (3<<3) | - | ||||||||||||
| 332 | ; | - | ||||||||||||
| 333 | break; never executed: break; | 0 | ||||||||||||
| 334 | case never executed: SYSLOG_FACILITY_USER:case SYSLOG_FACILITY_USER:never executed: case SYSLOG_FACILITY_USER: | 0 | ||||||||||||
| 335 | log_facility = | - | ||||||||||||
| 336 | (1<<3) | - | ||||||||||||
| 337 | ; | - | ||||||||||||
| 338 | break; never executed: break; | 0 | ||||||||||||
| 339 | case never executed: SYSLOG_FACILITY_AUTH:case SYSLOG_FACILITY_AUTH:never executed: case SYSLOG_FACILITY_AUTH: | 0 | ||||||||||||
| 340 | log_facility = | - | ||||||||||||
| 341 | (4<<3) | - | ||||||||||||
| 342 | ; | - | ||||||||||||
| 343 | break; never executed: break; | 0 | ||||||||||||
| 344 | - | |||||||||||||
| 345 | case never executed: SYSLOG_FACILITY_AUTHPRIV:case SYSLOG_FACILITY_AUTHPRIV:never executed: case SYSLOG_FACILITY_AUTHPRIV: | 0 | ||||||||||||
| 346 | log_facility = | - | ||||||||||||
| 347 | (10<<3) | - | ||||||||||||
| 348 | ; | - | ||||||||||||
| 349 | break; never executed: break; | 0 | ||||||||||||
| 350 | - | |||||||||||||
| 351 | case never executed: SYSLOG_FACILITY_LOCAL0:case SYSLOG_FACILITY_LOCAL0:never executed: case SYSLOG_FACILITY_LOCAL0: | 0 | ||||||||||||
| 352 | log_facility = | - | ||||||||||||
| 353 | (16<<3) | - | ||||||||||||
| 354 | ; | - | ||||||||||||
| 355 | break; never executed: break; | 0 | ||||||||||||
| 356 | case never executed: SYSLOG_FACILITY_LOCAL1:case SYSLOG_FACILITY_LOCAL1:never executed: case SYSLOG_FACILITY_LOCAL1: | 0 | ||||||||||||
| 357 | log_facility = | - | ||||||||||||
| 358 | (17<<3) | - | ||||||||||||
| 359 | ; | - | ||||||||||||
| 360 | break; never executed: break; | 0 | ||||||||||||
| 361 | case never executed: SYSLOG_FACILITY_LOCAL2:case SYSLOG_FACILITY_LOCAL2:never executed: case SYSLOG_FACILITY_LOCAL2: | 0 | ||||||||||||
| 362 | log_facility = | - | ||||||||||||
| 363 | (18<<3) | - | ||||||||||||
| 364 | ; | - | ||||||||||||
| 365 | break; never executed: break; | 0 | ||||||||||||
| 366 | case never executed: SYSLOG_FACILITY_LOCAL3:case SYSLOG_FACILITY_LOCAL3:never executed: case SYSLOG_FACILITY_LOCAL3: | 0 | ||||||||||||
| 367 | log_facility = | - | ||||||||||||
| 368 | (19<<3) | - | ||||||||||||
| 369 | ; | - | ||||||||||||
| 370 | break; never executed: break; | 0 | ||||||||||||
| 371 | case never executed: SYSLOG_FACILITY_LOCAL4:case SYSLOG_FACILITY_LOCAL4:never executed: case SYSLOG_FACILITY_LOCAL4: | 0 | ||||||||||||
| 372 | log_facility = | - | ||||||||||||
| 373 | (20<<3) | - | ||||||||||||
| 374 | ; | - | ||||||||||||
| 375 | break; never executed: break; | 0 | ||||||||||||
| 376 | case never executed: SYSLOG_FACILITY_LOCAL5:case SYSLOG_FACILITY_LOCAL5:never executed: case SYSLOG_FACILITY_LOCAL5: | 0 | ||||||||||||
| 377 | log_facility = | - | ||||||||||||
| 378 | (21<<3) | - | ||||||||||||
| 379 | ; | - | ||||||||||||
| 380 | break; never executed: break; | 0 | ||||||||||||
| 381 | case never executed: SYSLOG_FACILITY_LOCAL6:case SYSLOG_FACILITY_LOCAL6:never executed: case SYSLOG_FACILITY_LOCAL6: | 0 | ||||||||||||
| 382 | log_facility = | - | ||||||||||||
| 383 | (22<<3) | - | ||||||||||||
| 384 | ; | - | ||||||||||||
| 385 | break; never executed: break; | 0 | ||||||||||||
| 386 | case never executed: SYSLOG_FACILITY_LOCAL7:case SYSLOG_FACILITY_LOCAL7:never executed: case SYSLOG_FACILITY_LOCAL7: | 0 | ||||||||||||
| 387 | log_facility = | - | ||||||||||||
| 388 | (23<<3) | - | ||||||||||||
| 389 | ; | - | ||||||||||||
| 390 | break; never executed: break; | 0 | ||||||||||||
| 391 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 392 | fprintf( | - | ||||||||||||
| 393 | stderr | - | ||||||||||||
| 394 | , | - | ||||||||||||
| 395 | "Unrecognized internal syslog facility code %d\n", | - | ||||||||||||
| 396 | (int) facility); | - | ||||||||||||
| 397 | exit(1); never executed: exit(1); | 0 | ||||||||||||
| 398 | } | - | ||||||||||||
| 399 | openlog(argv0 ? argv0 : __progname, | - | ||||||||||||
| 400 | 0x01 | - | ||||||||||||
| 401 | , log_facility); | - | ||||||||||||
| 402 | closelog(); | - | ||||||||||||
| 403 | - | |||||||||||||
| 404 | } never executed: end of block | 0 | ||||||||||||
| 405 | - | |||||||||||||
| 406 | int | - | ||||||||||||
| 407 | log_change_level(LogLevel new_log_level) | - | ||||||||||||
| 408 | { | - | ||||||||||||
| 409 | - | |||||||||||||
| 410 | if (argv0 ==
| 0-58 | ||||||||||||
| 411 | ((void *)0)
| 0-58 | ||||||||||||
| 412 | ) | - | ||||||||||||
| 413 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 414 | - | |||||||||||||
| 415 | switch (new_log_level) { | - | ||||||||||||
| 416 | case never executed: SYSLOG_LEVEL_QUIET:case SYSLOG_LEVEL_QUIET:never executed: case SYSLOG_LEVEL_QUIET: | 0 | ||||||||||||
| 417 | case never executed: SYSLOG_LEVEL_FATAL:case SYSLOG_LEVEL_FATAL:never executed: case SYSLOG_LEVEL_FATAL: | 0 | ||||||||||||
| 418 | case never executed: SYSLOG_LEVEL_ERROR:case SYSLOG_LEVEL_ERROR:never executed: case SYSLOG_LEVEL_ERROR: | 0 | ||||||||||||
| 419 | case executed 58 times by 2 tests: SYSLOG_LEVEL_INFO:case SYSLOG_LEVEL_INFO:Executed by:
executed 58 times by 2 tests: case SYSLOG_LEVEL_INFO:Executed by:
| 58 | ||||||||||||
| 420 | case never executed: SYSLOG_LEVEL_VERBOSE:case SYSLOG_LEVEL_VERBOSE:never executed: case SYSLOG_LEVEL_VERBOSE: | 0 | ||||||||||||
| 421 | case never executed: SYSLOG_LEVEL_DEBUG1:case SYSLOG_LEVEL_DEBUG1:never executed: case SYSLOG_LEVEL_DEBUG1: | 0 | ||||||||||||
| 422 | case never executed: SYSLOG_LEVEL_DEBUG2:case SYSLOG_LEVEL_DEBUG2:never executed: case SYSLOG_LEVEL_DEBUG2: | 0 | ||||||||||||
| 423 | case never executed: SYSLOG_LEVEL_DEBUG3:case SYSLOG_LEVEL_DEBUG3:never executed: case SYSLOG_LEVEL_DEBUG3: | 0 | ||||||||||||
| 424 | log_level = new_log_level; | - | ||||||||||||
| 425 | return executed 58 times by 2 tests: 0;return 0;Executed by:
executed 58 times by 2 tests: return 0;Executed by:
| 58 | ||||||||||||
| 426 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 427 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 428 | } | - | ||||||||||||
| 429 | } | - | ||||||||||||
| 430 | - | |||||||||||||
| 431 | int | - | ||||||||||||
| 432 | log_is_on_stderr(void) | - | ||||||||||||
| 433 | { | - | ||||||||||||
| 434 | return never executed: log_on_stderrreturn log_on_stderr && log_stderr_fd == 2 ;
never executed: return log_on_stderr && log_stderr_fd == 2 ; | 0 | ||||||||||||
| 435 | 2
never executed: return log_on_stderr && log_stderr_fd == 2 ; | 0 | ||||||||||||
| 436 | ; never executed: return log_on_stderr && log_stderr_fd == 2 ; | 0 | ||||||||||||
| 437 | } | - | ||||||||||||
| 438 | - | |||||||||||||
| 439 | - | |||||||||||||
| 440 | void | - | ||||||||||||
| 441 | log_redirect_stderr_to(const char *logfile) | - | ||||||||||||
| 442 | { | - | ||||||||||||
| 443 | int fd; | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | if ((
| 0 | ||||||||||||
| 446 | 01
| 0 | ||||||||||||
| 447 | |
| 0 | ||||||||||||
| 448 | 0100
| 0 | ||||||||||||
| 449 | |
| 0 | ||||||||||||
| 450 | 02000
| 0 | ||||||||||||
| 451 | , 0600)) == -1
| 0 | ||||||||||||
| 452 | fprintf( | - | ||||||||||||
| 453 | stderr | - | ||||||||||||
| 454 | , "Couldn't open logfile %s: %s\n", logfile, | - | ||||||||||||
| 455 | strerror( | - | ||||||||||||
| 456 | (*__errno_location ()) | - | ||||||||||||
| 457 | )); | - | ||||||||||||
| 458 | exit(1); never executed: exit(1); | 0 | ||||||||||||
| 459 | } | - | ||||||||||||
| 460 | log_stderr_fd = fd; | - | ||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||
| 462 | - | |||||||||||||
| 463 | - | |||||||||||||
| 464 | - | |||||||||||||
| 465 | void | - | ||||||||||||
| 466 | set_log_handler(log_handler_fn *handler, void *ctx) | - | ||||||||||||
| 467 | { | - | ||||||||||||
| 468 | log_handler = handler; | - | ||||||||||||
| 469 | log_handler_ctx = ctx; | - | ||||||||||||
| 470 | } never executed: end of block | 0 | ||||||||||||
| 471 | - | |||||||||||||
| 472 | void | - | ||||||||||||
| 473 | do_log2(LogLevel level, const char *fmt,...) | - | ||||||||||||
| 474 | { | - | ||||||||||||
| 475 | va_list args; | - | ||||||||||||
| 476 | - | |||||||||||||
| 477 | - | |||||||||||||
| 478 | __builtin_va_start( | - | ||||||||||||
| 479 | args | - | ||||||||||||
| 480 | , | - | ||||||||||||
| 481 | fmt | - | ||||||||||||
| 482 | ) | - | ||||||||||||
| 483 | ; | - | ||||||||||||
| 484 | do_log(level, fmt, args); | - | ||||||||||||
| 485 | - | |||||||||||||
| 486 | __builtin_va_end( | - | ||||||||||||
| 487 | args | - | ||||||||||||
| 488 | ) | - | ||||||||||||
| 489 | ; | - | ||||||||||||
| 490 | } never executed: end of block | 0 | ||||||||||||
| 491 | - | |||||||||||||
| 492 | void | - | ||||||||||||
| 493 | do_log(LogLevel level, const char *fmt, va_list args) | - | ||||||||||||
| 494 | { | - | ||||||||||||
| 495 | - | |||||||||||||
| 496 | - | |||||||||||||
| 497 | - | |||||||||||||
| 498 | char msgbuf[1024]; | - | ||||||||||||
| 499 | char fmtbuf[1024]; | - | ||||||||||||
| 500 | char *txt = | - | ||||||||||||
| 501 | ((void *)0) | - | ||||||||||||
| 502 | ; | - | ||||||||||||
| 503 | int pri = | - | ||||||||||||
| 504 | 6 | - | ||||||||||||
| 505 | ; | - | ||||||||||||
| 506 | int saved_errno = | - | ||||||||||||
| 507 | (*__errno_location ()) | - | ||||||||||||
| 508 | ; | - | ||||||||||||
| 509 | log_handler_fn *tmp_handler; | - | ||||||||||||
| 510 | - | |||||||||||||
| 511 | if (level > log_level
| 40-32870 | ||||||||||||
| 512 | return; executed 32870 times by 6 tests: return;Executed by:
| 32870 | ||||||||||||
| 513 | - | |||||||||||||
| 514 | switch (level) { | - | ||||||||||||
| 515 | case never executed: SYSLOG_LEVEL_FATAL:case SYSLOG_LEVEL_FATAL:never executed: case SYSLOG_LEVEL_FATAL: | 0 | ||||||||||||
| 516 | if (!log_on_stderr
| 0 | ||||||||||||
| 517 | txt = "fatal"; never executed: txt = "fatal"; | 0 | ||||||||||||
| 518 | pri = | - | ||||||||||||
| 519 | 2 | - | ||||||||||||
| 520 | ; | - | ||||||||||||
| 521 | break; never executed: break; | 0 | ||||||||||||
| 522 | case never executed: SYSLOG_LEVEL_ERROR:case SYSLOG_LEVEL_ERROR:never executed: case SYSLOG_LEVEL_ERROR: | 0 | ||||||||||||
| 523 | if (!log_on_stderr
| 0 | ||||||||||||
| 524 | txt = "error"; never executed: txt = "error"; | 0 | ||||||||||||
| 525 | pri = | - | ||||||||||||
| 526 | 3 | - | ||||||||||||
| 527 | ; | - | ||||||||||||
| 528 | break; never executed: break; | 0 | ||||||||||||
| 529 | case executed 40 times by 1 test: SYSLOG_LEVEL_INFO:case SYSLOG_LEVEL_INFO:Executed by:
executed 40 times by 1 test: case SYSLOG_LEVEL_INFO:Executed by:
| 40 | ||||||||||||
| 530 | pri = | - | ||||||||||||
| 531 | 6 | - | ||||||||||||
| 532 | ; | - | ||||||||||||
| 533 | break; executed 40 times by 1 test: break;Executed by:
| 40 | ||||||||||||
| 534 | case never executed: SYSLOG_LEVEL_VERBOSE:case SYSLOG_LEVEL_VERBOSE:never executed: case SYSLOG_LEVEL_VERBOSE: | 0 | ||||||||||||
| 535 | pri = | - | ||||||||||||
| 536 | 6 | - | ||||||||||||
| 537 | ; | - | ||||||||||||
| 538 | break; never executed: break; | 0 | ||||||||||||
| 539 | case never executed: SYSLOG_LEVEL_DEBUG1:case SYSLOG_LEVEL_DEBUG1:never executed: case SYSLOG_LEVEL_DEBUG1: | 0 | ||||||||||||
| 540 | txt = "debug1"; | - | ||||||||||||
| 541 | pri = | - | ||||||||||||
| 542 | 7 | - | ||||||||||||
| 543 | ; | - | ||||||||||||
| 544 | break; never executed: break; | 0 | ||||||||||||
| 545 | case never executed: SYSLOG_LEVEL_DEBUG2:case SYSLOG_LEVEL_DEBUG2:never executed: case SYSLOG_LEVEL_DEBUG2: | 0 | ||||||||||||
| 546 | txt = "debug2"; | - | ||||||||||||
| 547 | pri = | - | ||||||||||||
| 548 | 7 | - | ||||||||||||
| 549 | ; | - | ||||||||||||
| 550 | break; never executed: break; | 0 | ||||||||||||
| 551 | case never executed: SYSLOG_LEVEL_DEBUG3:case SYSLOG_LEVEL_DEBUG3:never executed: case SYSLOG_LEVEL_DEBUG3: | 0 | ||||||||||||
| 552 | txt = "debug3"; | - | ||||||||||||
| 553 | pri = | - | ||||||||||||
| 554 | 7 | - | ||||||||||||
| 555 | ; | - | ||||||||||||
| 556 | break; never executed: break; | 0 | ||||||||||||
| 557 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 558 | txt = "internal error"; | - | ||||||||||||
| 559 | pri = | - | ||||||||||||
| 560 | 3 | - | ||||||||||||
| 561 | ; | - | ||||||||||||
| 562 | break; never executed: break; | 0 | ||||||||||||
| 563 | } | - | ||||||||||||
| 564 | if (txt !=
| 0-40 | ||||||||||||
| 565 | ((void *)0)
| 0-40 | ||||||||||||
| 566 | && log_handler ==
| 0 | ||||||||||||
| 567 | ((void *)0)
| 0 | ||||||||||||
| 568 | ) { | - | ||||||||||||
| 569 | snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt); | - | ||||||||||||
| 570 | vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args); | - | ||||||||||||
| 571 | } never executed: else {end of block | 0 | ||||||||||||
| 572 | vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); | - | ||||||||||||
| 573 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||
| 574 | strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), | - | ||||||||||||
| 575 | log_on_stderr ? (0x20|0x01) : (0x02|0x10|0x08|0x01)); | - | ||||||||||||
| 576 | if (log_handler !=
| 0-40 | ||||||||||||
| 577 | ((void *)0)
| 0-40 | ||||||||||||
| 578 | ) { | - | ||||||||||||
| 579 | - | |||||||||||||
| 580 | tmp_handler = log_handler; | - | ||||||||||||
| 581 | log_handler = | - | ||||||||||||
| 582 | ((void *)0) | - | ||||||||||||
| 583 | ; | - | ||||||||||||
| 584 | tmp_handler(level, fmtbuf, log_handler_ctx); | - | ||||||||||||
| 585 | log_handler = tmp_handler; | - | ||||||||||||
| 586 | } never executed: else if (log_on_stderrend of block
| 0-40 | ||||||||||||
| 587 | snprintf(msgbuf, sizeof msgbuf, "%.*s\r\n", | - | ||||||||||||
| 588 | (int)sizeof msgbuf - 3, fmtbuf); | - | ||||||||||||
| 589 | (void)write(log_stderr_fd, msgbuf, strlen(msgbuf)); | - | ||||||||||||
| 590 | } executed 40 times by 1 test: else {end of blockExecuted by:
| 40 | ||||||||||||
| 591 | - | |||||||||||||
| 592 | - | |||||||||||||
| 593 | - | |||||||||||||
| 594 | - | |||||||||||||
| 595 | - | |||||||||||||
| 596 | openlog(argv0 ? argv0 : __progname, | - | ||||||||||||
| 597 | 0x01 | - | ||||||||||||
| 598 | , log_facility); | - | ||||||||||||
| 599 | syslog(pri, "%.500s", fmtbuf); | - | ||||||||||||
| 600 | closelog(); | - | ||||||||||||
| 601 | - | |||||||||||||
| 602 | } never executed: end of block | 0 | ||||||||||||
| 603 | - | |||||||||||||
| 604 | (*__errno_location ()) | - | ||||||||||||
| 605 | = saved_errno; | - | ||||||||||||
| 606 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||
| Switch to Source code | Preprocessed file |