… | |
… | |
32 | #include <object.h> |
32 | #include <object.h> |
33 | #include <funcpoint.h> |
33 | #include <funcpoint.h> |
34 | #include <loader.h> |
34 | #include <loader.h> |
35 | |
35 | |
36 | int nrofallocobjects = 0; |
36 | int nrofallocobjects = 0; |
|
|
37 | static UUID uuid; |
|
|
38 | const uint64 UUID_SKIP = 1<<19; |
37 | |
39 | |
38 | object *objects; /* Pointer to the list of used objects */ |
40 | object *objects; /* Pointer to the list of used objects */ |
39 | object *active_objects; /* List of active objects that need to be processed */ |
41 | object *active_objects; /* List of active objects that need to be processed */ |
40 | |
42 | |
41 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
43 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
… | |
… | |
49 | }; |
51 | }; |
50 | int freedir[SIZEOFFREE] = { |
52 | int freedir[SIZEOFFREE] = { |
51 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
53 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
52 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
54 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
53 | }; |
55 | }; |
|
|
56 | |
|
|
57 | static void |
|
|
58 | write_uuid (void) |
|
|
59 | { |
|
|
60 | char filename1[MAX_BUF], filename2[MAX_BUF]; |
|
|
61 | |
|
|
62 | sprintf (filename1, "%s/uuid", settings.localdir); |
|
|
63 | sprintf (filename2, "%s/uuid~", settings.localdir); |
|
|
64 | |
|
|
65 | FILE *fp; |
|
|
66 | |
|
|
67 | if (!(fp = fopen (filename2, "w"))) |
|
|
68 | { |
|
|
69 | LOG (llevError, "ERROR: cannot open %s for writing, unable to write UUID!\n", filename2); |
|
|
70 | return; |
|
|
71 | } |
|
|
72 | |
|
|
73 | fprintf (fp, "<1,%llx>\n", (unsigned long long)uuid.seq + UUID_SKIP * 2); |
|
|
74 | fclose (fp); |
|
|
75 | rename (filename2, filename1); |
|
|
76 | } |
|
|
77 | |
|
|
78 | static void |
|
|
79 | read_uuid (void) |
|
|
80 | { |
|
|
81 | char filename[MAX_BUF]; |
|
|
82 | |
|
|
83 | sprintf (filename, "%s/uuid", settings.localdir); |
|
|
84 | |
|
|
85 | FILE *fp; |
|
|
86 | |
|
|
87 | if (!(fp = fopen (filename, "r"))) |
|
|
88 | { |
|
|
89 | if (errno == ENOENT) |
|
|
90 | { |
|
|
91 | LOG (llevInfo, "RESET uid to 1\n"); |
|
|
92 | uuid.seq = 0; |
|
|
93 | write_uuid (); |
|
|
94 | return; |
|
|
95 | } |
|
|
96 | |
|
|
97 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
|
|
98 | _exit (1); |
|
|
99 | } |
|
|
100 | |
|
|
101 | int version; |
|
|
102 | unsigned long long uid; |
|
|
103 | if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1) |
|
|
104 | { |
|
|
105 | LOG (llevError, "FATAL: error reading uid from %s!\n", filename); |
|
|
106 | _exit (1); |
|
|
107 | } |
|
|
108 | |
|
|
109 | uuid.seq = uid; |
|
|
110 | write_uuid (); |
|
|
111 | LOG (llevDebug, "read UID: %lld\n", uid); |
|
|
112 | fclose (fp); |
|
|
113 | } |
|
|
114 | |
|
|
115 | UUID |
|
|
116 | gen_uuid () |
|
|
117 | { |
|
|
118 | UUID uid; |
|
|
119 | |
|
|
120 | uid.seq = ++uuid.seq; |
|
|
121 | |
|
|
122 | if (!(uuid.seq & (UUID_SKIP - 1))) |
|
|
123 | write_uuid (); |
|
|
124 | |
|
|
125 | return uid; |
|
|
126 | } |
|
|
127 | |
|
|
128 | void |
|
|
129 | init_uuid () |
|
|
130 | { |
|
|
131 | read_uuid (); |
|
|
132 | } |
54 | |
133 | |
55 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
134 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
56 | static int |
135 | static int |
57 | compare_ob_value_lists_one (const object *wants, const object *has) |
136 | compare_ob_value_lists_one (const object *wants, const object *has) |
58 | { |
137 | { |
… | |
… | |
887 | } |
966 | } |
888 | |
967 | |
889 | void object::unlink () |
968 | void object::unlink () |
890 | { |
969 | { |
891 | count = 0; |
970 | count = 0; |
|
|
971 | uuid = gen_uuid (); |
892 | |
972 | |
893 | if (this == objects) |
973 | if (this == objects) |
894 | objects = next; |
974 | objects = next; |
895 | |
975 | |
896 | /* Remove this object from the list of used objects */ |
976 | /* Remove this object from the list of used objects */ |