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

zfs_main.c: fix unused variable error with GCC #14441

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

rob-wing
Copy link
Contributor

Fix the following error when building with GCC on FreeBSD:

cmd/zfs/zfs_main.c: In function 'main':
cmd/zfs/zfs_main.c:8675:23: error: unused variable 'environ' [-Werror=unused-variable]
 8675 |         extern char **environ;
      |                       ^~~~~~~

Motivation and Context

Description

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

zfs_setproctitle_init() is stubbed out on FreeBSD.

Signed-off-by: Rob Wing <rob.fx907@gmail.com>
@behlendorf behlendorf requested a review from a user January 30, 2023 19:20
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jan 30, 2023
@behlendorf
Copy link
Contributor

behlendorf commented Jan 30, 2023

@ixhamza can you take a look at this.

@@ -8672,7 +8672,6 @@ main(int argc, char **argv)
int i = 0;
const char *cmdname;
char **newargv;
extern char **environ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me of aaa9a67. It is odd that people keep putting interesting declarations into main().

That said, I would prefer it if we followed the standard's recommendation here:

Applications should use the getenv() function rather than accessing the environment directly via either envp or environ.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/environ.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, glibc puts environ behind #ifdef __USE_GNU in unistd.h. However, it has a __environ that can be used without specifying __USE_GNU. That is something that the Linux Standard Base appears to have invented:

https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---environ.html

It is portable across both glibc and musl libc, but it is not portable to non-Linux systems. Both illumos-gate and FreeBSD do not support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand your suggestion, that would require factoring out the **environ out of the zfs_setproctitle_init() function signature - is that correct?

Then **environ would have to be exposed to lib/libzutil/os/linux/zutil_setproctitle.c` through some fashion?

Any ideas/preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misremembered what getenv() does. On second thought, lets just go with this PR as is.

@ghost ghost added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jan 31, 2023
@behlendorf behlendorf merged commit 326f1e3 into openzfs:master Feb 2, 2023
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 3, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes openzfs#14441
ixhamza pushed a commit to truenas/zfs that referenced this pull request Mar 26, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes openzfs#14441
ixhamza pushed a commit to truenas/zfs that referenced this pull request Mar 26, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes openzfs#14441
tonyhutter pushed a commit that referenced this pull request Mar 29, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes #14441
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Mar 29, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes openzfs#14441
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Apr 5, 2023
zfs_setproctitle_init() is stubbed out on FreeBSD.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Rob Wing <rob.fx907@gmail.com>
Closes openzfs#14441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants