Skip to content

Commit

Permalink
remove "failure_is_okay" which was pointless
Browse files Browse the repository at this point in the history
  • Loading branch information
droundy committed Mar 19, 2017
1 parent b2e026f commit b1db2df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
6 changes: 3 additions & 3 deletions bigbro-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static int save_syscall_access(pid_t child, rw_status *h) {
}
char *rawpath = interpret_path_at(child, dirfd, arg);
free(arg);
char *abspath = flexible_realpath(rawpath, h, look_for_symlink, false);
char *abspath = flexible_realpath(rawpath, h, look_for_symlink);
delete_from_hashset(&h->read, abspath);
delete_from_hashset(&h->readdir, abspath);
delete_from_hashset(&h->written, abspath);
Expand Down Expand Up @@ -417,7 +417,7 @@ static int save_syscall_access(pid_t child, rw_status *h) {
if (arg) {
debugprintf("%d: %s('%s') -> %d\n", child, name, arg, retval);
char *rawpath = interpret_path_at(child, dirfd, arg);
char *abspath = flexible_realpath(rawpath, h, look_for_file_or_directory, false);
char *abspath = flexible_realpath(rawpath, h, look_for_file_or_directory);
insert_hashset(&h->mkdir, abspath);
free(rawpath);
free(abspath);
Expand Down Expand Up @@ -474,7 +474,7 @@ static int save_syscall_access(pid_t child, rw_status *h) {
}
if (from) {
char *rawpath = interpret_path_at(child, dirfd, from);
char *abspath = flexible_realpath(rawpath, h, look_for_symlink, false);
char *abspath = flexible_realpath(rawpath, h, look_for_symlink);
free(rawpath);
free(from);
from = abspath;
Expand Down
9 changes: 3 additions & 6 deletions fileaccesses.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ int main(int argc, char **argv) {
// the following are to test the corner and error cases of
// flexible_realpath.
#ifndef _WIN32
assert(! flexible_realpath(NULL, NULL,
look_for_file_or_directory, true));
assert(! flexible_realpath("", NULL,
look_for_file_or_directory, true));
assert(! flexible_realpath(NULL, NULL, look_for_file_or_directory));
assert(! flexible_realpath("", NULL, look_for_file_or_directory));
// the following should give null because flexible_realpath wants an
// absolute path.
assert(! flexible_realpath("tmp", NULL,
look_for_file_or_directory, true));
assert(! flexible_realpath("tmp", NULL, look_for_file_or_directory));
#endif

if (argc < 2) {
Expand Down
22 changes: 10 additions & 12 deletions linux-proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static inline char *interpret_path_at(pid_t pid, int fd, const char *path) {

static inline void read_dir_fd(pid_t pid, int dirfd, rw_status *h) {
char *rawpath = interpret_path_at(pid, dirfd, ".");
char *abspath = flexible_realpath(rawpath, h, look_for_file_or_directory, false);
char *abspath = flexible_realpath(rawpath, h, look_for_file_or_directory);
if (!lookup_in_hash(&h->mkdir, abspath)) {
insert_hashset(&h->readdir, abspath);
}
Expand All @@ -51,10 +51,9 @@ static inline void read_dir_fd(pid_t pid, int dirfd, rw_status *h) {
}

static inline void read_something_at(pid_t pid, int dirfd, const char *path,
rw_status *h, enum last_symlink_handling lh,
bool failure_is_okay) {
rw_status *h, enum last_symlink_handling lh) {
char *rawpath = interpret_path_at(pid, dirfd, path);
char *abspath = flexible_realpath(rawpath, h, lh, failure_is_okay);
char *abspath = flexible_realpath(rawpath, h, lh);
struct stat st;
if (!lookup_in_hash(&h->written, abspath) && !stat(abspath, &st) && S_ISREG(st.st_mode)) {
insert_hashset(&h->read, abspath);
Expand All @@ -64,10 +63,9 @@ static inline void read_something_at(pid_t pid, int dirfd, const char *path,
}

static inline void write_something_at(pid_t pid, int dirfd, const char *path,
rw_status *h, enum last_symlink_handling lh,
bool failure_is_okay) {
rw_status *h, enum last_symlink_handling lh) {
char *rawpath = interpret_path_at(pid, dirfd, path);
char *abspath = flexible_realpath(rawpath, h, lh, failure_is_okay);
char *abspath = flexible_realpath(rawpath, h, lh);
insert_hashset(&h->written, abspath);
delete_from_hashset(&h->read, abspath);
free(rawpath);
Expand All @@ -76,25 +74,25 @@ static inline void write_something_at(pid_t pid, int dirfd, const char *path,

static inline void read_file_at(pid_t pid, int dirfd, const char *path,
rw_status *h) {
read_something_at(pid, dirfd, path, h, look_for_file_or_directory, false);
read_something_at(pid, dirfd, path, h, look_for_file_or_directory);
}

static inline void maybe_read_file_at(pid_t pid, int dirfd, const char *path,
rw_status *h) {
read_something_at(pid, dirfd, path, h, look_for_file_or_directory, true);
read_something_at(pid, dirfd, path, h, look_for_file_or_directory);
}

static inline void write_file_at(pid_t pid, int dirfd, const char *path,
rw_status *h) {
write_something_at(pid, dirfd, path, h, look_for_file_or_directory, false);
write_something_at(pid, dirfd, path, h, look_for_file_or_directory);
}

static inline void read_link_at(pid_t pid, int dirfd, const char *path,
rw_status *h) {
read_something_at(pid, dirfd, path, h, look_for_symlink, false);
read_something_at(pid, dirfd, path, h, look_for_symlink);
}

static inline void write_link_at(pid_t pid, int dirfd, const char *path,
rw_status *h) {
write_something_at(pid, dirfd, path, h, look_for_symlink, false);
write_something_at(pid, dirfd, path, h, look_for_symlink);
}
6 changes: 1 addition & 5 deletions realpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ enum last_symlink_handling {

static inline char *flexible_realpath(const char *name,
rw_status *h,
enum last_symlink_handling lasth,
bool failure_is_okay) {
enum last_symlink_handling lasth) {
char *rpath; // rpath is where we hold the path as we have
// determined it so far
char *dest; // dest is the location for the next portion of the path
Expand Down Expand Up @@ -198,9 +197,6 @@ static inline char *flexible_realpath(const char *name,
}
} else if (!S_ISDIR(st.st_mode) && *end != '\0') {
errno = (ENOTDIR);
if (!failure_is_okay)
fprintf(stderr, "error: %s is not a dir (realpaht of %s, w/ end %s)\n",
rpath, name, end);
goto error;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/realpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main() {
else printf("parent '%s' is NOT a directory\n", parent);

char *actual_rp = realpath(buf, 0);
char *rp = flexible_realpath(buf, &st, look_for_file_or_directory, true);
char *rp = flexible_realpath(buf, &st, look_for_file_or_directory);
printf("input %s\n", buf);
printf("actual_rp %s\n", actual_rp);
printf("flexible_realpath look_for_file_or_directory true returns %s\n", rp);
Expand All @@ -89,7 +89,7 @@ int main() {
assert(actual_rp);
assert(!strcmp(rp, actual_rp));
}
char *symrp = flexible_realpath(buf, &st, look_for_symlink, true);
char *symrp = flexible_realpath(buf, &st, look_for_symlink);
if (*buf != '/') {
printf("relative paths count as failure...\n");
assert(!rp);
Expand Down

0 comments on commit b1db2df

Please sign in to comment.