3 *
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
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /*
30 * DESCRIPTION: Contains utilities relating to TTL calculation.
31 */
32 #include <unistd.h>
33 #include <syslog.h>
34 #include <errno.h>
35 #include <strings.h>
36 #include <ndbm.h>
37 #include "ypsym.h"
38 #include "ypdefs.h"
39 #include "shim.h"
40 #include "yptol.h"
41 #include "../ldap_util.h"
42
43 /*
44 * Constants used in time calculations
45 */
46 #define MILLION 1000000
47
48 /*
268 * FUNCTION: add_to_timeval()
269 *
270 * DESCRIPTION: Adds an int to a timeval
271 *
272 * NOTE : Seems strange that there is not a library function to do this
273 * if one exists then this function can be removed.
274 *
275 * NOTE : Does not handle UNIX clock wrap round but this is a much bigger
276 * problem.
277 *
278 * INPUTS: Time value to add to
279 * Time value to add in seconds
280 *
281 * OUTPUTS: SUCCESS = Addition successful
282 * FAILURE = Addition failed (probably wrapped)
283 *
284 */
285 suc_code
286 add_to_timeval(struct timeval *t1, int t2)
287 {
288 long usec;
289 struct timeval oldval;
290
291 oldval.tv_sec = t1->tv_sec;
292
293 /* Add seconds part */
294 t1->tv_sec += t2;
295
296 /* Check for clock wrap */
297 if (!(t1->tv_sec >= oldval.tv_sec)) {
298 logmsg(MSG_NOTIMECHECK, LOG_ERR,
299 "Wrap when adding %d to %d", t2, oldval.tv_sec);
300 return (FAILURE);
301 }
302
303 return (SUCCESS);
304 }
305
306 /*
307 * FUNCTION: is_greater_timeval()
308 *
|
3 *
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
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2015 Gary Mills
24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /*
29 * DESCRIPTION: Contains utilities relating to TTL calculation.
30 */
31 #include <unistd.h>
32 #include <syslog.h>
33 #include <errno.h>
34 #include <strings.h>
35 #include <ndbm.h>
36 #include "ypsym.h"
37 #include "ypdefs.h"
38 #include "shim.h"
39 #include "yptol.h"
40 #include "../ldap_util.h"
41
42 /*
43 * Constants used in time calculations
44 */
45 #define MILLION 1000000
46
47 /*
267 * FUNCTION: add_to_timeval()
268 *
269 * DESCRIPTION: Adds an int to a timeval
270 *
271 * NOTE : Seems strange that there is not a library function to do this
272 * if one exists then this function can be removed.
273 *
274 * NOTE : Does not handle UNIX clock wrap round but this is a much bigger
275 * problem.
276 *
277 * INPUTS: Time value to add to
278 * Time value to add in seconds
279 *
280 * OUTPUTS: SUCCESS = Addition successful
281 * FAILURE = Addition failed (probably wrapped)
282 *
283 */
284 suc_code
285 add_to_timeval(struct timeval *t1, int t2)
286 {
287 struct timeval oldval;
288
289 oldval.tv_sec = t1->tv_sec;
290
291 /* Add seconds part */
292 t1->tv_sec += t2;
293
294 /* Check for clock wrap */
295 if (!(t1->tv_sec >= oldval.tv_sec)) {
296 logmsg(MSG_NOTIMECHECK, LOG_ERR,
297 "Wrap when adding %d to %d", t2, oldval.tv_sec);
298 return (FAILURE);
299 }
300
301 return (SUCCESS);
302 }
303
304 /*
305 * FUNCTION: is_greater_timeval()
306 *
|