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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <sys/types.h>
29 #include <sys/uadmin.h>
38 * Pull in the following three interfaces from libscf without introducing
39 * a dependency on it, which since libscf depends on libc would be circular:
42 * scf_simple_prop_next_boolean
43 * scf_simple_prop_free
45 typedef scf_simple_prop_t
*(*scf_simple_prop_get_t
)(scf_handle_t
*,
46 const char *, const char *, const char *);
47 static scf_simple_prop_get_t real_scf_simple_prop_get
= NULL
;
48 typedef uint8_t *(*scf_simple_prop_next_boolean_t
)(scf_simple_prop_t
*);
49 static scf_simple_prop_next_boolean_t real_scf_simple_prop_next_boolean
= NULL
;
50 typedef void (*scf_simple_prop_free_t
)(scf_simple_prop_t
*);
51 static scf_simple_prop_free_t real_scf_simple_prop_free
= NULL
;
52 static mutex_t scf_lock
= DEFAULTMUTEX
;
57 void *scf_handle
= dlopen("libscf.so.1", RTLD_LAZY
);
58 scf_simple_prop_get_t scf_simple_prop_get
= (scf_handle
== NULL
)? NULL
:
59 (scf_simple_prop_get_t
)dlsym(scf_handle
, "scf_simple_prop_get");
60 scf_simple_prop_next_boolean_t scf_simple_prop_next_boolean
=
61 (scf_handle
== NULL
)? NULL
:
62 (scf_simple_prop_next_boolean_t
)dlsym(scf_handle
,
63 "scf_simple_prop_next_boolean");
64 scf_simple_prop_free_t scf_simple_prop_free
=
65 (scf_handle
== NULL
)? NULL
:
66 (scf_simple_prop_free_t
)dlsym(scf_handle
, "scf_simple_prop_free");
68 lmutex_lock(&scf_lock
);
69 if (real_scf_simple_prop_get
== NULL
||
70 real_scf_simple_prop_next_boolean
== NULL
||
71 real_scf_simple_prop_free
== NULL
) {
72 if (scf_simple_prop_get
== NULL
)
73 real_scf_simple_prop_get
= (scf_simple_prop_get_t
)(-1);
75 real_scf_simple_prop_get
= scf_simple_prop_get
;
76 scf_handle
= NULL
; /* don't dlclose it */
78 if (scf_simple_prop_next_boolean
== NULL
)
79 real_scf_simple_prop_next_boolean
=
80 (scf_simple_prop_next_boolean_t
)(-1);
82 real_scf_simple_prop_next_boolean
=
83 scf_simple_prop_next_boolean
;
84 scf_handle
= NULL
; /* don't dlclose it */
86 if (scf_simple_prop_free
== NULL
)
87 real_scf_simple_prop_free
=
88 (scf_simple_prop_free_t
)(-1);
90 real_scf_simple_prop_free
= scf_simple_prop_free
;
91 scf_handle
= NULL
; /* don't dlclose it */
95 lmutex_unlock(&scf_lock
);
98 (void) dlclose(scf_handle
);
102 check_archive_update(void)
104 scf_simple_prop_t
*prop
= NULL
;
105 boolean_t update_flag
= B_FALSE
;
106 char *fmri
= "svc:/system/boot-config:default";
107 uint8_t *ret_val
= NULL
;
109 if (real_scf_simple_prop_get
== NULL
||
110 real_scf_simple_prop_next_boolean
== NULL
||
111 real_scf_simple_prop_free
== NULL
) {
114 if (real_scf_simple_prop_get
== (scf_simple_prop_get_t
)(-1) ||
115 real_scf_simple_prop_next_boolean
==
116 (scf_simple_prop_next_boolean_t
)(-1) ||
117 real_scf_simple_prop_free
== (scf_simple_prop_free_t
)(-1)) {
121 prop
= real_scf_simple_prop_get(NULL
, fmri
, "config",
122 "uadmin_boot_archive_sync");
124 if ((ret_val
= real_scf_simple_prop_next_boolean(prop
)) !=
126 update_flag
= (*ret_val
== 0) ? B_FALSE
:
128 real_scf_simple_prop_free(prop
);
131 if (update_flag
== B_TRUE
)
132 (void) system("/sbin/bootadm update-archive");
136 uadmin(int cmd
, int fcn
, uintptr_t mdep
)
138 extern int __uadmin(int cmd
, int fcn
, uintptr_t mdep
);
140 if (geteuid() == 0 && getzoneid() == GLOBAL_ZONEID
&&
141 (cmd
== A_SHUTDOWN
|| cmd
== A_REBOOT
)) {
142 check_archive_update();
145 return (__uadmin(cmd
, fcn
, mdep
));