xref: /titanic_44/usr/src/lib/libnisdb/yptol/ttl_utils.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * DESCRIPTION: Contains utilities relating to TTL calculation.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate #include <unistd.h>
33*7c478bd9Sstevel@tonic-gate #include <syslog.h>
34*7c478bd9Sstevel@tonic-gate #include <errno.h>
35*7c478bd9Sstevel@tonic-gate #include <strings.h>
36*7c478bd9Sstevel@tonic-gate #include <ndbm.h>
37*7c478bd9Sstevel@tonic-gate #include "ypsym.h"
38*7c478bd9Sstevel@tonic-gate #include "ypdefs.h"
39*7c478bd9Sstevel@tonic-gate #include "shim.h"
40*7c478bd9Sstevel@tonic-gate #include "yptol.h"
41*7c478bd9Sstevel@tonic-gate #include "../ldap_util.h"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * Constants used in time calculations
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define	MILLION 1000000
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Decs
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate suc_code is_greater_timeval(struct timeval *, struct timeval *);
52*7c478bd9Sstevel@tonic-gate suc_code add_to_timeval(struct timeval *, int);
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  * FUNCTION:	has_entry_expired()
56*7c478bd9Sstevel@tonic-gate  *
57*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Determines if an individual entry has expired.
58*7c478bd9Sstevel@tonic-gate  *
59*7c478bd9Sstevel@tonic-gate  * INPUTS:	Map control structure for an open map
60*7c478bd9Sstevel@tonic-gate  *		Entry key
61*7c478bd9Sstevel@tonic-gate  *
62*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	TRUE =  Entry has expired or cannot be found this will cause
63*7c478bd9Sstevel@tonic-gate  *			missing entries to be pulled out of the DIT.
64*7c478bd9Sstevel@tonic-gate  *		FALSE = Entry has not expired
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate bool_t
has_entry_expired(map_ctrl * map,datum * key)68*7c478bd9Sstevel@tonic-gate has_entry_expired(map_ctrl *map, datum *key)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	datum ttl;
71*7c478bd9Sstevel@tonic-gate 	struct timeval	now;
72*7c478bd9Sstevel@tonic-gate 	struct timeval	old_time;
73*7c478bd9Sstevel@tonic-gate 	char	*key_name;
74*7c478bd9Sstevel@tonic-gate 	char *myself = "has_entry_expired";
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	if ((map == NULL) || (map->ttl == NULL))
77*7c478bd9Sstevel@tonic-gate 		return (FALSE);
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 	/* Get expiry time entry for key */
80*7c478bd9Sstevel@tonic-gate 	ttl = dbm_fetch(map->ttl, *key);
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 	if (NULL == ttl.dptr) {
83*7c478bd9Sstevel@tonic-gate 		/*
84*7c478bd9Sstevel@tonic-gate 		 * If we failed to get a map expiry key, which must always be
85*7c478bd9Sstevel@tonic-gate 		 * present, then something is seriously wrong. Try to recreate
86*7c478bd9Sstevel@tonic-gate 		 * the map.
87*7c478bd9Sstevel@tonic-gate 		 */
88*7c478bd9Sstevel@tonic-gate 		if ((key->dsize == strlen(MAP_EXPIRY_KEY)) &&
89*7c478bd9Sstevel@tonic-gate 			(0 == strncmp(key->dptr, MAP_EXPIRY_KEY, key->dsize))) {
90*7c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR, "Cannot find %s TTL "
91*7c478bd9Sstevel@tonic-gate 				"for map %s. Will attempt to recreate map",
92*7c478bd9Sstevel@tonic-gate 				MAP_EXPIRY_KEY, map->map_name);
93*7c478bd9Sstevel@tonic-gate 			return (TRUE);
94*7c478bd9Sstevel@tonic-gate 		}
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 		/*
97*7c478bd9Sstevel@tonic-gate 		 * Not a problem just no TTL entry for this entry. Maybe it has
98*7c478bd9Sstevel@tonic-gate 		 * not yet been downloaded. Maybe it will be handled by a
99*7c478bd9Sstevel@tonic-gate 		 * service other than NIS. Check if the entire map has expired.
100*7c478bd9Sstevel@tonic-gate 		 * This prevents repeated LDAP reads when requests are made for
101*7c478bd9Sstevel@tonic-gate 		 * nonexistant entries.
102*7c478bd9Sstevel@tonic-gate 		 */
103*7c478bd9Sstevel@tonic-gate 		if (has_map_expired(map)) {
104*7c478bd9Sstevel@tonic-gate 			/* Kick of a map update */
105*7c478bd9Sstevel@tonic-gate 			update_map_if_required(map, FALSE);
106*7c478bd9Sstevel@tonic-gate 		}
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 		/* Don't update the entry */
109*7c478bd9Sstevel@tonic-gate 		return (FALSE);
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	if (ttl.dsize != sizeof (struct timeval)) {
113*7c478bd9Sstevel@tonic-gate 		/*
114*7c478bd9Sstevel@tonic-gate 		 * Need to malloc some memory before can syslog the key name
115*7c478bd9Sstevel@tonic-gate 		 * but this may fail. Solution log a simple message first THEn
116*7c478bd9Sstevel@tonic-gate 		 * a more detailed one if it works.
117*7c478bd9Sstevel@tonic-gate 		 */
118*7c478bd9Sstevel@tonic-gate 		logmsg(MSG_NOTIMECHECK, LOG_ERR,
119*7c478bd9Sstevel@tonic-gate 			"Invalid TTL key in map %s. error %d",
120*7c478bd9Sstevel@tonic-gate 					map->map_name, dbm_error(map->ttl));
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 		/* Log the key name */
123*7c478bd9Sstevel@tonic-gate 		key_name = (char *)am(myself, key->dsize + 1);
124*7c478bd9Sstevel@tonic-gate 		if (NULL == key_name) {
125*7c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOMEM, LOG_ERR,
126*7c478bd9Sstevel@tonic-gate 					"Could not alloc memory for keyname");
127*7c478bd9Sstevel@tonic-gate 		} else {
128*7c478bd9Sstevel@tonic-gate 			strncpy(key_name, key->dptr, key->dsize);
129*7c478bd9Sstevel@tonic-gate 			key_name[key->dsize] = '\0';
130*7c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
131*7c478bd9Sstevel@tonic-gate 						"Key name was %s", key_name);
132*7c478bd9Sstevel@tonic-gate 			sfree(key_name);
133*7c478bd9Sstevel@tonic-gate 		}
134*7c478bd9Sstevel@tonic-gate 		/* Update it Anyway */
135*7c478bd9Sstevel@tonic-gate 		return (TRUE);
136*7c478bd9Sstevel@tonic-gate 	}
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	/* Get current time */
139*7c478bd9Sstevel@tonic-gate 	gettimeofday(&now, NULL);
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	/*
142*7c478bd9Sstevel@tonic-gate 	 * Because dptr may not be int aligned need to build an int
143*7c478bd9Sstevel@tonic-gate 	 * out of what it points to or will get a bus error
144*7c478bd9Sstevel@tonic-gate 	 */
145*7c478bd9Sstevel@tonic-gate 	bcopy(ttl.dptr, &old_time, sizeof (struct timeval));
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	return (is_greater_timeval(&now, &old_time));
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate /*
151*7c478bd9Sstevel@tonic-gate  * FUNCTION:	has_map_expired()
152*7c478bd9Sstevel@tonic-gate  *
153*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Determines if an entire map has expire
154*7c478bd9Sstevel@tonic-gate  *
155*7c478bd9Sstevel@tonic-gate  * INPUTS:	Map control structure for an open map
156*7c478bd9Sstevel@tonic-gate  *
157*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	TRUE = Map has expired
158*7c478bd9Sstevel@tonic-gate  *		FALSE  Map has not expired
159*7c478bd9Sstevel@tonic-gate  *
160*7c478bd9Sstevel@tonic-gate  */
161*7c478bd9Sstevel@tonic-gate bool_t
has_map_expired(map_ctrl * map)162*7c478bd9Sstevel@tonic-gate has_map_expired(map_ctrl *map)
163*7c478bd9Sstevel@tonic-gate {
164*7c478bd9Sstevel@tonic-gate 	datum key;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	/* Set up datum with magic expiry key */
167*7c478bd9Sstevel@tonic-gate 	key.dsize = strlen(MAP_EXPIRY_KEY);
168*7c478bd9Sstevel@tonic-gate 	key.dptr = MAP_EXPIRY_KEY;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	/* Call has_entry_expired() with magic map expiry key */
171*7c478bd9Sstevel@tonic-gate 	return (has_entry_expired(map, &key));
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate /*
175*7c478bd9Sstevel@tonic-gate  * FUNCTION:	update_entry_ttl()
176*7c478bd9Sstevel@tonic-gate  *
177*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Updates the TTL for one map entry
178*7c478bd9Sstevel@tonic-gate  *
179*7c478bd9Sstevel@tonic-gate  * INPUTS:	Map control structure for an open map
180*7c478bd9Sstevel@tonic-gate  *		Entry key
181*7c478bd9Sstevel@tonic-gate  *		Flag indication if TTL should be max, min or random
182*7c478bd9Sstevel@tonic-gate  *
183*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	SUCCESS = TTL updated
184*7c478bd9Sstevel@tonic-gate  *		FAILURE = TTL not updated
185*7c478bd9Sstevel@tonic-gate  *
186*7c478bd9Sstevel@tonic-gate  */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate suc_code
update_entry_ttl(map_ctrl * map,datum * key,TTL_TYPE type)189*7c478bd9Sstevel@tonic-gate update_entry_ttl(map_ctrl *map, datum *key, TTL_TYPE type)
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	datum expire;
192*7c478bd9Sstevel@tonic-gate 	struct timeval	now;
193*7c478bd9Sstevel@tonic-gate 	int	ttl;
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	/* Get current time */
196*7c478bd9Sstevel@tonic-gate 	gettimeofday(&now, NULL);
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 	/* Get TTL from mapping file */
199*7c478bd9Sstevel@tonic-gate 	ttl = get_ttl_value(map, type);
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 	if (FAILURE == add_to_timeval(&now, ttl))
202*7c478bd9Sstevel@tonic-gate 		return (FAILURE);
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	/* Convert time into a datum */
205*7c478bd9Sstevel@tonic-gate 	expire.dsize = sizeof (struct timeval);
206*7c478bd9Sstevel@tonic-gate 	expire.dptr = (char *)&now;
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	/* Set expiry time entry for key */
209*7c478bd9Sstevel@tonic-gate 	errno = 0;
210*7c478bd9Sstevel@tonic-gate 	if (0 > dbm_store(map->ttl, *key, expire, DBM_REPLACE)) {
211*7c478bd9Sstevel@tonic-gate 		logmsg(MSG_NOTIMECHECK, LOG_ERR, "Could not write TTL entry "
212*7c478bd9Sstevel@tonic-gate 						"(errno=%d)", errno);
213*7c478bd9Sstevel@tonic-gate 		return (FAILURE);
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
217*7c478bd9Sstevel@tonic-gate }
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /*
220*7c478bd9Sstevel@tonic-gate  * FUNCTION:	update_map_ttl()
221*7c478bd9Sstevel@tonic-gate  *
222*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Updates the TTL for entire map. This can be called either with
223*7c478bd9Sstevel@tonic-gate  *		the map open (map_ctrl DBM pointer set up) or the map closed
224*7c478bd9Sstevel@tonic-gate  *		(map_ctrl DBM pointers not set). The latter case will occur
225*7c478bd9Sstevel@tonic-gate  *		when we have just created a new map.
226*7c478bd9Sstevel@tonic-gate  *
227*7c478bd9Sstevel@tonic-gate  *		This function must open the TTL map but, in either case, must
228*7c478bd9Sstevel@tonic-gate  *		return with the map_ctrl in it's original state.
229*7c478bd9Sstevel@tonic-gate  *
230*7c478bd9Sstevel@tonic-gate  * INPUTS:	Map control structure for an open map
231*7c478bd9Sstevel@tonic-gate  *
232*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	SUCCESS = TTL updated
233*7c478bd9Sstevel@tonic-gate  *		FAILURE = TTL not updated
234*7c478bd9Sstevel@tonic-gate  *
235*7c478bd9Sstevel@tonic-gate  */
236*7c478bd9Sstevel@tonic-gate suc_code
update_map_ttl(map_ctrl * map)237*7c478bd9Sstevel@tonic-gate update_map_ttl(map_ctrl *map)
238*7c478bd9Sstevel@tonic-gate {
239*7c478bd9Sstevel@tonic-gate 	datum key;
240*7c478bd9Sstevel@tonic-gate 	bool_t map_was_open = TRUE;
241*7c478bd9Sstevel@tonic-gate 	suc_code ret;
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	/* Set up datum with magic expiry key */
244*7c478bd9Sstevel@tonic-gate 	key.dsize = strlen(MAP_EXPIRY_KEY);
245*7c478bd9Sstevel@tonic-gate 	key.dptr = MAP_EXPIRY_KEY;
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 	/* If TTL not open open it */
248*7c478bd9Sstevel@tonic-gate 	if (NULL == map->ttl) {
249*7c478bd9Sstevel@tonic-gate 		map->ttl = dbm_open(map->ttl_path, O_RDWR, 0644);
250*7c478bd9Sstevel@tonic-gate 		if (NULL == map->ttl)
251*7c478bd9Sstevel@tonic-gate 			return (FAILURE);
252*7c478bd9Sstevel@tonic-gate 		map_was_open = FALSE;
253*7c478bd9Sstevel@tonic-gate 	}
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	/* Call update_entry_ttl() with magic map expiry key */
256*7c478bd9Sstevel@tonic-gate 	ret = update_entry_ttl(map, &key, TTL_MIN);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	/* If we had to open TTL file close it */
259*7c478bd9Sstevel@tonic-gate 	if (!map_was_open) {
260*7c478bd9Sstevel@tonic-gate 		dbm_close(map->ttl);
261*7c478bd9Sstevel@tonic-gate 		map->ttl_path = NULL;
262*7c478bd9Sstevel@tonic-gate 	}
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 	return (ret);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate /*
268*7c478bd9Sstevel@tonic-gate  * FUNCTION:	add_to_timeval()
269*7c478bd9Sstevel@tonic-gate  *
270*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Adds an int to a timeval
271*7c478bd9Sstevel@tonic-gate  *
272*7c478bd9Sstevel@tonic-gate  * NOTE :	Seems strange that there is not a library function to do this
273*7c478bd9Sstevel@tonic-gate  *		if one exists then this function can be removed.
274*7c478bd9Sstevel@tonic-gate  *
275*7c478bd9Sstevel@tonic-gate  * NOTE :	Does not handle UNIX clock wrap round but this is a much bigger
276*7c478bd9Sstevel@tonic-gate  *		problem.
277*7c478bd9Sstevel@tonic-gate  *
278*7c478bd9Sstevel@tonic-gate  * INPUTS:	Time value to add to
279*7c478bd9Sstevel@tonic-gate  *		Time value to add in seconds
280*7c478bd9Sstevel@tonic-gate  *
281*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	SUCCESS = Addition successful
282*7c478bd9Sstevel@tonic-gate  *		FAILURE = Addition failed (probably wrapped)
283*7c478bd9Sstevel@tonic-gate  *
284*7c478bd9Sstevel@tonic-gate  */
285*7c478bd9Sstevel@tonic-gate suc_code
add_to_timeval(struct timeval * t1,int t2)286*7c478bd9Sstevel@tonic-gate add_to_timeval(struct timeval *t1, int t2)
287*7c478bd9Sstevel@tonic-gate {
288*7c478bd9Sstevel@tonic-gate 	long usec;
289*7c478bd9Sstevel@tonic-gate 	struct timeval oldval;
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	oldval.tv_sec = t1->tv_sec;
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	/* Add seconds part */
294*7c478bd9Sstevel@tonic-gate 	t1->tv_sec += t2;
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	/* Check for clock wrap */
297*7c478bd9Sstevel@tonic-gate 	if (!(t1->tv_sec >= oldval.tv_sec)) {
298*7c478bd9Sstevel@tonic-gate 		logmsg(MSG_NOTIMECHECK, LOG_ERR,
299*7c478bd9Sstevel@tonic-gate 			"Wrap when adding %d to %d", t2, oldval.tv_sec);
300*7c478bd9Sstevel@tonic-gate 		return (FAILURE);
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate  * FUNCTION:	is_greater_timeval()
308*7c478bd9Sstevel@tonic-gate  *
309*7c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Compares two timevals
310*7c478bd9Sstevel@tonic-gate  *
311*7c478bd9Sstevel@tonic-gate  * NOTE :	Seems strange that there is not a library function to do this
312*7c478bd9Sstevel@tonic-gate  *		if one exists then this function can be removed.
313*7c478bd9Sstevel@tonic-gate  *
314*7c478bd9Sstevel@tonic-gate  * INPUTS:	First time value
315*7c478bd9Sstevel@tonic-gate  *		Time value to compare it with
316*7c478bd9Sstevel@tonic-gate  *
317*7c478bd9Sstevel@tonic-gate  * OUTPUTS:	TRUE t1 > t2
318*7c478bd9Sstevel@tonic-gate  *		FALSE t1 <= t2
319*7c478bd9Sstevel@tonic-gate  *
320*7c478bd9Sstevel@tonic-gate  */
321*7c478bd9Sstevel@tonic-gate suc_code
is_greater_timeval(struct timeval * t1,struct timeval * t2)322*7c478bd9Sstevel@tonic-gate is_greater_timeval(struct timeval *t1, struct timeval *t2)
323*7c478bd9Sstevel@tonic-gate {
324*7c478bd9Sstevel@tonic-gate 	if (t1->tv_sec > t2->tv_sec)
325*7c478bd9Sstevel@tonic-gate 		return (TRUE);
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	if (t1->tv_sec == t2->tv_sec) {
328*7c478bd9Sstevel@tonic-gate 		if (t1->tv_usec > t2->tv_usec)
329*7c478bd9Sstevel@tonic-gate 			return (TRUE);
330*7c478bd9Sstevel@tonic-gate 		else
331*7c478bd9Sstevel@tonic-gate 			return (FALSE);
332*7c478bd9Sstevel@tonic-gate 	}
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	return (FALSE);
335*7c478bd9Sstevel@tonic-gate }
336