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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.


(void) setlocale(LC_ALL, "");
(void) setlocale(LC_NUMERIC, "C");
Expand Down
1 change: 1 addition & 0 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ _LIBZUTIL_H int printf_color(const char *color, const char *format, ...);
_LIBZUTIL_H const char *zfs_basename(const char *path);
_LIBZUTIL_H ssize_t zfs_dirnamelen(const char *path);
#ifdef __linux__
extern char **environ;
_LIBZUTIL_H void zfs_setproctitle_init(int argc, char *argv[], char *envp[]);
_LIBZUTIL_H void zfs_setproctitle(const char *fmt, ...);
#else
Expand Down