/** * Fd-enum is a simple tool to list open file descriptors of a pid by type * Copyright (C) 2023 Aaron Ball * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #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; }