]> Zhao Yanbai Git Server - minix.git/commitdiff
Implementation of getrlimit and getdtablesize
authorErik van der Kouwe <erik@minix3.org>
Mon, 7 Dec 2009 19:56:40 +0000 (19:56 +0000)
committerErik van der Kouwe <erik@minix3.org>
Mon, 7 Dec 2009 19:56:40 +0000 (19:56 +0000)
include/sys/resource.h
include/unistd.h
lib/other/Makefile.in
lib/other/rlimit.c [new file with mode: 0644]
man/man3/getdtablesize.3 [new file with mode: 0644]
man/man3/getrlimit.3 [new file with mode: 0644]

index 6dc5bd8696e39ea8e5df430cdd01ba86d5bd9d81..465b6ea9503afb1e2308b82caa5a4aa5a5079891 100644 (file)
 int getpriority(int, int);
 int setpriority(int, int, int);
 
+#ifdef _POSIX_SOURCE
+
+#include <sys/time.h>
+
+typedef unsigned long rlim_t;
+
+#define RLIM_INFINITY ((rlim_t) -1)
+#define RLIM_SAVED_CUR RLIM_INFINITY
+#define RLIM_SAVED_MAX RLIM_INFINITY
+
+struct rlimit
+{
+       rlim_t rlim_cur;
+       rlim_t rlim_max;
+};
+
+#define RLIMIT_CORE    1
+#define RLIMIT_CPU     2
+#define RLIMIT_DATA    3
+#define RLIMIT_FSIZE   4
+#define RLIMIT_NOFILE  5
+#define RLIMIT_STACK   6
+#define RLIMIT_AS      7
+
+int getrlimit(int resource, struct rlimit *rlp);
+
+#endif /* defined(_POSIX_SOURCE) */
+
 #endif
index 156742430f246c13a3876e731667855791a867ee..3d129bfeb6e526160739c1bdf6f668db2f5826dc 100644 (file)
@@ -216,4 +216,8 @@ _PROTOTYPE( int initgroups, (const char *name, gid_t basegid)               );
 
 #endif
 
+#ifdef _POSIX_SOURCE
+_PROTOTYPE( int getdtablesize, (void)                                   );
+#endif
+
 #endif /* _UNISTD_H */
index 6d84c857038041d34038fd5a3272c66f240ff4bd..6f191121bfccc9e33f787fb38a1b9fc3cd831418 100644 (file)
@@ -77,6 +77,7 @@ libc_FILES=" \
        random.c \
        realpath.c \
        rindex.c \
+       rlimit.c \
        setenv.c \
        setgroups.c \
        settimeofday.c \
diff --git a/lib/other/rlimit.c b/lib/other/rlimit.c
new file mode 100644 (file)
index 0000000..77fd8c2
--- /dev/null
@@ -0,0 +1,55 @@
+/*     getdtablesize, getrlimit              Author: Erik van der Kouwe
+ *      query resource consumtion limits      4 December 2009
+ *
+ * Based on these specifications:
+ * http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html 
+ * http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html 
+ */
+#include <errno.h>
+#include <limits.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+int getdtablesize(void)
+{
+       return OPEN_MAX;
+}
+
+int getrlimit(int resource, struct rlimit *rlp)
+{
+       rlim_t limit;
+       
+       switch (resource)
+       {
+               case RLIMIT_CORE:
+                       /* no core currently produced */
+                       limit = 0;
+                       break;
+
+               case RLIMIT_CPU:
+               case RLIMIT_DATA:
+               case RLIMIT_FSIZE:
+               case RLIMIT_STACK:
+               case RLIMIT_AS:
+                       /* no limit enforced (however architectural limits 
+                        * may apply) 
+                        */     
+                       limit = RLIM_INFINITY;
+                       break;
+
+               case RLIMIT_NOFILE:
+                       limit = OPEN_MAX;
+                       break;
+
+               default:
+                       errno = EINVAL;
+                       return -1;
+       }               
+
+       /* return limit */
+       rlp->rlim_cur = limit;
+       rlp->rlim_max = limit;
+       return 0;
+}
+
diff --git a/man/man3/getdtablesize.3 b/man/man3/getdtablesize.3
new file mode 100644 (file)
index 0000000..9e5d24b
--- /dev/null
@@ -0,0 +1,16 @@
+.TH GETDTABLESIZE 3  "December 4, 2009"
+.UC 4
+.SH NAME
+getdtablesize \- query maximum number of open files
+.SH SYNOPSIS
+.nf
+.ft B
+#include <unistd.h>
+
+int getdtablesize(void);
+.fi
+.SH DESCRIPTION
+getdtablesize returns the number of files that may be open at the same time
+in a process.
+.SH "RETURN VALUE
+The number of files that may be open at the same time in a process is returned.
diff --git a/man/man3/getrlimit.3 b/man/man3/getrlimit.3
new file mode 100644 (file)
index 0000000..c2e1e48
--- /dev/null
@@ -0,0 +1,23 @@
+.TH GETRLIMIT 3  "December 4, 2009"
+.UC 4
+.SH NAME
+getrlimit \- query resource consumption limits
+.SH SYNOPSIS
+.nf
+.ft B
+#include <sys/resource.h>
+
+int getrlimit(int \fIresource\fP, struct rlimit *\fIrlp\fP);
+.fi
+.SH DESCRIPTION
+getrlimit queries the current resource limit regarding the specified
+\fIresource\fP. This can be one of the following: RLIMIT_CORE, RLIMIT_CPU,
+RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_NOFILE, RLIMIT_STACK or RLIMIT_AS.
+The soft limit is specified in \fIrlp\fP\->rlim_cur and the hard limit in
+\fIrlp\fP\->rlim_max. On MINIX, these are currently always the same.
+A value of RLIM_INFINITY specifies that no limit is enforced, although
+architectural limits may still apply.
+.SH "RETURN VALUE
+If the function succeeds, 0 is returned.
+If the function fails, -1 is returned and errno is set to indicate the
+cause of the failure.