9 /* #include <iostuff.h>
11 /* off_t get_file_limit()
13 /* void set_file_limit(limit)
16 /* This module manipulates the process-wide file size limit.
17 /* The limit is specified in bytes.
19 /* get_file_limit() looks up the process-wide file size limit.
21 /* set_file_limit() sets the process-wide file size limit to
24 /* All errors are fatal.
31 /* The Secure Mailer license must be distributed with this software.
34 /* IBM T.J. Watson Research
36 /* Yorktown Heights, NY 10598, USA
46 #include <sys/resource.h>
51 /* Utility library. */
56 #define ULIMIT_BLOCK_SIZE 512
58 /* get_file_limit - get process-wide file size limit */
60 off_t
get_file_limit(void)
65 if ((limit
= ulimit(UL_GETFSIZE
, 0)) < 0)
66 msg_fatal("ulimit: %m");
67 if (limit
> OFF_T_MAX
/ ULIMIT_BLOCK_SIZE
)
68 limit
= OFF_T_MAX
/ ULIMIT_BLOCK_SIZE
;
69 return (limit
* ULIMIT_BLOCK_SIZE
);
73 if (getrlimit(RLIMIT_FSIZE
, &rlim
) < 0)
74 msg_fatal("getrlimit: %m");
75 limit
= rlim
.rlim_cur
;
76 return (limit
< 0 ? OFF_T_MAX
: rlim
.rlim_cur
);
77 #endif /* USE_ULIMIT */
80 /* set_file_limit - process-wide file size limit */
82 void set_file_limit(off_t limit
)
85 if (ulimit(UL_SETFSIZE
, limit
/ ULIMIT_BLOCK_SIZE
) < 0)
86 msg_fatal("ulimit: %m");
90 rlim
.rlim_cur
= rlim
.rlim_max
= limit
;
91 if (setrlimit(RLIMIT_FSIZE
, &rlim
) < 0)
92 msg_fatal("setrlimit: %m");
94 if (signal(SIGXFSZ
, SIG_IGN
) == SIG_ERR
)
95 msg_fatal("signal(SIGXFSZ,SIG_IGN): %m");
97 #endif /* USE_ULIMIT */