1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 #include <sys/types.h> |
|
27 #include <string.h> |
|
28 #include <stdio.h> |
|
29 #include <stdlib.h> |
|
30 #include <unistd.h> |
|
31 #include <time.h> |
|
32 #include <errno.h> |
|
33 #include <limits.h> |
|
34 |
|
35 #include <rad/adr.h> |
|
36 #include <rad/rad_modapi.h> |
|
37 |
|
38 #include "api_example_time2.h" |
|
39 |
|
40 /*ARGSUSED*/ |
|
41 conerr_t |
|
42 interface_Time_read_time(rad_instance_t *inst, adr_attribute_t *attr, |
|
43 adr_data_t **data, adr_data_t **error) |
|
44 { |
|
45 *data = adr_data_new_long((long long)time(NULL) * 1000); |
|
46 return (CE_OK); |
|
47 } |
|
48 |
|
49 /*ARGSUSED*/ |
|
50 conerr_t |
|
51 interface_Time_write_time(rad_instance_t *inst, adr_attribute_t *attr, |
|
52 adr_data_t *data, adr_data_t **error) |
|
53 { |
|
54 long long rawtime = adr_data_to_longint(data) / 1000; |
|
55 time_t newtime = (time_t)rawtime; |
|
56 |
|
57 if (rawtime > LONG_MAX) |
|
58 return (CE_OBJECT); |
|
59 |
|
60 if (stime(&newtime) == -1) { |
|
61 if (errno == EPERM) |
|
62 return (CE_PRIV); |
|
63 return (CE_OBJECT); |
|
64 } |
|
65 |
|
66 return (CE_OK); |
|
67 } |
|
68 |
|
69 |
|
70 int |
|
71 _rad_init(void) |
|
72 { |
|
73 adr_name_t *name = adr_name_vcreate( |
|
74 MOD_DOMAIN, 1, "type", "Time"); |
|
75 (void) rad_cont_insert_singleton(rad_container, name, &modinfo, |
|
76 &interface_Time_svr); |
|
77 |
|
78 return (0); |
|
79 } |
|
80 |
|
81 /* |
|
82 * _rad_fini is called by the RAD daemon when the module is unloaded. Any |
|
83 * module finalisation is completed here. |
|
84 */ |
|
85 /*ARGSUSED*/ |
|
86 void |
|
87 _rad_fini(void *unused) |
|
88 { |
|
89 } |
|