public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] getrlimit.2: fix example program
@ 2011-08-31 14:38 Seonghun Lim
       [not found] ` <4E5E4766.5040500-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Seonghun Lim @ 2011-08-31 14:38 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

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.


diff --git a/man2/getrlimit.2 b/man2/getrlimit.2
--- a/man2/getrlimit.2
+++ b/man2/getrlimit.2
@@ -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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] getrlimit.2: fix example program
       [not found] ` <4E5E4766.5040500-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-09-17  5:15   ` Michael Kerrisk
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk @ 2011-09-17  5:15 UTC (permalink / raw)
  To: Seonghun Lim; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hello Seonghun,

2011/8/31 Seonghun Lim <wariua-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> 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.
>
>
> diff --git a/man2/getrlimit.2 b/man2/getrlimit.2
> --- a/man2/getrlimit.2
> +++ b/man2/getrlimit.2
> @@ -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);

Thanks for this report. I applied the patch below.

Cheers

Michael

--- a/man2/getrlimit.2
+++ b/man2/getrlimit.2
@@ -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)) {

-- 
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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-17  5:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-31 14:38 [patch] getrlimit.2: fix example program Seonghun Lim
     [not found] ` <4E5E4766.5040500-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-17  5:15   ` Michael Kerrisk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox