]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
mount.nfs - make sure program name in error message is correct.
authorNeil Brown <neilb@suse.de>
Tue, 20 Mar 2007 01:53:32 +0000 (12:53 +1100)
committerNeil Brown <neilb@suse.de>
Tue, 20 Mar 2007 01:53:32 +0000 (12:53 +1100)
getopt_long uses argv[0] in error messages.  So it it is given
argv+2 for example, we need to make sure that argv[2] has the
correct program name.

utils/mount/mount.c
utils/mount/nfsumount.c

index 71a87375868322c3dacebf86f92b5a0cad16adb5..9ae66f070503dc9db3b6a3107f983ef34a1fb546 100644 (file)
@@ -350,6 +350,7 @@ int main(int argc, char *argv[])
        spec = argv[1];
        mount_point = argv[2];
 
        spec = argv[1];
        mount_point = argv[2];
 
+       argv[2] = argv[0]; /* so that getopt error messages are correct */
        while ((c = getopt_long (argc - 2, argv + 2, "rt:vVwfno:hs",
                                longopts, NULL)) != -1) {
                switch (c) {
        while ((c = getopt_long (argc - 2, argv + 2, "rt:vVwfno:hs",
                                longopts, NULL)) != -1) {
                switch (c) {
@@ -448,7 +449,7 @@ int main(int argc, char *argv[])
        if (mount_point == NULL ||
            mount_point[0] != '/') {
                fprintf(stderr, "%s: unknown mount point %s\n",
        if (mount_point == NULL ||
            mount_point[0] != '/') {
                fprintf(stderr, "%s: unknown mount point %s\n",
-                       progname, argv[2]);
+                       progname, mount_point ? : "");
                exit(1);
        }
        
                exit(1);
        }
        
index e101105268d3bdd9bd42a49ca3649b3b17250383..81d0d3a72c4ea5ca1a1230e3991b33fc38f38164 100644 (file)
@@ -288,6 +288,7 @@ int nfsumount(int argc, char *argv[])
        argv += 1;
        argc -= 1;
 
        argv += 1;
        argc -= 1;
 
+       argv[0] = argv[-1]; /* So that getopt error messages are correct */
        while ((c = getopt_long (argc, argv, "fvnrlh",
                                umount_longopts, NULL)) != -1) {
 
        while ((c = getopt_long (argc, argv, "fvnrlh",
                                umount_longopts, NULL)) != -1) {