On 31/10/13 07:03, Nathan Hintz wrote:

Signed-off-by: Nathan Hintz<nlhi...@hotmail.com>
---

Hi,

please use getopt when handling more than 1 argument

        John




  block.c | 19 +++++++++++++------
  1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index 2289b77..2ef33e8 100644
--- a/block.c
+++ b/block.c
@@ -1038,8 +1038,8 @@ static int main_info(int argc, char **argv)

  static int main_swapon(int argc, char **argv)
  {
-       if (argc != 2) {
-               fprintf(stderr, "Usage: swapon<-s>  <-a>  [DEVICE]\n\n\tStart 
swapping on [DEVICE]\n -a\tStart swapping on all swap devices\n -s\tShow summary\n");
+       if (argc != 2&&  argc != 4) {
+               fprintf(stderr, "Usage: swapon<-s>  <-a>  <-p pri>  
[DEVICE]\n\n\tStart swapping on [DEVICE]\n -a\tStart swapping on all swap devices\n -p pri\tSet priority of 
swap device\n -s\tShow summary\n");
                return -1;
        }

@@ -1070,14 +1070,21 @@ static int main_swapon(int argc, char **argv)
        } else {
                struct stat s;
                int err;
+               int prio = 0;
+               int dev_arg = 1;

-               if (stat(argv[1],&s) || (!S_ISBLK(s.st_mode)&&  
!S_ISREG(s.st_mode))) {
-                       fprintf(stderr, "%s is not a block device or file\n", 
argv[1]);
+               if (!strcmp(argv[1], "-p")) {
+                       prio = ((atoi(argv[2])<<  SWAP_FLAG_PRIO_SHIFT)&  
SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER;
+                       dev_arg = 3;
+               }
+
+               if (stat(argv[dev_arg],&s) || (!S_ISBLK(s.st_mode)&&  
!S_ISREG(s.st_mode))) {
+                       fprintf(stderr, "%s is not a block device or file\n", 
argv[dev_arg]);
                        return -1;
                }
-               err = swapon(argv[1], 0);
+               err = swapon(argv[dev_arg], prio);
                if (err) {
-                       fprintf(stderr, "failed to swapon %s (%d)\n", argv[1], 
err);
+                       fprintf(stderr, "failed to swapon %s (%d)\n", 
argv[dev_arg], err);
                        return err;
                }
        }
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to