Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang: Fix file_exists_and_ownedby return value #4935

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

luochenglcs
Copy link
Contributor

commit 008ea09 (clang: check header ownership) updates file_exists() to file_exists_and_ownedby(), add verifies onwer, but the return value is different from before, causing problems with the original code.

After commit 008ea09 (clang: check header ownership), /usr/share/bcc/examples/hello_world.py --help output is different: (left: old | right: new)
image

Because commit 008ea09 changed the return value:
Old: If file exists, file_exists() return 1;

static inline int file_exists(const char *f)
{
  struct stat buffer;
  return (stat(f, &buffer) == 0);  //ret = stat(f, &buffer) == 0
}

New: If file exists, file_exists_and_ownedby() return 0;

static inline int file_exists_and_ownedby(const char *f, uid_t uid)
{
  struct stat buffer;
  int ret;
  if ((ret = stat(f, &buffer)) == 0) {   //ret = stat(f, &buffer)) 
    if (buffer.st_uid != uid) {
      std::cout << "ERROR: header file ownership unexpected: " << std::string(f) << "\n";
      return -1;
    }
  }
  return ret;
}

commit 008ea09 (clang: check header ownership) updates file_exists()
to file_exists_and_ownedby(), add verifies onwer, but the return value
is different from before, causing problems with the original code.

Signed-off-by: Chunsheng Luo <[email protected]>
@luochenglcs
Copy link
Contributor Author

@brendangregg Please check.

@yonghong-song yonghong-song merged commit c00d69c into iovisor:master Mar 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants