Branch data Line data Source code
1 : : #include "precizer.h"
2 : : #define IN_MEMORY_DB_NAME "DisposableDB"
3 : :
4 : : /**
5 : : * Determine file name of the database.
6 : : * This database file name can be passed as an argument --database=FILE
7 : : * Unless specified, the default database filename
8 : : * will be the hostname and ".db" as the filename extension
9 : : */
10 : 325 : Return db_determine_name(void)
11 : : {
12 : : /* Status returned by this function through provide()
13 : : Default value assumes successful completion */
14 : 325 : Return status = SUCCESS;
15 : :
16 : : /* Interrupt the function smoothly */
17 : : /* Interrupt when Ctrl+C */
18 [ - + ]: 325 : if(global_interrupt_flag == true)
19 : : {
20 : 0 : provide(status);
21 : : }
22 : :
23 [ + + ]: 325 : if(config->compare == true)
24 : : {
25 [ + - ]: 76 : if(config->db_primary_file_path.length == 0)
26 : : {
27 : : // In-memory database
28 : 76 : const char in_memory_db_path[] = ":memory:";
29 : 76 : config->db_primary_path_is_memory = true;
30 : :
31 : : // Set primary DB path to SQLite in-memory marker.
32 [ + - - + ]: 76 : run(copy_buffer(conf(db_primary_file_path),in_memory_db_path,sizeof(in_memory_db_path)));
33 : : // Set display-friendly DB name for logs.
34 [ + - - + ]: 76 : run(copy_literal(conf(db_file_name),IN_MEMORY_DB_NAME));
35 : :
36 [ - + ]: 76 : if(CRITICAL & status)
37 : : {
38 : 0 : slog(ERROR,"Failed to initialize in-memory database names\n");
39 [ # # # # ]: 0 : call(del(conf(db_primary_file_path)));
40 : : }
41 : : } else {
42 : 0 : slog(ERROR,"General failure. config->db_primary_file_path must be blank for this case\n");
43 : 0 : status = FAILURE;
44 : : }
45 : :
46 : : } else {
47 : :
48 [ + + ]: 249 : if(config->db_primary_file_path.length == 0)
49 : : {
50 [ - + - + ]: 18 : call(del(conf(db_file_name)));
51 : 18 : config->db_primary_path_is_memory = false;
52 : :
53 : 18 : struct utsname utsname = {0};
54 : 18 : const char db_file_extension[] = ".db";
55 : :
56 : : // Determine local host name
57 [ - + ]: 18 : if(uname(&utsname) != 0)
58 : : {
59 : 0 : slog(ERROR,"Failed to get hostname\n");
60 : 0 : status = FAILURE;
61 : : } else {
62 : : // Build default DB path from hostname plus ".db" suffix.
63 [ + - - + ]: 18 : run(copy_cstring(conf(db_primary_file_path),utsname.nodename,sizeof(utsname.nodename)));
64 [ + - - + ]: 18 : run(concat_cstring(conf(db_primary_file_path),db_file_extension,sizeof(db_file_extension)));
65 : : // Copy the same path to db_file_name.
66 [ + - - + ]: 18 : run(copy(conf(db_file_name),conf(db_primary_file_path)));
67 : :
68 [ - + ]: 18 : if(CRITICAL & status)
69 : : {
70 : 0 : slog(ERROR,"Failed to build default database name from hostname\n");
71 [ # # # # ]: 0 : call(del(conf(db_primary_file_path)));
72 : : }
73 : : }
74 : : }
75 : : }
76 : :
77 : : // Log message when database file is specified and confirmed as persistent storage (non-memory database)
78 [ + - ]: 325 : if(TRIUMPH & status)
79 : : {
80 [ + + + + ]: 325 : if(config->db_primary_path_is_memory == false || ((rational_logger_mode & REGULAR) == 0))
81 : : {
82 : 321 : slog(EVERY,"Primary database file name: %s\n",confstr(db_file_name));
83 : : }
84 : :
85 : 325 : slog(TRACE,"Primary database file path: %s\n",confstr(db_primary_file_path));
86 : : }
87 : :
88 : 325 : slog(TRACE,"Finished determining database name\n");
89 : :
90 : 325 : provide(status);
91 : : }
|