Signed-off-by: Zeng Linggang <[email protected]>
---
 include/safe_macros.h | 10 ++++++++++
 lib/safe_macros.c     | 30 ++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/safe_macros.h b/include/safe_macros.h
index 207affc..bdd974c 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -196,5 +196,15 @@ int safe_lstat(const char *file, const int lineno, void 
(cleanup_fn)(void),
 #define SAFE_LSTAT(cleanup_fn, path, buf) \
        safe_lstat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
 
+int safe_getrlimit(const char *file, const int lineno, void (cleanup_fn)(void),
+                  int resource, struct rlimit *rlim);
+#define SAFE_GETRLIMIT(cleanup_fn, resource, rlim) \
+       safe_getrlimit(__FILE__, __LINE__, (cleanup_fn), (resource), (rlim))
+
+int safe_setrlimit(const char *file, const int lineno, void (cleanup_fn)(void),
+                  int resource, const struct rlimit *rlim);
+#define SAFE_SETRLIMIT(cleanup_fn, resource, rlim) \
+       safe_setrlimit(__FILE__, __LINE__, (cleanup_fn), (resource), (rlim))
+
 #endif /* __SAFE_MACROS_H__ */
 #endif /* __TEST_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index ad24195..e8795ef 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -500,3 +500,33 @@ int safe_lstat(const char *file, const int lineno,
 
        return rval;
 }
+
+int safe_getrlimit(const char *file, const int lineno,
+                  void (cleanup_fn)(void), int resource, struct rlimit *rlim)
+{
+       int rval;
+
+       rval = getrlimit(resource, rlim);
+
+       if (rval == -1) {
+               tst_brkm(TBROK | TERRNO, cleanup_fn,
+                        "getrlimit failed at %s:%d", file, lineno);
+       }
+
+       return rval;
+}
+
+int safe_setrlimit(const char *file, const int lineno, void (cleanup_fn)(void),
+                  int resource, const struct rlimit *rlim)
+{
+       int rval;
+
+       rval = setrlimit(resource, rlim);
+
+       if (rval == -1) {
+               tst_brkm(TBROK | TERRNO, cleanup_fn,
+                        "setrlimit failed at %s:%d", file, lineno);
+       }
+
+       return rval;
+}
-- 
1.8.4.2




------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to