Patch for argument parsing below.

Diff taken in relation to Revision 3 of the aforementioned patch.

I do not understand why this should be a separate diff for this, as it
is essentially part of the functionality itself.

Let me know if you want it all together.



--- mount_tmpfs.c       Fri Sep 19 12:04:50 2014
+++ mount_tmpfs.c       Fri Sep 19 12:14:21 2014
@@ -88,7 +88,7 @@
 void
 mount_tmpfs_parseargs(int argc, char *argv[],
        struct tmpfs_args *args, int *mntflags,
-       char *canon_dev, char *canon_dir)
+       char *template, char *canon_dir)
 {
        int gidset, modeset, uidset; /* Ought to be 'bool'. */
        int ch;
@@ -110,7 +110,7 @@
        modeset = 0; mode = 0;
 
        optind = optreset = 1;
-       while ((ch = getopt(argc, argv, "g:m:n:o:s:u:")) != -1 ) {
+       while ((ch = getopt(argc, argv, "g:m:n:o:s:u:P:")) != -1 ) {
                switch (ch) {
                case 'g':
                        gid = a_gid(optarg);
@@ -145,6 +145,12 @@
                        uid = a_uid(optarg);
                        uidset = 1;
                        break;
+               
+               case 'P':
+                       if(strlcpy(template, optarg, MAXPATHLEN)
+                               >= MAXPATHLEN)
+                               errx(1, "template path %s too long",
optarg);
+                       break;
 
                case '?':
                default:
@@ -157,7 +163,6 @@
        if (argc != 2)
                usage();
 
-       strlcpy(canon_dev, argv[0], MAXPATHLEN);
        pathadj(argv[1], canon_dir);
 
        if (stat(canon_dir, &sb) == -1)
@@ -176,7 +181,7 @@
        extern char *__progname;
        (void)fprintf(stderr,
            "usage: %s [-g group] [-m mode] [-n nodes] [-o options]
[-s size]\n"
-           "           [-u user] tmpfs mount_point\n", __progname);
+           "           [-u user] [-P template] tmpfs mount_point\n",
__progname); exit(1);
 }
 
@@ -186,12 +191,12 @@
 mount_tmpfs(int argc, char *argv[])
 {
        struct tmpfs_args args;
-       char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
+       char canon_dir[MAXPATHLEN] = {'\0'};
        char template[MAXPATHLEN] = {'\0'};
        int mntflags, rdonly;
 
        mount_tmpfs_parseargs(argc, argv, &args, &mntflags,
-           canon_dev, canon_dir);
+           template, canon_dir);
 
        rdonly = mntflags & MNT_RDONLY;
 

Reply via email to