summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/config.c b/config.c
new file mode 100644
index 0000000..1f209c6
--- /dev/null
+++ b/config.c
@@ -0,0 +1,61 @@
+#include "config.h"
+
+void get_help() {
+ puts("Usage: \n\
+ -d, --dead Print list of dead file descriptors (deleted but still open)\n\
+ -i, --inodes Print list of inode file descriptors\n\
+ -l, --live Print list of live file descriptors (open and existing)\n\
+ -p, --pipes Print list of pipe file descriptors\n\
+ -s, --sockets Print list of socket file descriptors\n\
+\n\
+ -n, --no-stats Hide file descriptor statistics\n\
+ -sf, --sizefd Show total size of dead and live file descriptors\n\
+ -sd, --sizedead Show total size of dead file descriptors\n\
+ -sl, --sizelive Show total size of live file descriptors\n\
+ --truncate-dead Truncate dead file descriptors\n\
+ -h, --help Print this help text\n\
+");
+}
+
+int config_from_argv(struct config* c, int argc, char* argv[]) {
+ int i = 1;
+ while(i < argc) {
+ if(strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--dead") == 0) {
+ c->dead = 1;
+ } else if(strcmp(argv[i], "--truncate-dead") == 0) {
+ c->truncate_dead = 1;
+ } else if(strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--live") == 0) {
+ c->live = 1;
+ } else if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--sockets") == 0) {
+ c->sockets = 1;
+ } else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--inodes") == 0) {
+ c->inodes = 1;
+ } else if(strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--pipes") == 0) {
+ c->pipes = 1;
+ } else if(strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--no-stats") == 0) {
+ c->showstats = 0;
+ } else if(strcmp(argv[i], "-sfd") == 0 || strcmp(argv[i], "--sizefd") == 0) {
+ c->showsizefd = 1;
+ } else if(strcmp(argv[i], "-sd") == 0 || strcmp(argv[i], "--sizedead") == 0) {
+ c->showsizedead = 1;
+ } else if(strcmp(argv[i], "-sl") == 0 || strcmp(argv[i], "--sizelive") == 0) {
+ c->showsizelive = 1;
+ } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
+ get_help();
+ return 1;
+ } else if(argv[i][0] == '-') {
+ fprintf(stderr, "Unknown argument \"%s\"\n", argv[i]);
+ return 1;
+ } else {
+ c->pid = strtol(argv[i], NULL, 10);
+ }
+
+ i++;
+ }
+
+ if(c->pid == -1) {
+ fprintf(stderr, "Must specify valid pid\n");
+ return 2;
+ }
+ return 0;
+}

Generated by cgit