summaryrefslogtreecommitdiff
path: root/config.c
blob: 1f209c614440c7ea59c51332a12f98201e531104 (plain)
    1 #include "config.h"
    2 
    3 void get_help() {
    4   puts("Usage: \n\
    5   -d, --dead       Print list of dead file descriptors (deleted but still open)\n\
    6   -i, --inodes     Print list of inode file descriptors\n\
    7   -l, --live       Print list of live file descriptors (open and existing)\n\
    8   -p, --pipes      Print list of pipe file descriptors\n\
    9   -s, --sockets    Print list of socket file descriptors\n\
   10 \n\
   11   -n, --no-stats   Hide file descriptor statistics\n\
   12   -sf, --sizefd    Show total size of dead and live file descriptors\n\
   13   -sd, --sizedead  Show total size of dead file descriptors\n\
   14   -sl, --sizelive  Show total size of live file descriptors\n\
   15   --truncate-dead  Truncate dead file descriptors\n\
   16   -h, --help       Print this help text\n\
   17 ");
   18 }
   19 
   20 int config_from_argv(struct config* c, int argc, char* argv[]) {
   21   int i = 1;
   22   while(i < argc) {
   23     if(strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--dead") == 0) {
   24       c->dead = 1;
   25     } else if(strcmp(argv[i], "--truncate-dead") == 0) {
   26       c->truncate_dead = 1;
   27     } else if(strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--live") == 0) {
   28       c->live = 1;
   29     } else if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--sockets") == 0) {
   30       c->sockets = 1;
   31     } else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--inodes") == 0) {
   32       c->inodes = 1;
   33     } else if(strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--pipes") == 0) {
   34       c->pipes = 1;
   35     } else if(strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--no-stats") == 0) {
   36       c->showstats = 0;
   37     } else if(strcmp(argv[i], "-sfd") == 0 || strcmp(argv[i], "--sizefd") == 0) {
   38       c->showsizefd = 1;
   39     } else if(strcmp(argv[i], "-sd") == 0 || strcmp(argv[i], "--sizedead") == 0) {
   40       c->showsizedead = 1;
   41     } else if(strcmp(argv[i], "-sl") == 0 || strcmp(argv[i], "--sizelive") == 0) {
   42       c->showsizelive = 1;
   43     } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
   44       get_help();
   45       return 1;
   46     } else if(argv[i][0] == '-') {
   47       fprintf(stderr, "Unknown argument \"%s\"\n", argv[i]);
   48       return 1;
   49     } else {
   50       c->pid = strtol(argv[i], NULL, 10);
   51     }
   52 
   53     i++;
   54   }
   55 
   56   if(c->pid == -1) {
   57     fprintf(stderr, "Must specify valid pid\n");
   58     return 2;
   59   }
   60   return 0;
   61 }

Generated by cgit