summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm/t-memstat.c
blob: b3bd91891904a80a0543715bd97f7a23470e756c (plain)
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
/*
 * Copyright (c) 2005, 2006 Sendmail, Inc. and its suppliers.
 *      All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include <sm/gen.h>
SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.6 2006/03/27 22:34:47 ca Exp $")

/*
**  Simple test program for memstat
*/

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>

extern char *optarg;
extern int optind;

int
main(argc, argv)
	int argc;
	char **argv;
{
	int r, r2, i, l, slp, sz;
	long v;
	char *resource;

	l = 1;
	sz = slp = 0;
	resource = NULL;
	while ((r = getopt(argc, argv, "l:m:r:s:")) != -1)
	{
		switch ((char) r)
		{
		  case 'l':
			l = strtol(optarg, NULL, 0);
			break;

		  case 'm':
			sz = strtol(optarg, NULL, 0);
			break;

		  case 'r':
			resource = strdup(optarg);
			break;

		  case 's':
			slp = strtol(optarg, NULL, 0);
			break;

		  default:
			break;
		}
	}

	r = sm_memstat_open();
	r2 = -1;
	for (i = 0; i < l; i++)
	{
		char *mem;

		r2 = sm_memstat_get(resource, &v);
		if (slp > 0 && i + 1 < l && 0 == r)
		{
			printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
				resource != NULL ? resource : "default-value",
				v);
			sleep(slp);
			if (sz > 0)
			{
				/*
				**  Just allocate some memory to test the
				**  values that are returned.
				**  Note: this is a memory leak, but that
				**  doesn't matter here.
				*/

				mem = malloc(sz);
				if (NULL == mem)
					printf("malloc(%d) failed\n", sz);
			}
		}
	}
	printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
		resource != NULL ? resource : "default-value", v);
	r = sm_memstat_close();
	return r;
}
OpenPOWER on IntegriCloud