Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libperfuse Deal with limits properly.



details:   https://anonhg.NetBSD.org/src/rev/344b8b81da1f
branches:  trunk
changeset: 338960:344b8b81da1f
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jun 19 17:33:20 2015 +0000

description:
Deal with limits properly.
Don't print strerror() 2ice.
XXX: pullup-7

diffstat:

 lib/libperfuse/perfuse.c |  38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diffs (63 lines):

diff -r f641f473c1f6 -r 344b8b81da1f lib/libperfuse/perfuse.c
--- a/lib/libperfuse/perfuse.c  Fri Jun 19 17:20:02 2015 +0000
+++ b/lib/libperfuse/perfuse.c  Fri Jun 19 17:33:20 2015 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.36 2015/02/15 20:21:29 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.37 2015/06/19 17:33:20 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -391,6 +391,27 @@
        return ps->ps_unique++;
 } 
 
+static void
+updatelimit(const char *func, int lim, const char *name)
+{
+       struct rlimit rl;
+
+       /* Try infinity but that will fail unless we are root */
+       rl.rlim_cur = RLIM_INFINITY;
+       rl.rlim_max = RLIM_INFINITY;
+       if (setrlimit(lim, &rl) != -1)
+               return;
+
+       /* Get and set to the maximum allowed */
+       if (getrlimit(lim, &rl) == -1)
+               DERR(EX_OSERR, "%s: getrlimit %s failed", func, name);
+
+       rl.rlim_cur = rl.rlim_max;
+       if (setrlimit(lim, &rl) == -1)
+               DERR(EX_OSERR, "%s: setrlimit %s to %ju failed", func,
+                   name, (uintmax_t)rl.rlim_cur);
+}
+
 struct puffs_usermount *
 perfuse_init(struct perfuse_callbacks *pc, struct perfuse_mount_info *pmi)
 {
@@ -402,23 +423,12 @@
        unsigned int puffs_flags;
        struct puffs_node *pn_root;
        struct puffs_pathobj *po_root;
-       struct rlimit rl;
 
        /*
         * perfused can grow quite large, let assume there's enough ram ...
         */
-       rl.rlim_cur = RLIM_INFINITY;
-       rl.rlim_max = RLIM_INFINITY;
-
-       if (setrlimit(RLIMIT_DATA, &rl) < 0) {
-               DERR(EX_OSERR, "%s: setrlimit failed: %s", __func__,
-                   strerror(errno));
-       }
-
-       if (setrlimit(RLIMIT_AS, &rl) < 0) {
-               DERR(EX_OSERR, "%s: setrlimit failed: %s", __func__,
-                   strerror(errno));
-       }
+       updatelimit(__func__, RLIMIT_DATA, "RLIMIT_DATA");
+       updatelimit(__func__, RLIMIT_AS, "RLIMIT_AS");
 
        ps = init_state();
        ps->ps_owner_uid = pmi->pmi_uid;



Home | Main Index | Thread Index | Old Index