From b51f45ffb97ce4b4c43ffd2bae0d92f55fbf01a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Mon, 7 Dec 2020 10:49:57 +0100
Subject: [PATCH 6/6] pkg/runtime: support for AIX

---
 pkg/runtime/fds_aix.go   | 38 ++++++++++++++++++++++++++++++++++++++
 pkg/runtime/fds_other.go |  2 +-
 2 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 pkg/runtime/fds_aix.go

diff --git a/pkg/runtime/fds_aix.go b/pkg/runtime/fds_aix.go
new file mode 100644
index 0000000..3fbeae3
--- /dev/null
+++ b/pkg/runtime/fds_aix.go
@@ -0,0 +1,38 @@
+// Copyright 2015 The etcd Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package runtime implements utility functions for runtime systems.
+package runtime
+
+import (
+	"fmt"
+	"io/ioutil"
+	"syscall"
+)
+
+func FDLimit() (uint64, error) {
+	var rlimit syscall.Rlimit
+	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
+		return 0, err
+	}
+	return rlimit.Cur, nil
+}
+
+func FDUsage() (uint64, error) {
+	fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", syscall.Getpid()))
+	if err != nil {
+		return 0, err
+	}
+	return uint64(len(fds)), nil
+}
diff --git a/pkg/runtime/fds_other.go b/pkg/runtime/fds_other.go
index 0cbdb88..53cc955 100644
--- a/pkg/runtime/fds_other.go
+++ b/pkg/runtime/fds_other.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// +build !linux
+// +build !aix,!linux
 
 package runtime
 
-- 
2.25.0

