]> Sergey Matveev's repositories - nnn.git/commitdiff
Maximize rlimit, switch to detail view in du mode
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 11 Apr 2017 04:47:50 +0000 (10:17 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 11 Apr 2017 14:52:30 +0000 (20:22 +0530)
Makefile
nnn.c

index 4800e8d485bede6c7bf2109ab5ad716d6212fa06..a1dcb6e04549fadbdf182c367395651e676f5f10 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VERSION = 0.6
 PREFIX = /usr/local
 MANPREFIX = $(PREFIX)/man
 
-CFLAGS += -O3 -march=native -Wall -Wextra
+CFLAGS += -O3 -march=native -Wall -Wextra -Wno-unused-parameter
 LDLIBS = -lcurses
 
 DISTFILES = nnn.c config.def.h nnn.1 Makefile README.md LICENSE
diff --git a/nnn.c b/nnn.c
index 78d159c1492c938cae3393b1b737c67d785ec916..9dc7afbc7133f50bd659e02f52b445b09ddcf0f4 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -3,6 +3,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/statvfs.h>
+#include <sys/resource.h>
 
 #include <curses.h>
 #include <dirent.h>
@@ -123,6 +124,7 @@ static char *fallback_opener;
 static char *copier;
 static off_t blk_size;
 static size_t fs_free;
+static int open_max;
 static const double div_2_pow_10 = 1.0 / 1024.0;
 static const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
 
@@ -167,6 +169,28 @@ xrealloc(void *p, size_t size)
 }
 #endif
 
+static rlim_t
+max_openfds()
+{
+       struct rlimit rl;
+        rlim_t limit;
+
+       limit = getrlimit(RLIMIT_NOFILE, &rl);
+       if (limit != 0)
+               return 32;
+
+       limit = rl.rlim_cur;
+       rl.rlim_cur = rl.rlim_max;
+
+       if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
+               return rl.rlim_max - 64;
+
+       if (limit > 128)
+               return limit - 64;
+
+       return 32;
+}
+
 static size_t
 xstrlcpy(char *dest, const char *src, size_t n)
 {
@@ -936,14 +960,11 @@ show_help(void)
 }
 
 static int
-sum_sizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
+sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
 {
-       if (!fpath || !ftwbuf)
-               printmsg("fpath or ftwbuf NULL"); /* TODO: on %s", fpath); */
-
        /* Handle permission problems */
        if(typeflag == FTW_NS) {
-               printmsg("No stats (permissions ?)"); /* TODO: on %s", fpath); */
+               printmsg("No stats (permissions ?)");
                return 0;
        }
 
@@ -1023,8 +1044,8 @@ dentfill(char *path, struct entry **dents,
 
        while ((dp = readdir(dirp)) != NULL) {
                /* Skip self and parent */
-               if ((dp->d_name[0] == '.' && dp->d_name[1] == '\0') ||
-                   (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
+               if ((dp->d_name[0] == '.' && (dp->d_name[1] == '\0' ||
+                   (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))))
                        continue;
                if (filter(re, dp->d_name) == 0)
                        continue;
@@ -1042,8 +1063,8 @@ dentfill(char *path, struct entry **dents,
                if (bsizeorder) {
                        if (S_ISDIR(sb.st_mode)) {
                                blk_size = 0;
-                               if (nftw(newpath, sum_sizes, 128, FTW_MOUNT | FTW_PHYS) == -1) {
-                                       printmsg("nftw(3) failed"); /* TODO: , newpath); */
+                               if (nftw(newpath, sum_bsizes, open_max, FTW_MOUNT | FTW_PHYS) == -1) {
+                                       printmsg("nftw(3) failed");
                                        (*dents)[n].bsize = sb.st_blocks;
                                } else
                                        (*dents)[n].bsize = blk_size;
@@ -1507,6 +1528,10 @@ nochange:
                        goto begin;
                case SEL_BSIZE:
                        bsizeorder = !bsizeorder;
+                       if (bsizeorder) {
+                               showdetail = 1;
+                               printptr = &printent_long;
+                       }
                        mtimeorder = 0;
                        sizeorder = 0;
                        /* Save current */
@@ -1619,6 +1644,8 @@ main(int argc, char *argv[])
                }
        }
 
+       open_max = max_openfds();
+
        if (getuid() == 0)
                showhidden = 1;
        initfilter(showhidden, &ifilter);