File: resources.c

package info (click to toggle)
zmailer 2.99.55-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,516 kB
  • ctags: 9,694
  • sloc: ansic: 120,953; sh: 3,862; makefile: 3,166; perl: 2,695; python: 115; awk: 22
file content (129 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 *	Copyright 1994-1998 Matti Aarnio, all rights reserved.
 *	This module is a part of Zmailer, and subject to its
 *	distribution rules.
 */


#include "hostenv.h"
#include <sfio.h>
#include <sys/types.h>

#if defined(HAVE_SETRLIMIT) && !defined(_AIX)
/* AIX 4.2.1 has "funny" RLIMIT_NOFILE return value: RLIM_INFINITY ..
   Earlier AIXes don't have RLIMIT_NOFILE resource, thus lets not let
   AIX to use  setrlimit()  even when it exists.. */

/* ================================================================== */

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

/* #include "prototypes.h" */ /* Scheduler's prototypes */

int resources_query_nofiles()
{
#ifdef	RLIMIT_NOFILE
	struct rlimit rl;
	int rc;

	rc = getrlimit(RLIMIT_NOFILE,&rl);
	if (rc == 0 && rl.rlim_cur > 10)
	    return rl.rlim_cur;
	else
	  return getdtablesize();
#else
	return sysconf(_SC_OPEN_MAX);
#endif
}

void
resources_maximize_nofiles()
{
#ifdef	RLIMIT_NOFILE		/* Linuxes pre 1.2 (1.3?) don't have this..*/
	struct rlimit rl;
	int rc;

	rc = getrlimit(RLIMIT_NOFILE,&rl);
	if (rc != 0) return;
	rl.rlim_cur = rl.rlim_max;
	setrlimit(RLIMIT_NOFILE,&rl);
#endif
}

void
resources_limit_nofiles(nfiles)
int nfiles;
{
#ifdef	RLIMIT_NOFILE
	struct rlimit rl;
	int rc;

	rc = getrlimit(RLIMIT_NOFILE,&rl);
	if (rc != 0) return;
	rl.rlim_cur = nfiles;
	setrlimit(RLIMIT_NOFILE,&rl);
#endif
}

#else
#ifdef HAVE_SYSCONF
/* ================================================================ */

#include <unistd.h>
int
resources_query_nofiles()
{
	return sysconf(_SC_OPEN_MAX);
}

void
resources_maximize_nofiles()
{
}

void
resources_limit_nofiles(nfiles)
int nfiles;
{
}

#else
/* ================================================================ */

int
resources_query_nofiles()
{
	return getdtablesize();
}

void
resources_maximize_nofiles()
{
}

void
resources_limit_nofiles(nfiles)
int nfiles;
{
}

#endif
#endif

#ifdef HAVE_FPATHCONF
int
resources_query_pipesize(fildes)
int fildes;
{
	return (int) fpathconf(fildes, _PC_PIPE_BUF);
}
#else
int
resources_query_pipesize(fildes)
int fildes;
{
	return 4096;	/* pipe buffer size (max contents before blocking) */
}
#endif