More autofs cleanup
Subsystems (3)
PATCH 1/1 More autofs cleanup
Hello list,
Finally built and semi-figured-out git. A few more wrinkles ironed out in this patch.
A walkthrough, in order:
Makefile:
* Invoke autoheader in the configure target, 'cause it sure as heck hasn't been run in a while :-)
(You might want to update config.h.in, given that it uses an #ident directive that gcc complains about in pedantic mode)
Makefile.conf.in:
* Added a dummy @substitution@ for datarootdir, so that config.status doesn't print a warning at the end of a configure script run.
configure.in:
* Autoconf (or was it autoheader?) really wants you to use the three-argument form of AC_DEFINE().
daemon/indirect.c, daemon/lookup.c:
* Removed random redundant variable declarations.
include/automount.h:
* From the way it's used, shouldn't the status field be a time_t? This gets rid of some signed-vs-unsigned comparisons, at the very least.
* Don't use a generic local variable name like "status" in a macro definition. (This was shadowing local "status" variables in numerous places.)
include/state.h, lib/alarm.c:
* Same deal with "status" local variable inside a macro definition.
lib/parse_subs.c:
* Got a signed-vs-unsigned comparison warning here. Is it kosher to use __SWORD_TYPE? I don't know if "struct statfs" is officially supposed to use more formal type names for its fields.
modules/lookup_file.c, modules/parse_hesiod.c:
* Signed-vs-unsigned comparison fixes.
modules/lookup_hosts.c:
* The rpcgen-generated mount.h actually typedefs a "name" type. This makes the compiler look askance at subsequent, innocuous uses of variables named "name", so shove aside the typedef with a temporary #define.
* Fixed more weirdness of using sprintf()'s return value.
modules/parse_sun.c:
* The function already has a local variable "ent", of "const char *" type. I renamed this one to "xent", but you might have a better name for it.
That takes care of pretty much all the warnings that can be addressed without annoyingly invasive modifications (assuming you'd want to address them at all). Here is what remains, with commentary:
294 warning: ISO C does not permit named variadic macros 174 warning: ISO C99 requires rest arguments to be used
(Well, what can you do?)
22 warning: cast discards qualifiers from pointer target type
(This seems to be done deliberately, so no prob)
11 warning: ISO C forbids conversion of object pointer to function pointer type
(You have no choice when you're using dlsym()!)
5 warning: shadowed declaration is here
5 warning: declaration of ‘_buffer’ shadows a previous local
(From nested instances of pthread_cleanup_push())
4 warning: comma at end of enumerator list
1 warning: negative integer implicitly converted to unsigned type
(rpcgen wackiness)
1 warning: comparison between signed and unsigned
(In Flex-generated code for nss_tok.l)
--Daniel
Signature · 6 lines
NAME = Daniel Richard G. ## Remember, skunks _\|/_ meef? EMAIL1 = [email protected] ## don't smell bad--- (/o|o\) / EMAIL2 = [email protected] ## it's the people who < (^),> WWW = http://www.******.org/ ## annoy them that do! / \ -- (****** = site not yet online)
.autofs-5.0.1-rc1 +0 -0
Makefile +1 -0
@@ -52,6 +52,7 @@ backup: mrproper configure: configure.in aclocal.m4 autoconf + autoheader rm -rf config.* *.cache configure.in: .version
Makefile.conf.in +2 -0
@@ -80,3 +80,5 @@ mandir = @mandir@ # Location for init.d files initdir = @initdir@ +# This is here just to keep config.status quiet +UNUSED_datarootdir = @datarootdir@
configure.in +3 -3
@@ -276,7 +276,7 @@ AC_ARG_ENABLE(mount-locking, [ --disable-mount-locking disable use of locking when spawning mount command],, enableval=yes) if test x$enable_mount_locking = xyes -o x$enableval = xyes; then - AC_DEFINE(ENABLE_MOUNT_LOCKING, 1) + AC_DEFINE(ENABLE_MOUNT_LOCKING, 1, [Disable use of locking when spawning mount command]) fi #
@@ -287,7 +287,7 @@ AC_ARG_ENABLE(forced-shutdown, busy mounts during shutdown],, enableval=no) if test x$enable_forced_shutdown = xyes -o x$enableval = xyes; then - AC_DEFINE(ENABLE_FORCED_SHUTDOWN, 1) + AC_DEFINE(ENABLE_FORCED_SHUTDOWN, 1, [Enable forced shutdown on USR1 signal]) fi #
@@ -298,7 +298,7 @@ AC_ARG_ENABLE(ignore-busy, shutdown],, enableval=no) if test x$enable_ignore_busy_mounts = xyes -o x$enableval = xyes; then - AC_DEFINE(ENABLE_IGNORE_BUSY_MOUNTS, 1) + AC_DEFINE(ENABLE_IGNORE_BUSY_MOUNTS, 1, [Enable exit, ignoring busy mounts]) fi #
daemon/indirect.c +0 -1
@@ -436,7 +436,6 @@ void *expire_proc_indirect(void *arg) mnts =get_mnt_list (_PROC_MOUNTS, ap->path,0 );for (next = mnts; next; next = next->next) {char *ind_key; -int ret;if (!strcmp (next->fs_type,"autofs" ))continue ;
daemon/lookup.c +0 -2
@@ -786,8 +786,6 @@ int lookup_nss_mount(struct autofs_point head = &nsslist;list_for_each (p, head) { -enum nsswitch_status status; - this = list_entry(p, struct nss_source, list); result =lookup_map_name (this, ap, map, name, name_len);
include/automount.h +13 -13
@@ -148,7 +148,7 @@ struct mapent {char *mapent;time_t age;/* Time of last mount fail */ -unsigned int status; +time_t status;/* For direct mounts per entry context is kept here */ int dir_created;/* File descriptor for ioctls */
@@ -479,30 +479,30 @@ int count_mounts(struct autofs_point *ap#define state_mutex_lock (ap) \ do { \ - int status = pthread_mutex_lock(&ap->state_mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_lock(&ap->state_mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while(0)#define state_mutex_unlock (ap) \ do{ \ - int status = pthread_mutex_unlock(&ap->state_mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_unlock(&ap->state_mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)#define mounts_mutex_lock (ap) \ do { \ - int status = pthread_mutex_lock(&ap->mounts_mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_lock(&ap->mounts_mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)#define mounts_mutex_unlock (ap) \ do { \ - int status = pthread_mutex_unlock(&ap->mounts_mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_unlock(&ap->mounts_mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while(0)/* Expire alarm handling routines */
include/state.h +6 -6
@@ -91,16 +91,16 @@ int st_start_handler(void);#define st_mutex_lock () \ do { \ - int status = pthread_mutex_lock(&mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_lock(&mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)#define st_mutex_unlock () \ do { \ - int status = pthread_mutex_unlock(&mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_unlock(&mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)#endif
lib/alarm.c +6 -6
@@ -28,16 +28,16 @@ static LIST_HEAD(alarms);#define alarm_lock () \ do { \ - int status = pthread_mutex_lock(&mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_lock(&mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)#define alarm_unlock () \ do { \ - int status = pthread_mutex_unlock(&mutex); \ - if (status) \ - fatal(status); \ + int _mtx_status = pthread_mutex_unlock(&mutex); \ + if (_mtx_status) \ + fatal(_mtx_status); \ } while (0)void dump_alarms (void )
lib/parse_subs.c +2 -2
@@ -284,8 +284,8 @@ int umount_ent(struct autofs_point *ap,warn (ap->logopt,"could not stat fs of %s" , path); is_smbfs =0 ; }else { -int cifsfs = fs.f_type ==CIFS_MAGIC_NUMBER ; -int smbfs = fs.f_type ==SMB_SUPER_MAGIC ; +int cifsfs = fs.f_type == (__SWORD_TYPE )CIFS_MAGIC_NUMBER ; +int smbfs = fs.f_type == (__SWORD_TYPE )SMB_SUPER_MAGIC ; is_smbfs = (cifsfs | smbfs) ?1 :0 ; }
modules/lookup_file.c +1 -1
@@ -781,7 +781,7 @@ static int lookup_one(struct autofs_poinif (!s_key)continue ; -if (key_len !=strlen (s_key)) { +if (key_len != (int )strlen (s_key)) {free (s_key);continue ; }
modules/lookup_hosts.c +5 -3
@@ -21,7 +21,9 @@ #include <sys/types.h>#include <sys/stat.h> #include <netdb.h> +#define name __xdr_name#include "mount.h" +#undef name#define MODULE_LOOKUP #include "automount.h"
@@ -170,10 +172,10 @@ int lookup_mount(struct autofs_point *ap*/ if (*name =='/' ) {pthread_cleanup_push (cache_lock_cleanup, mc); - mapent =alloca (strlen (me->mapent) +1 ); - mapent_len =sprintf (mapent, me->mapent); + mapent_len =strlen (me->mapent); + mapent =alloca (mapent_len +1 ); +strcpy (mapent, me->mapent);pthread_cleanup_pop (0 ); - mapent[mapent_len] ='\0' ; } done:cache_unlock (mc);
modules/parse_hesiod.c +1 -1
@@ -106,7 +106,7 @@ static int parse_nfs(struct autofs_point p++;/* Isolate the remote mountpoint for this NFS fs. */ -for (i =0 ; (!isspace (p[i]) && i <sizeof (mount)); i++) { +for (i =0 ; (!isspace (p[i]) && i < (int )sizeof (mount)); i++) { mount[i] = p[i]; }
modules/parse_sun.c +10 -10
@@ -755,7 +755,7 @@ static int parse_mapent(const char *ent, p =skipspace (p);while (*p && *p !='/' ) { -char *ent; +char *xent;/* Location can't begin with a '/' */ if (*p =='/' ) {
@@ -767,38 +767,38 @@ static int parse_mapent(const char *ent, } l =chunklen (p,check_colon (p)); - ent =dequote (p, l, logopt); -if (!ent) { + xent =dequote (p, l, logopt); +if (!xent) {warn (logopt,MODPREFIX "null location or out of memory" );free (myoptions);free (loc);return 0 ; } -if (!validate_location (ent)) { +if (!validate_location (xent)) {warn (logopt, -MODPREFIX "invalid location %s" , ent); -free (ent); +MODPREFIX "invalid location %s" , xent); +free (xent);free (myoptions);free (loc);return 0 ; } -debug (logopt,MODPREFIX "dequote(\"%.*s\") -> %s" , l, p, ent); +debug (logopt,MODPREFIX "dequote(\"%.*s\") -> %s" , l, p, xent); loc =realloc (loc,strlen (loc) + l +2 );if (!loc) {error (logopt,MODPREFIX "out of memory" ); -free (ent); +free (xent);free (myoptions);free (loc);return 0 ; }strcat (loc," " ); -strcat (loc, ent); +strcat (loc, xent); -free (ent); +free (xent); p += l; p =skipspace (p);
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerThanks Daniel.
A small point.
When you send patches could you send them in-line in the mail. It's much easier to deal with and keeps the flow of though going.
Quoted 6 lines · Daniel Richard G.
Hello list,
Finally built and semi-figured-out git. A few more wrinkles ironed out in this patch.
Quoted 6 lines
A walkthrough, in order:
Makefile:* Invoke autoheader in the configure target, 'cause it sure as heck hasn't been run in a while :-)
True.
Quoted 3 lines
(You might want to update config.h.in, given that it uses an #ident directive that gcc complains about in pedantic mode)
All the CVS identification will be removed when I get to it.
I'll need to put this to one side for a while and merge it by hand as stress testing autofs has exposed a number of more nasty problems that compiler warnings.
Just so we're on the same page, what CFLAGS are you using? I'm fairly lazy about compiler warnings most of the time. You wouldn't guess, would you.
Quoted 5 lines
Makefile.conf.in:
* Added a dummy @substitution@ for datarootdir, so that config.status doesn't print a warning at the end of a configure script run.
OK. I'll have a look at that.
Quoted 5 lines
configure.in:
* Autoconf (or was it autoheader?) really wants you to use the three-argument form of
AC_DEFINE().
Yep.
Quoted 4 lines
daemon/indirect.c,daemon/lookup.c:* Removed random redundant variable declarations.
There's more already.
Quoted 5 lines
include/automount.h:* From the way it's used, shouldn't the status field be a
time_t? This gets rid of some signed-vs-unsigned comparisons, at the very least.
Yes. I do need to spend time on the signed-vs-unsigned issues as they can cause unusual problems. I'll pay special attention to this soonish.
Quoted 4 lines
* Don't use a generic local variable name like "status" in a macro definition. (This was shadowing local "status" variables in numerous places.)
Did I say lazy!
Quoted 10 lines
include/state.h,lib/alarm.c:* Same deal with "status" local variable inside a macro definition.
lib/parse_subs.c:* Got a signed-vs-unsigned comparison warning here. Is it kosher to use
__SWORD_TYPE? I don't know if "struct statfs" is officially supposed to use more formal type names for its fields.
Me neither but I need it so I include it.
Quoted 10 lines
modules/lookup_file.c,modules/parse_hesiod.c:* Signed-vs-unsigned comparison fixes.
modules/lookup_hosts.c:* The rpcgen-generated
mount.hactually typedefs a "name" type. This makes the compiler look askance at subsequent, innocuous uses of variables named "name", so shove aside the typedef with a temporary #define.
That's been annoying me for a while now.
Quoted 7 lines
* Fixed more weirdness of using sprintf()'s return value.
modules/parse_sun.c:* The function already has a local variable "ent", of "const char *" type. I renamed this one to "xent", but you might have a better name for it.
Missed that.
Quoted 6 lines
That takes care of pretty much all the warnings that can be addressed without annoyingly invasive modifications (assuming you'd want to address them at all). Here is what remains, with commentary:
Quoted 8 lines
294 warning: ISO C does not permit named variadic macros 174 warning: ISO C99 requires rest arguments to be used
(Well, what can you do?)
22 warning: cast discards qualifiers from pointer target type
(This seems to be done deliberately, so no prob)
No sure I what to do about this.
I'd like to rationalize it sometime but I always break stuff when I try. There's more important issues to address at the moment.
Quoted 20 lines
11 warning: ISO C forbids conversion of object pointer to function pointer type
(You have no choice when you're using
dlsym()!)5 warning: shadowed declaration is here
5 warning: declaration of ‘_buffer’ shadows a previous local(From nested instances of
pthread_cleanup_push())4 warning: comma at end of enumerator list
1 warning: negative integer implicitly converted to unsigned type(rpcgen wackiness)
1 warning: comparison between signed and unsigned
(In Flex-generated code for nss_tok.l)
Quoted 7 lines
--Daniel
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Quoted 6 lines · Ian Kent
Thanks Daniel.
A small point.
When you send patches could you send them in-line in the mail. It's much easier to deal with and keeps the flow of though going.
Understood, will keep in mind.
Quoted 4 lines
Quoted 2 lines
(You might want to update config.h.in, given that it uses an #ident directive that gcc complains about in pedantic mode)
All the CVS identification will be removed when I get to it.
Here, it's just the old-autoheader-output problem. New versions of autoheader don't use #ident.
Quoted 3 lines
I'll need to put this to one side for a while and merge it by hand as stress testing autofs has exposed a number of more nasty problems that compiler warnings.
Oh, certainly. This is peripheral work, after all. (With the potential exception of it pointing out some odd bug, as last time.)
Quoted 3 lines
Just so we're on the same page, what CFLAGS are you using? I'm fairly lazy about compiler warnings most of the time. You wouldn't guess, would you.
Tsk tsk :-)
For development, I normally use
-O0 -g3 -ansi -pedantic -fno-common -pipe -W -Wall -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winline -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-parameter -Waggregate-return -Wnested-externs
For autofs, you have to drop -ansi (otherwise you don't get __u64, needed in auto_fs4.h), and -Wconversion generates more noise than it's worth.
I've attached the script I use to produce my warning summaries, in case you find it useful.
Quoted 6 lines
Quoted 4 lines
Makefile.conf.in:
* Added a dummy @substitution@ for datarootdir, so that config.status doesn't print a warning at the end of a configure script run.
OK. I'll have a look at that.
Another problem with the makefiles is that they assign CFLAGS from scratch, and allow the environment to override it, instead of having a line like
CFLAGS = @CFLAGS@
so that they pick up whatever was in the environment at configure time. This threw me off for a bit---it's definitely not the behavior one expects when a package uses autoconf.
Quoted 7 lines
Quoted 3 lines
22 warning: cast discards qualifiers from pointer target type
(This seems to be done deliberately, so no prob)
No sure I what to do about this.
I'd like to rationalize it sometime but I always break stuff when I try. There's more important issues to address at the moment.
Yeah, I get the impression some previous maintainer went a little const-happy and used it willy-nilly everywhere. Bad enough to see the code de-const-ing a pointer, then passing it to free()....
--Daniel
Signature · 6 lines
NAME = Daniel Richard G. ## Remember, skunks _\|/_ meef? EMAIL1 = [email protected] ## don't smell bad--- (/o|o\) / EMAIL2 = [email protected] ## it's the people who < (^),> WWW = http://www.******.org/ ## annoy them that do! / \ -- (****** = site not yet online)
#!/usr/bin/env perl
# warning-summary
use strict;
use warnings;
open(OUT, "| sort | uniq -c | sort -nr");
while (<>)
{
/warning:/ || next;
/\(near initialization for .*\)/ && next;
s/^.*: warning: //g;
s/\barg(ument|) \d+\b/arg$1 N/g;
s/\b(type|function|variable|enumeration value|declaration of|argument N of|type of) '[^']+'/$1 'blah'/g;
s/"[^"]+" (is not defined)/"BLAH" $1/g;
s/'[^']+' (defined but not used)/'blah' $1/g;
s/format '%\w+'/format '%blah'/g;
s/'\d+'/'NNN'/g;
s/'[^']+' (declared 'static' but never defined)/'blah' $1/g;
print OUT;
}close(OUT);
# end warning-summary
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 5 lines · Daniel Richard G.
Hello list,
Finally built and semi-figured-out git. A few more wrinkles ironed out in this patch.
Cogito!
==> Regarding [autofs] [PATCH] More autofs cleanup; "Daniel Richard G." <[email protected]> adds:
skunk> Hello list, Finally built and semi-figured-out git. A few more skunk> wrinkles ironed out in this patch.
skunk> modules/lookup_hosts.c:
skunk> * Fixed more weirdness of using sprintf()'s return value.
@@ -170,10 +172,10 @@ int lookup_mount(struct autofs_point *ap
*/
if (*name == '/') {
pthread_cleanup_push(cache_lock_cleanup, mc);
- mapent = alloca(strlen(me->mapent) + 1);
- mapent_len = sprintf(mapent, me->mapent);
+ mapent_len = strlen(me->mapent);
+ mapent = alloca(mapent_len + 1);
+ strcpy(mapent, me->mapent);
pthread_cleanup_pop(0);
- mapent[mapent_len] = '\0';
}
done:
cache_unlock(mc);
This is just a refactoring of code with no real gain. The previous usage was correct.
As Ian mentioned before, posting patches inline makes it easier to quote in the reply (at least for my arcane mailer. ;).
The rest up to this point looks pretty good to me. Thanks a bunch for doing this!
-Jeff
Quoted 12 lines · Jeff Moyer
modules/lookup_hosts.c +3
-3pthread_cleanup_push (cache_lock_cleanup, mc); - mapent =alloca (strlen (me->mapent) +1 ); - mapent_len =sprintf (mapent, me->mapent); + mapent_len =strlen (me->mapent); + mapent =alloca (mapent_len +1 ); +strcpy (mapent, me->mapent);pthread_cleanup_pop (0 ); - mapent[mapent_len] ='\0' ; } done:cache_unlock (mc);
Quoted 2 lines
This is just a refactoring of code with no real gain. The previous usage was correct.
Well, there were some problems with the previous code...
1. It passes a variable format string to sprintf()---the cause of the original warning, and a potential crash/security bug. (What happens if me->mapent contains instances of "%s"?)
2. It takes the length of me->mapent twice. (Not something I addressed, but if you're okay with it, you could change that strcpy() into a memcpy())
3. In general, it was less clear/straightforward than it could have been. There are times when it's useful to grab the return value of sprintf(), but here, it's pointless (and unsafe...)
Quoted 2 lines
As Ian mentioned before, posting patches inline makes it easier to quote in the reply (at least for my arcane mailer. ;).
Understood. My experience has been that things in the main body tend to get mangled, but here I see that's not a problem.
Quoted 2 lines
The rest up to this point looks pretty good to me. Thanks a bunch for doing this!
Sure thing :)
--Daniel
Signature · 6 lines
NAME = Daniel Richard G. ## Remember, skunks _\|/_ meef? EMAIL1 = [email protected] ## don't smell bad--- (/o|o\) / EMAIL2 = [email protected] ## it's the people who < (^),> WWW = http://www.******.org/ ## annoy them that do! / \ -- (****** = site not yet online)