@cryptotaxi247 / kubo / commits / 8cca57244

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: Rob Deutsch <rdeutschob@gmail.com>

rob-deutsch committed Sep 20, 2018 at 17:53 UTC 8cca57244c2da0276af0f12574463c63ab428907
3 files changed +16 -14
cmd/ipfs/daemon.go
+5 -1
@@ -201,8 +201,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
201
202 managefd, _ := req.Options[adjustFDLimitKwd].(bool)
203 if managefd {
204 - if err := utilmain.ManageFdLimit(); err != nil {
204 + if changedFds, newFdsLimit, err := utilmain.ManageFdLimit(); err != nil {
205 log.Errorf("setting file descriptor limit: %s", err)
206 + } else {
207 + if changedFds {
208 + fmt.Printf("Successfully raised file descriptor limit to %d.\n", newFdsLimit)
209 + }
210 }
211 }
212
cmd/ipfs/util/ulimit.go
+8 -10
@@ -45,19 +45,19 @@ func setMaxFds() {
45
46 // ManageFdLimit raise the current max file descriptor count
47 // of the process based on the IPFS_FD_MAX value
48 -func ManageFdLimit() error {
48 +func ManageFdLimit() (changed bool, newLimit uint64, err error) {
49 if !supportsFDManagement {
50 - return nil
50 + return false, 0, nil
51 }
52
53 setMaxFds()
54 soft, hard, err := getLimit()
55 if err != nil {
56 - return err
56 + return false, 0, err
57 }
58
59 if maxFds <= soft {
60 - return nil
60 + return false, 0, nil
61 }
62
63 // the soft limit is the value that the kernel enforces for the
@@ -67,23 +67,21 @@ func ManageFdLimit() error {
67 // alue in the range from 0 up to the hard limit
68 if err = setLimit(maxFds, maxFds); err != nil {
69 if err != syscall.EPERM {
70 - return fmt.Errorf("error setting: ulimit: %s", err)
70 + return false, 0, fmt.Errorf("error setting: ulimit: %s", err)
71 }
72
73 // the process does not have permission so we should only
74 // set the soft value
75 if maxFds > hard {
76 - return errors.New(
76 + return false, 0, errors.New(
77 "cannot set rlimit, IPFS_FD_MAX is larger than the hard limit",
78 )
79 }
80
81 if err = setLimit(maxFds, hard); err != nil {
82 - return fmt.Errorf("error setting ulimit wihout hard limit: %s", err)
82 + return false, 0, fmt.Errorf("error setting ulimit wihout hard limit: %s", err)
83 }
84 }
85
86 - fmt.Printf("Successfully raised file descriptor limit to %d.\n", maxFds)
87 -
88 - return nil
86 + return true, maxFds, nil
87 }
cmd/ipfs/util/ulimit_test.go
+3 -3
@@ -12,7 +12,7 @@ import (
12
13 func TestManageFdLimit(t *testing.T) {
14 t.Log("Testing file descriptor count")
15 - if err := ManageFdLimit(); err != nil {
15 + if _, _, err := ManageFdLimit(); err != nil {
16 t.Errorf("Cannot manage file descriptors")
17 }
18
@@ -41,7 +41,7 @@ func TestManageInvalidNFds(t *testing.T) {
41 // call to check and set the maximum file descriptor from the env
42 setMaxFds()
43
44 - if err = ManageFdLimit(); err == nil {
44 + if _, _, err := ManageFdLimit(); err == nil {
45 t.Errorf("ManageFdLimit should return an error")
46 } else if err != nil {
47 flag := strings.Contains(err.Error(),
@@ -79,7 +79,7 @@ func TestManageFdLimitWithEnvSet(t *testing.T) {
79 t.Errorf("The maxfds is not set from IPFS_FD_MAX")
80 }
81
82 - if err = ManageFdLimit(); err != nil {
82 + if _, _, err = ManageFdLimit(); err != nil {
83 t.Errorf("Cannot manage file descriptor count")
84 }
85