Commit 8cca5724 authored by rob-deutsch's avatar rob-deutsch

supressed fd util printing to output

Moved the fmt.Printf call from ManageFdLimit() to the calling code. ManageFdLimit() is called by tests and its annoying to have it output text

License: MIT
Signed-off-by: default avatarRob Deutsch <rdeutschob@gmail.com>
parent 182507d0
......@@ -201,8 +201,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
managefd, _ := req.Options[adjustFDLimitKwd].(bool)
if managefd {
if err := utilmain.ManageFdLimit(); err != nil {
if changedFds, newFdsLimit, err := utilmain.ManageFdLimit(); err != nil {
log.Errorf("setting file descriptor limit: %s", err)
} else {
if changedFds {
fmt.Printf("Successfully raised file descriptor limit to %d.\n", newFdsLimit)
}
}
}
......
......@@ -45,19 +45,19 @@ func setMaxFds() {
// ManageFdLimit raise the current max file descriptor count
// of the process based on the IPFS_FD_MAX value
func ManageFdLimit() error {
func ManageFdLimit() (changed bool, newLimit uint64, err error) {
if !supportsFDManagement {
return nil
return false, 0, nil
}
setMaxFds()
soft, hard, err := getLimit()
if err != nil {
return err
return false, 0, err
}
if maxFds <= soft {
return nil
return false, 0, nil
}
// the soft limit is the value that the kernel enforces for the
......@@ -67,23 +67,21 @@ func ManageFdLimit() error {
// alue in the range from 0 up to the hard limit
if err = setLimit(maxFds, maxFds); err != nil {
if err != syscall.EPERM {
return fmt.Errorf("error setting: ulimit: %s", err)
return false, 0, fmt.Errorf("error setting: ulimit: %s", err)
}
// the process does not have permission so we should only
// set the soft value
if maxFds > hard {
return errors.New(
return false, 0, errors.New(
"cannot set rlimit, IPFS_FD_MAX is larger than the hard limit",
)
}
if err = setLimit(maxFds, hard); err != nil {
return fmt.Errorf("error setting ulimit wihout hard limit: %s", err)
return false, 0, fmt.Errorf("error setting ulimit wihout hard limit: %s", err)
}
}
fmt.Printf("Successfully raised file descriptor limit to %d.\n", maxFds)
return nil
return true, maxFds, nil
}
......@@ -12,7 +12,7 @@ import (
func TestManageFdLimit(t *testing.T) {
t.Log("Testing file descriptor count")
if err := ManageFdLimit(); err != nil {
if _, _, err := ManageFdLimit(); err != nil {
t.Errorf("Cannot manage file descriptors")
}
......@@ -41,7 +41,7 @@ func TestManageInvalidNFds(t *testing.T) {
// call to check and set the maximum file descriptor from the env
setMaxFds()
if err = ManageFdLimit(); err == nil {
if _, _, err := ManageFdLimit(); err == nil {
t.Errorf("ManageFdLimit should return an error")
} else if err != nil {
flag := strings.Contains(err.Error(),
......@@ -79,7 +79,7 @@ func TestManageFdLimitWithEnvSet(t *testing.T) {
t.Errorf("The maxfds is not set from IPFS_FD_MAX")
}
if err = ManageFdLimit(); err != nil {
if _, _, err = ManageFdLimit(); err != nil {
t.Errorf("Cannot manage file descriptor count")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment