Simply bump resource limits if file opens fail, and retry.
Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com>
oname = malloc(strlen(aqd_name) + strlen(str) + 32);
sprintf(oname, "%s_%s.dat", aqd_name, str);
- if ((ap->fp = fopen(oname, "w")) == NULL) {
+ if ((ap->fp = my_fopen(oname, "w")) == NULL) {
perror(oname);
return NULL;
}
{
if (fname) {
char *buf;
- FILE *ofp = fopen(fname, "w");
+ FILE *ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
char *fname = malloc(strlen(output_name) + 32);
sprintf(fname, "%s.dat", output_name);
- ranges_ofp = fopen(fname, "w");
+ ranges_ofp = my_fopen(fname, "w");
if (ranges_ofp == NULL) {
perror(fname);
exit(1);
printf("Sending range data to %s\n", fname);
sprintf(fname, "%s.avg", output_name);
- avgs_ofp = fopen(fname, "w");
+ avgs_ofp = my_fopen(fname, "w");
if (avgs_ofp == NULL) {
perror(fname);
exit(1);
printf("Sending stats data to %s\n", fname);
sprintf(fname, "%s.msg", output_name);
- msgs_ofp = fopen(fname, "w");
+ msgs_ofp = my_fopen(fname, "w");
if (msgs_ofp == NULL) {
perror(fname);
exit(1);
if (easy_parse_avgs) {
sprintf(fname, "%s.xvg", output_name);
- xavgs_ofp = fopen(fname, "w");
+ xavgs_ofp = my_fopen(fname, "w");
if (avgs_ofp == NULL) {
perror(fname);
exit(1);
oname = malloc(strlen(bno_dump_name) + 32);
sprintf(oname, "%s_%03d,%03d_%c.dat", bno_dump_name, mjr, mnr, rwc);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&bno_dump_files, fp, oname);
{
char line[256];
struct devmap dm;
- FILE *fp = fopen(fname, "r");
+ FILE *fp = my_fopen(fname, "r");
if (!fp) {
perror(fname);
static inline FILE *open_pit(char *str)
{
- FILE *fp = fopen(str, "w");
+ FILE *fp = my_fopen(str, "w");
if (fp == NULL)
perror(str);
void add_buf(void *buf);
void clean_bufs(void);
char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens);
+FILE *my_fopen(const char *path, const char *mode);
void dbg_ping(void);
/* mmap.c */
oname = malloc(strlen(name)+32);
sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&all_files, fp, oname);
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#define INLINE_DECLARE
#include "globals.h"
return pad;
}
+/*
+ * Due to the N(devs) parts of a lot of the output features provided
+ * by btt, it will fail opens on large(ish) systems. Here we try to
+ * keep bumping our open file limits, and if those fail, we return NULL.
+ *
+ * Root users will probably be OK with this, others...
+ */
+FILE *my_fopen(const char *path, const char *mode)
+{
+ FILE *fp;
+
+ fp = fopen(path, mode);
+ while (fp == NULL) {
+ if (errno == ENFILE || errno == EMFILE) {
+ struct rlimit rlim;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ perror("get: RLIMIT_NOFILE");
+ return NULL;
+ }
+
+ rlim.rlim_cur++;
+ if (rlim.rlim_cur >= rlim.rlim_max)
+ rlim.rlim_max++;
+
+ if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ perror("set: RLIMIT_NOFILE");
+ return NULL;
+ }
+ }
+ else {
+ perror(path);
+ return NULL;
+ }
+
+ fp = fopen(path, mode);
+ }
+
+ return fp;
+}
+
void dbg_ping(void) {}
if (output_name == NULL) return;
sprintf(fname, "%s_qhist.dat", output_name);
- ofp = fopen(fname, "w");
+ ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
return;
fclose(ofp);
sprintf(fname, "%s_dhist.dat", output_name);
- ofp = fopen(fname, "w");
+ ofp = my_fopen(fname, "w");
if (!ofp) {
perror(fname);
return;
oname = malloc(strlen(str) + 32);
sprintf(oname, "%s.dat", str);
- if ((pp->fp = fopen(oname, "w")) == NULL) {
+ if ((pp->fp = my_fopen(oname, "w")) == NULL) {
perror(oname);
return NULL;
}
oname = malloc(strlen(seek_name) + strlen(str) + 32);
sprintf(oname, "%s_%s_%c.dat", seek_name, str, rw);
- if ((fp = fopen(oname, "w")) == NULL)
+ if ((fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&seek_files, fp, oname);
oname = malloc(strlen(sps_name) + strlen(str) + 32);
sprintf(oname, "%s_%s.dat", sps_name, str);
- if ((sip->sps_fp = fopen(oname, "w")) == NULL)
+ if ((sip->sps_fp = my_fopen(oname, "w")) == NULL)
perror(oname);
else
add_file(&seek_files, sip->sps_fp, oname);