| 124 | */ |
| 125 | |
| 126 | static void |
| 127 | pathTranslator_VirtualToReal(DmtcpEventData_t *data) |
| 128 | { |
| 129 | pathTranslator_Init(); |
| 130 | char *virtPath = data->virtualToRealPath.path; |
| 131 | |
| 132 | // Check to see if prefix of virtPath is present in pathMappings. |
| 133 | // This is O(n) in the number of mappings. We could make this faster by using |
| 134 | // a trie or a hash table. |
| 135 | // TODO (kapil): Investigate if we need to match the longest prefix instead of |
| 136 | // the first one. |
| 137 | for (const auto &mapping : *pathMapping) { |
| 138 | const string &oldp = mapping.first; |
| 139 | const string &newp = mapping.second; |
| 140 | if (Util::strStartsWith(virtPath, oldp.c_str())) { |
| 141 | // boundary check: next char must be '/' or end |
| 142 | char next = virtPath[oldp.size()]; |
| 143 | if (next == '/' || next == '\0') { |
| 144 | string suffix = &virtPath[oldp.size()]; |
| 145 | int n = snprintf(data->virtualToRealPath.path, |
| 146 | PATH_MAX, |
| 147 | "%s%s", |
| 148 | newp.c_str(), |
| 149 | suffix.c_str()); |
| 150 | JASSERT(n > 0 && n < PATH_MAX).Text("Translated path exceeds PATH_MAX"); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | pathTranslator_EventHook(DmtcpEvent_t event, DmtcpEventData_t *data) |
no test coverage detected