Revert "Replace strtok_r() with C++-style android::base::Tokenize()"

Revert submission 1890098

Reason for revert: Breaks tests, b/206740783
Reverted Changes:
I71190c735:Add ParseFstabFromString(), remove ReadFstabFromFp...
Ic1dd0eb97:Replace strtok_r() with C++-style android::base::T...

Change-Id: I1eecdc43d504385b00caec17db626eb1d623c8ef
This commit is contained in:
Martin Stjernholm 2021-11-17 15:51:01 +00:00
parent 62291bfd5c
commit 867916e8b5

View file

@ -526,11 +526,11 @@ bool EraseFstabEntry(Fstab* fstab, const std::string& mount_point) {
} // namespace
bool ReadFstabFromFp(FILE* fstab_file, bool proc_mounts, Fstab* fstab_out) {
const int expected_fields = proc_mounts ? 4 : 5;
ssize_t len;
size_t alloc_len = 0;
char *line = NULL;
char* p;
const char *delim = " \t";
char *save_ptr, *p;
Fstab fstab;
while ((len = getline(&line, &alloc_len, fstab_file)) != -1) {
@ -548,23 +548,42 @@ bool ReadFstabFromFp(FILE* fstab_file, bool proc_mounts, Fstab* fstab_out) {
if (*p == '#' || *p == '\0')
continue;
auto fields = android::base::Tokenize(line, " \t");
if (fields.size() < expected_fields) {
LERROR << "Error parsing fstab: expected " << expected_fields << " fields, got "
<< fields.size();
FstabEntry entry;
if (!(p = strtok_r(line, delim, &save_ptr))) {
LERROR << "Error parsing mount source";
goto err;
}
entry.blk_device = p;
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
LERROR << "Error parsing mount_point";
goto err;
}
entry.mount_point = p;
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
LERROR << "Error parsing fs_type";
goto err;
}
entry.fs_type = p;
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
LERROR << "Error parsing mount_flags";
goto err;
}
FstabEntry entry;
auto it = fields.begin();
entry.blk_device = std::move(*it++);
entry.mount_point = std::move(*it++);
entry.fs_type = std::move(*it++);
ParseMountFlags(std::move(*it++), &entry);
ParseMountFlags(p, &entry);
// For /proc/mounts, ignore everything after mnt_freq and mnt_passno
if (!proc_mounts && !ParseFsMgrFlags(std::move(*it++), &entry)) {
if (proc_mounts) {
p += strlen(p);
} else if (!(p = strtok_r(NULL, delim, &save_ptr))) {
LERROR << "Error parsing fs_mgr_options";
goto err;
}
if (!ParseFsMgrFlags(p, &entry)) {
LERROR << "Error parsing fs_mgr_flags";
goto err;
}