Deal with limits properly.

Don't print strerror() 2ice.
XXX: pullup-7
This commit is contained in:
christos 2015-06-19 17:33:20 +00:00
parent be0200b5b7
commit a73bc7adc9
1 changed files with 24 additions and 14 deletions

View File

@ -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 @@ perfuse_next_unique(struct puffs_usermount *pu)
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 @@ perfuse_init(struct perfuse_callbacks *pc, struct perfuse_mount_info *pmi)
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;