[parted-devel] [PATCH] Enable full memory dump
Frodo Baggins
frodo.drogo at gmail.com
Fri Sep 14 21:17:07 UTC 2007
Any thoughts on this?
On 9/12/07, Frodo Baggins <frodo.drogo at gmail.com> wrote:
> From b8866155b7b9aed4c3035f3aeff8662e4c785e92 Mon Sep 17 00:00:00 2001
> From: Frodo Baggins <frodo.drogo at gmail.com>
> Date: Wed, 12 Sep 2007 00:11:37 +0530
> Subject: [PATCH] Enable full memory dump
>
> If user is root, we can remove the limit on core dump size. This may
> make it easier to debug dumps.
> The old limit is saved and restored at exit via atexit(3).
> ---
> parted/parted.c | 24 ++++++++++++++++++++++++
> 1 files changed, 24 insertions(+), 0 deletions(-)
>
> diff --git a/parted/parted.c b/parted/parted.c
> index 6a606ae..154e710 100644
> --- a/parted/parted.c
> +++ b/parted/parted.c
> @@ -57,6 +57,8 @@
> #endif
>
> #include <getopt.h>
> +#include <sys/time.h>
> +#include <sys/resource.h>
>
> /* minimum amount of free space to leave, or maximum amount to gobble up */
> #define MIN_FREESPACE (1000 * 2) /* 1000k */
> @@ -147,9 +149,24 @@ static Command* commands [256] = {NULL};
> static PedTimer* g_timer;
> static TimerContext timer_context;
>
> +#ifdef HAVE_GETUID
> +static struct rlimit old_limit;
> +static void restore_rlimit(void);
> +#endif
> +
> static int _print_list ();
> static void _done (PedDevice* dev);
>
> +#ifdef HAVE_GETUID
> +static void
> +restore_rlimit(void)
> +{
> + if(getuid() == 0){
> + setrlimit(RLIMIT_CORE,&old_limit);
> + }
> +}
> +#endif
> +
> static void
> _timer_handler (PedTimer* timer, void* context)
> {
> @@ -2397,6 +2414,7 @@ static PedDevice*
> _init (int* argc_ptr, char*** argv_ptr)
> {
> PedDevice* dev;
> +struct rlimit infinity={RLIM_INFINITY,RLIM_INFINITY};
>
> #ifdef ENABLE_MTRACE
> mtrace();
> @@ -2416,6 +2434,11 @@ if (!_parse_options (argc_ptr, argv_ptr)
> puts (_("WARNING: You are not superuser. Watch out for "
> "permissions."));
> }
> + /* Set maximum permitted core file size to infinity if possible */
> + if(getuid() == 0){
> + getrlimit(RLIMIT_CORE,&old_limit);
> + setrlimit(RLIMIT_CORE,&infinity);
> + }
> #endif
>
> dev = _choose_device (argc_ptr, argv_ptr);
> @@ -2470,6 +2493,7 @@ main (int argc, char** argv)
>
> program_name = argv[0];
> atexit (close_stdout);
> + atexit (restore_rlimit);
>
> dev = _init (&argc, &argv);
> if (!dev)
> --
> 1.4.3.4
>
More information about the parted-devel
mailing list