diff options
-rw-r--r-- | main.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -30,6 +30,7 @@ struct config { char inodes; char pipes; char showstats; + char truncate_dead; }; int fexists(char* path) { @@ -42,31 +43,35 @@ int fexists(char* path) { 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\ + -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\ - -h, --help Print this help text\n\ + -n, --no-stats Hide file descriptor statistics\n\ + --truncate-dead Truncate dead file descriptors\n\ + -h, --help Print this help text\n\ "); } int parse_args(int argc, char* argv[], struct config* c) { // Initialize config struct - c->pid = -1; - c->dead = 0; - c->live = 0; - c->sockets = 0; - c->pipes = 0; - c->inodes = 0; - c->showstats = 1; + c->pid = -1; + c->dead = 0; + c->truncate_dead = 0; + c->live = 0; + c->sockets = 0; + c->pipes = 0; + c->inodes = 0; + c->showstats = 1; 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) { @@ -102,7 +107,7 @@ int main(int argc, char* argv[]) { char lnpath[512] = {'\0'}; int retval = 0; int len = 0; - unsigned long unknown = 0; + unsigned long unknown = 0; unsigned long dead = 0; unsigned long live = 0; unsigned long sockets = 0; @@ -163,6 +168,8 @@ int main(int argc, char* argv[]) { dead++; if(c.dead) printf("%s -> %s\n", fdpath, lnpath); + if(c.truncate_dead) + truncate(fdpath, 0); } // Inodes |