-Werror=unused-but-set-variable#1402
Conversation
d610a79 to
ddd475d
Compare
hallyn
left a comment
There was a problem hiding this comment.
Patch 2 could avoid adding any ifdefs by doing something like:
diff --git a/src/login.c b/src/login.c
index 6798bb1d..680653d1 100644
--- a/src/login.c
+++ b/src/login.c
@@ -64,6 +64,9 @@ static pam_handle_t *pamh = NULL;
#define PAM_END { retcode = pam_close_session(pamh,0); \
(void) pam_end(pamh,retcode); }
+#define mark_subroot() { subroot = true; }
+#else /* USE_PAM */
+#define mark_subroot() {}
#endif /* USE_PAM */
@@ -448,7 +451,6 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
int main (int argc, char **argv)
{
int err;
- bool subroot = false;
char **envp = environ;
char *host = NULL;
char tty[BUFSIZ];
@@ -464,6 +466,7 @@ int main (int argc, char **argv)
struct passwd *pwd = NULL;
#if defined(USE_PAM)
+ bool subroot = false;
int retcode;
char *pam_user = NULL;
pid_t child;
@@ -1018,7 +1021,7 @@ int main (int argc, char **argv)
if (strprefix(pwd->pw_shell, "*")) { /* subsystem root */
pwd->pw_shell++; /* skip the '*' */
subsystem (pwd); /* figure out what to execute */
- subroot = true; /* say I was here again */
+ mark_subroot(); /* say I was here again */
endpwent (); /* close all of the file which were */
endgrent (); /* open in the original rooted file */
endspent (); /* system. they will be re-opened */
Similarly in patch 3, it may be cleaner to define a noop set_selinux_file_context() in src/selinux.c in the !WITH_SELINUX case, and then just drop the #ifdef WITH_SELINUX from src/useradd.c:2218 and 2356.
I find macros that affect undeclared objects to be worse than ifdefs. And after all, you're still using an ifdef, just an existing one.
|
|
On Sat, Dec 06, 2025 at 03:41:16AM -0800, Alejandro Colomar wrote:
alejandro-colomar left a comment (shadow-maint/shadow#1402)
> Patch 2 could avoid adding any ifdefs by doing something like:
>
> ```
> diff --git a/src/login.c b/src/login.c
> index 6798bb1d..680653d1 100644
> --- a/src/login.c
> +++ b/src/login.c
> @@ -64,6 +64,9 @@ static pam_handle_t *pamh = NULL;
> #define PAM_END { retcode = pam_close_session(pamh,0); \
> (void) pam_end(pamh,retcode); }
>
> +#define mark_subroot() { subroot = true; }
I find macros that affect undeclared objects to be worse than ifdefs.
And after all, you're still using an ifdef, just an existing one.
If there were one ifdef, that might not sound so bad. But look at
that file! I'd like to rewrite the whole thing so a person can
actually follow the flow.
|
I'll have a look at simplifying that file further (in a separate PR). I'm seeing a few things I could get rid of. |
ddd475d to
deb5d8d
Compare
deb5d8d to
e4652d3
Compare
e4652d3 to
13253d9
Compare
13253d9 to
f752f33
Compare
f752f33 to
f010ba3
Compare
f010ba3 to
997b468
Compare
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This variable is only read if !USE_PAM. Writing to it unconditionally triggers -Werror=unused-but-set-variable errors. Let's wrap it in ifndef to avoid the error. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Writing to it unconditionally triggers -Werror=unused-but-set-variable, as it's only read if using selinux. Also add MAYBE_UNUSED to parameters that become maybe unused due to this change. Signed-off-by: Alejandro Colomar <alx@kernel.org>
997b468 to
fcd76be
Compare
Another one.
Revisions:
v1b
v1c
v1d
v1e
v1f
v1g
v1h