Print this page
XXXX update sendmail to 8.14.9
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/sendmail/libsm/t-memstat.c
+++ new/usr/src/cmd/sendmail/libsm/t-memstat.c
1 1 /*
2 - * Copyright (c) 2005-2007 Sendmail, Inc. and its suppliers.
2 + * Copyright (c) 2005-2007 Proofpoint, Inc. and its suppliers.
3 3 * All rights reserved.
4 4 *
5 5 * By using this file, you agree to the terms and conditions set
6 6 * forth in the LICENSE file which can be found at the top level of
7 7 * the sendmail distribution.
8 8 */
9 9
10 -#pragma ident "%Z%%M% %I% %E% SMI"
11 -
12 10 #include <sm/gen.h>
13 -SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
11 +SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.11 2013-11-22 20:51:43 ca Exp $")
14 12
15 13 #include <sm/misc.h>
16 14
17 15 /*
18 16 ** Simple test program for memstat
19 17 */
20 18
21 19 #include <stdlib.h>
22 20 #include <unistd.h>
23 21 #include <stdio.h>
24 22 #include <strings.h>
25 23 #include <string.h>
26 24
27 25 extern char *optarg;
28 26 extern int optind;
29 27
30 28 void
31 29 usage(prg)
32 30 char *prg;
33 31 {
34 32 fprintf(stderr, "usage: %s [options]\n", prg);
35 33 fprintf(stderr, "options:\n");
36 34 fprintf(stderr, "-l n loop n times\n");
37 35 fprintf(stderr, "-m n allocate n bytes per iteration\n");
38 36 fprintf(stderr, "-r name use name as resource to query\n");
39 37 fprintf(stderr, "-s n sleep n seconds per iteration\n");
40 38 }
41 39
42 40 int
43 41 main(argc, argv)
44 42 int argc;
45 43 char **argv;
46 44 {
47 45 int r, r2, i, l, slp, sz;
48 46 long v;
49 47 char *resource;
50 48
51 49 l = 1;
52 50 sz = slp = 0;
53 51 resource = NULL;
54 52 while ((r = getopt(argc, argv, "l:m:r:s:")) != -1)
55 53 {
56 54 switch ((char) r)
57 55 {
|
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
58 56 case 'l':
59 57 l = strtol(optarg, NULL, 0);
60 58 break;
61 59
62 60 case 'm':
63 61 sz = strtol(optarg, NULL, 0);
64 62 break;
65 63
66 64 case 'r':
67 65 resource = strdup(optarg);
66 + if (resource == NULL)
67 + {
68 + fprintf(stderr, "strdup(%s) failed\n",
69 + optarg);
70 + exit(1);
71 + }
68 72 break;
69 73
70 74 case 's':
71 75 slp = strtol(optarg, NULL, 0);
72 76 break;
73 77
74 78 default:
75 79 usage(argv[0]);
76 80 exit(1);
77 81 }
78 82 }
79 83
80 84 r = sm_memstat_open();
81 85 r2 = -1;
82 86 for (i = 0; i < l; i++)
83 87 {
84 88 char *mem;
85 89
86 90 r2 = sm_memstat_get(resource, &v);
87 91 if (slp > 0 && i + 1 < l && 0 == r)
88 92 {
89 93 printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
90 94 resource != NULL ? resource : "default-value",
91 95 v);
92 96 sleep(slp);
93 97 if (sz > 0)
94 98 {
95 99 /*
96 100 ** Just allocate some memory to test the
97 101 ** values that are returned.
98 102 ** Note: this is a memory leak, but that
99 103 ** doesn't matter here.
100 104 */
101 105
102 106 mem = malloc(sz);
103 107 if (NULL == mem)
104 108 printf("malloc(%d) failed\n", sz);
105 109 }
106 110 }
107 111 }
108 112 printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
109 113 resource != NULL ? resource : "default-value", v);
110 114 r = sm_memstat_close();
111 115 return r;
112 116 }
|
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX