Skip to contentSkip to conversation

getrlimit.2: fix example program

PATCH In review Seonghun Lim 2 participants 2 messages Aug 31, 2011 – Sep 17, 2011 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 getrlimit.2: fix example program

man-pages version: latest git repository
why: Fix compile error of the example program.
Use struct rlimit instead of rlimit64, which is used in prlimit64(). Make error handling code similar with other examples.

man2/getrlimit.2 +0 -0
@@ -529,11 +529,14 @@ The program below demonstrates the use of

#include <unistd.h>
#include <sys/resource.h>

+#define handle_error(msg) \\
+ do { perror(msg); exit(EXIT_FAILURE); } while (0) +
int
main(int argc, char *argv[])
{
- struct rlimit64 old, new;
- struct rlimit64 *newp;
+ struct rlimit old, new;
+ struct rlimit *newp;
pid_t pid;

if (!(argc == 2 || argc == 4)) {
@@ -555,14 +558,16 @@ main(int argc, char *argv[]) previous limit */

if (prlimit(pid, RLIMIT_CPU, newp, &old) == \-1)
- errExit("prlimit\-1");
+ handle_error("prlimit\-1");
+
printf("Previous limits: soft=%lld; hard=%lld\\n", (long long) old.rlim_cur, (long long) old.rlim_max);

/* Retrieve and display new CPU time limit */

if (prlimit(pid, RLIMIT_CPU, NULL, &old) == \-1)
- errExit("prlimit\-2");
+ handle_error("prlimit\-2");
+
printf("New limits: soft=%lld; hard=%lld\\n", (long long) old.rlim_cur, (long long) old.rlim_max);

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hello Seonghun,

2011/8/31 Seonghun Lim <[email protected]>:

Quoted 36 lines

man-pages version: latest git repository
why: Fix compile error of the example program.
Use struct rlimit instead of rlimit64, which is used in prlimit64(). Make error handling code similar with other examples.

man2/getrlimit.2 +3 -0
@@ -529,11 +529,14 @@ The program below demonstrates the use of
 #include <unistd.h>
 #include <sys/resource.h>
 
+#define handle_error(msg) \\
+ do { perror(msg); exit(EXIT_FAILURE); } while (0)
+

int
main(int argc, char *argv[])
{
- struct rlimit64 old, new;
- struct rlimit64 *newp;
+ struct rlimit old, new;
+ struct rlimit *newp;
pid_t pid;

if (!(argc == 2 || argc == 4)) {

man2/getrlimit.2 +0 -0
@@ -555,14 +558,16 @@ main(int argc, char *argv[])

previous limit */

if (prlimit(pid, RLIMIT_CPU, newp, &old) == \-1)
- errExit("prlimit\-1");
+ handle_error("prlimit\-1");
+
printf("Previous limits: soft=%lld; hard=%lld\\n", (long long) old.rlim_cur, (long long) old.rlim_max);

Quoted 8 lines

/* Retrieve and display new CPU time limit */

if (prlimit(pid, RLIMIT_CPU, NULL, &old) == \-1)
- errExit("prlimit\-2");
+ handle_error("prlimit\-2");
+
printf("New limits: soft=%lld; hard=%lld\\n", (long long) old.rlim_cur, (long long) old.rlim_max);

Thanks for this report. I applied the patch below.

Cheers

Michael

man2/getrlimit.2 +8 -4
@@ -61,7 +61,7 @@
 .\" 2008-05-07, mtk / Peter Zijlstra, Added description of RLIMIT_RTTIME
 .\" 2010-11-06, mtk: Added documentation of prlimit()
 .\"
-.TH GETRLIMIT 2 2010-12-03 "Linux" "Linux Programmer's Manual"
+.TH GETRLIMIT 2 2011-09-10 "Linux" "Linux Programmer's Manual"
 .SH NAME
 getrlimit, setrlimit, prlimit \- get/set resource limits
 .SH SYNOPSIS
@@ -84,7 +84,7 @@ Feature Test Macro Requirements for glibc (see
 .in
 .sp
 .BR prlimit ():
-_GNU_SOURCE
+_GNU_SOURCE && _FILE_OFFSET_BITS == 64
 .SH DESCRIPTION
 The
 .BR getrlimit ()
@@ -523,17 +523,21 @@ The program below demonstrates the use of
 .PP
 .nf
 #define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
 #include <stdio.h>
 #include <time.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/resource.h>
 
+#define errExit(msg)   do { perror(msg); exit(EXIT_FAILURE); \\
+                        } while (0)
+
 int
 main(int argc, char *argv[])
 {
-    struct rlimit64 old, new;
-    struct rlimit64 *newp;
+    struct rlimit old, new;
+    struct rlimit *newp;
     pid_t pid;
 
     if (!(argc == 2 || argc == 4)) {
Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html