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

error: cannot take the address of an rvalue of type 'FILE *' when building on OpenBSD #4145

Closed
williamleuschner opened this issue Sep 10, 2018 · 5 comments · Fixed by #4149
Closed
Labels

Comments

@williamleuschner
Copy link

On line 137 of log.c (and a few lines after that), netdata tries to get the address of stdout and co., which is a compilation error on OpenBSD (see issue title), and is not technically within C specifications.

I have some experience developing in C and could probably put a patch together which uses freopen(3), as suggested by the musl developer in the mailing list link above. Should I investigate patching it myself, or is this a trivial enough change that you'd rather just do it yourself?

@ktsaou
Copy link
Member

ktsaou commented Sep 10, 2018

Hi, could you please test PR #4149 ?

@ktsaou
Copy link
Member

ktsaou commented Sep 10, 2018

btw, it works on Linux, and it does not get the address of FILE * anymore.

@ktsaou
Copy link
Member

ktsaou commented Sep 10, 2018

Well, it turns out it does not work on a few versions of gcc/Linux:

log.c: In function 'reopen_all_log_files':
log.c:142:16: error: assignment of read-only variable 'stdout'
         stdout = open_log_file(STDOUT_FILENO, stdout, stdout_filename, &output_log_syslog, 0, NULL);
                ^
log.c:145:16: error: assignment of read-only variable 'stderr'
         stderr = open_log_file(STDERR_FILENO, stderr, stderr_filename, &error_log_syslog, 0, NULL);
                ^
log.c: In function 'open_all_log_files':
log.c:153:11: error: assignment of read-only variable 'stdin'
     stdin = open_log_file(STDIN_FILENO, stdin, "/dev/null", NULL, 0, NULL);
           ^
log.c:155:12: error: assignment of read-only variable 'stdout'
     stdout = open_log_file(STDOUT_FILENO, stdout, stdout_filename, &output_log_syslog, 0, NULL);
            ^
log.c:156:12: error: assignment of read-only variable 'stderr'
     stderr = open_log_file(STDERR_FILENO, stderr, stderr_filename, &error_log_syslog, 0, NULL);
            ^

So, even the freopen() method is not valid.

@ktsaou
Copy link
Member

ktsaou commented Sep 10, 2018

If you check the code, it attempts to change the level-1 file (fd) and use dup2() to copy the new file descriptor to the location required by stdXXX (so 1 for stdin, 2 for stdout, 3 for stderr). This way it manages to reopen the file without changing stdXXX.

The whole point for passing the address of FILE * was only for stdaccess (the access.log of netdata).
So I updated the code to prevent it from attempting to set stdXXX, except stdaccess.

@williamleuschner
Copy link
Author

Thanks! The patch from PR #4149 makes log.c build successfully. Next up, threads.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants