|
61 | 61 | # endif |
62 | 62 | #endif |
63 | 63 |
|
| 64 | +#include <getopt.h> |
| 65 | +#ifndef CONFIGURATION_FILES_DIR |
| 66 | +#define CONFIGURATION_FILES_DIR "/etc" |
| 67 | +#endif |
| 68 | +#ifndef DLT_USER_IPC_PATH |
| 69 | +#define DLT_USER_IPC_PATH "/tmp" |
| 70 | +#endif |
| 71 | + |
64 | 72 | #include "dlt_types.h" |
65 | 73 | #include "dlt-daemon.h" |
66 | 74 | #include "dlt-daemon_cfg.h" |
@@ -204,7 +212,7 @@ void usage() |
204 | 212 | printf("Options:\n"); |
205 | 213 | printf(" -d Daemonize\n"); |
206 | 214 | printf(" -h Usage\n"); |
207 | | - printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n"); |
| 215 | + printf(" -c filename DLT daemon configuration file (Default: %s/dlt.conf)\n", CONFIGURATION_FILES_DIR); |
208 | 216 |
|
209 | 217 | #ifdef DLT_DAEMON_USE_FIFO_IPC |
210 | 218 | printf(" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n"); |
@@ -363,10 +371,18 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) |
363 | 371 | /* switch() */ |
364 | 372 |
|
365 | 373 | #ifdef DLT_DAEMON_USE_FIFO_IPC |
366 | | - snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, |
367 | | - "%s/dltpipes", dltFifoBaseDir); |
368 | | - snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, |
369 | | - "%s/dlt", dltFifoBaseDir); |
| 374 | + if (strlen(dltFifoBaseDir) + strlen("/dltpipes") < DLT_PATH_MAX) { |
| 375 | + snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, |
| 376 | + "%s/dltpipes", dltFifoBaseDir); |
| 377 | + } else { |
| 378 | + daemon_local->flags.userPipesDir[0] = '\0'; |
| 379 | + } |
| 380 | + if (strlen(dltFifoBaseDir) + strlen("/dlt") < DLT_PATH_MAX) { |
| 381 | + snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, |
| 382 | + "%s/dlt", dltFifoBaseDir); |
| 383 | + } else { |
| 384 | + daemon_local->flags.daemonFifoName[0] = '\0'; |
| 385 | + } |
370 | 386 | #endif |
371 | 387 |
|
372 | 388 | #ifdef DLT_SHM_ENABLE |
@@ -407,7 +423,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) |
407 | 423 | #else /* DLT_DAEMON_USE_FIFO_IPC */ |
408 | 424 | n = snprintf(daemon_local->flags.loggingFilename, |
409 | 425 | sizeof(daemon_local->flags.loggingFilename), |
410 | | - "%s/dlt.log", dltFifoBaseDir); |
| 426 | + "%s/dlt.log", DLT_USER_IPC_PATH); |
411 | 427 | #endif |
412 | 428 |
|
413 | 429 | if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) { |
@@ -1309,7 +1325,7 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca |
1309 | 1325 | } |
1310 | 1326 | #endif |
1311 | 1327 |
|
1312 | | -static int dlt_mkdir_recursive(const char *dir) |
| 1328 | +int dlt_mkdir_recursive(const char *dir) |
1313 | 1329 | { |
1314 | 1330 | int ret = 0; |
1315 | 1331 | char tmp[PATH_MAX + 1]; |
@@ -1464,21 +1480,17 @@ int main(int argc, char *argv[]) |
1464 | 1480 | PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag); |
1465 | 1481 |
|
1466 | 1482 | /* Make sure the parent user directory is created */ |
| 1483 | +const char *dir_to_create; |
1467 | 1484 | #ifdef DLT_DAEMON_USE_FIFO_IPC |
1468 | | - |
1469 | | - if (dlt_mkdir_recursive(dltFifoBaseDir) != 0) { |
1470 | | - dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", dltFifoBaseDir); |
1471 | | - return -1; |
1472 | | - } |
1473 | | - |
| 1485 | + dir_to_create = dltFifoBaseDir; |
1474 | 1486 | #else |
1475 | | - if (dlt_mkdir_recursive(DLT_USER_IPC_PATH) != 0) { |
1476 | | - dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", daemon_local.flags.appSockPath); |
| 1487 | + dir_to_create = DLT_USER_IPC_PATH; |
| 1488 | +#endif |
| 1489 | + if (dlt_mkdir_recursive(dir_to_create) != 0) { |
| 1490 | + dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", dir_to_create); |
1477 | 1491 | return -1; |
1478 | 1492 | } |
1479 | 1493 |
|
1480 | | -#endif |
1481 | | - |
1482 | 1494 | /* --- Daemon init phase 1 begin --- */ |
1483 | 1495 | if (dlt_daemon_local_init_p1(&daemon, &daemon_local, daemon_local.flags.vflag) == -1) { |
1484 | 1496 | dlt_log(LOG_CRIT, "Initialization of phase 1 failed!\n"); |
|
0 commit comments