4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:utility.c 2.9 */
31 static void logError();
32 extern int cuantos(), gnamef();
38 * produce an assert error message
42 * i1 - integer 1 (usually errno)
43 * file - __FILE of calling module
44 * line - __LINE__ of calling module
47 assert(s1
, s2
, i1
, file
, line
)
50 logError(s1
, s2
, i1
, TY_ASSERT
, file
, line
);
56 * produce an assert error message
57 * input: -- same as assert
60 errent(s1
, s2
, i1
, file
, line
)
63 logError(s1
, s2
, i1
, TY_ERROR
, file
, line
);
67 #define EFORMAT "%sERROR (%.9s) pid: %ld (%s) %s %s (%d) [FILE: %s, LINE: %d]\n"
70 logError(s1
, s2
, i1
, type
, file
, line
)
73 register FILE *errlog
;
80 errlog
= fopen(ERRLOG
, "a");
81 (void) chmod(ERRLOG
, PUB_FILEMODE
);
88 (void) fprintf(errlog
, EFORMAT
, type
== TY_ASSERT
? "ASSERT " : " ",
89 Progname
, (long) pid
, timeStamp(), s1
, s2
, i1
, file
, line
);
92 (void) fclose(errlog
);
94 (void) sprintf(text
, " %sERROR %.100s %.100s (%.9s)",
95 type
== TY_ASSERT
? "ASSERT " : " ",
97 if (type
== TY_ASSERT
)
98 systat(Rmtname
, SS_ASSERT_ERROR
, text
, Retrytime
);
103 /* timeStamp - create standard time string
105 * pointer to time string
111 register struct tm
*tp
;
116 tp
= localtime(&clock
);
117 (void) sprintf(str
, "%d/%d-%d:%2.2d:%2.2d", tp
->tm_mon
+ 1,
118 tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
, tp
->tm_sec
);
124 * Function: countProcs - Count Process to Stay Within Limits
126 * There are a number of cases in BNU when we want to limit the number
127 * of processes of a certain type that are running at a given time. This
128 * process is used to check the number of existing processes, to determine
129 * if a new one is allowed.
131 * The strategy is that all processes of a given type will place a lock
132 * file with a specific prefix in a single directory, usually
133 * /var/spool/locks. The caller of this function must provide a full
134 * path prefix, and countProcs will count the number of files that begin
135 * with the prefix and compare the count to the allowable maximum.
139 * prefix - A full path prefix for lock files that identify
140 * processes that are to be counted.
141 * maxCount - Maximum number of allowable processes.
145 * TRUE is returned if this process is allowed to continue, and
146 * FALSE is returned if the maximum is exceeded.
150 countProcs (prefix
, maxCount
)
156 register char * namePrefix
; /* Points to file name part */
158 char directory
[MAXNAMESIZE
];
159 register int processes
; /* Count of processes. */
161 /* Separate prefix into directory part and file name part. */
163 strncpy(directory
, prefix
, MAXNAMESIZE
);
164 directory
[MAXNAMESIZE
-1] = NULLCHAR
;
165 namePrefix
= strrchr(directory
, '/');
166 ASSERT(namePrefix
!= NULL
, "No file name in", prefix
, 0);
167 *namePrefix
++ = NULLCHAR
; /* Terminate directory part */
169 /* Check to see if we can continue. */
171 processes
= cuantos(namePrefix
, directory
);
172 if (processes
<= maxCount
)
180 * return the number of files in directory <dir> who's names
181 * begin with <prefix>
182 * This is used to count the number of processes of a certain
183 * type that are currently running.
192 char fullname
[MAXNAMESIZE
], file
[MAXNAMESIZE
];
195 ASSERT(pdir
!= NULL
, Ct_OPEN
, dir
, errno
);
197 while (gnamef(pdir
, file
) == TRUE
)
198 if (PREFIX(prefix
, file
)) {
199 (void) sprintf(fullname
, "%s/%s", dir
, file
);
200 if (cklock(fullname
))