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 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * specials.c - knowledge of special services
31 * svc.startd(1M) has duties that cannot be carried out without knowledge of the
32 * transition of various services, such as the milestones, to their online
33 * states. Hooks are called with the restarter instance's ri_lock held, so
34 * operations on all instances (or on the graph) should be performed
38 #include <sys/statvfs.h>
39 #include <sys/types.h>
56 special_null_transition()
61 special_fsroot_post_online()
67 * /usr, with timezone and locale data, is now available.
69 if (!st
->st_log_timezone_known
) {
71 st
->st_log_timezone_known
= 1;
74 if (!st
->st_log_locale_known
) {
75 locale
= st
->st_locale
;
77 (void) setlocale(LC_ALL
, "");
78 st
->st_locale
= setlocale(LC_MESSAGES
, "");
80 st
->st_locale
= safe_strdup(st
->st_locale
);
81 xstr_sanitize(st
->st_locale
);
84 st
->st_locale
= locale
;
87 (void) textdomain(TEXT_DOMAIN
);
88 st
->st_log_locale_known
= 1;
95 * ctime(3C) ends with '\n\0'.
98 log_framework(LOG_INFO
, "system start time was %s",
99 ctime(&st
->st_start_time
.tv_sec
));
103 special_fsminimal_post_online(void)
109 log_framework(LOG_DEBUG
, "special_fsminimal_post_online hook "
113 * If /var is still read-only, and it is on a separate filesystem, then
114 * attempt to mount it read-write now.
116 if ((ret
= fs_is_read_only("/var", &fsid
)) == 1) {
117 (void) fs_is_read_only("/", &rfsid
);
120 log_framework(LOG_WARNING
, "/var filesystem "
121 "read-only after system/filesystem/minimal\n");
122 if (fs_remount("/var"))
123 log_framework(LOG_WARNING
, "/var "
124 "filesystem remount failed\n");
128 if ((ret
= fs_is_read_only("/var", &fsid
)) != 1) {
130 log_error(LOG_WARNING
, gettext("couldn't check status "
131 "of /var filesystem: %s\n"), strerror(errno
));
134 * Clear (dead) entries and record boot time.
137 utmpx_write_boottime();
140 * Reinitialize the logs to point to LOG_PREFIX_NORMAL.
145 * Poke init so it will create /var/run/initpipe.
147 if (zone_getattr(getzoneid(), ZONE_ATTR_INITPID
, &init_pid
,
148 sizeof (init_pid
)) != sizeof (init_pid
)) {
149 log_error(LOG_WARNING
, "Could not get pid of init: "
150 "%s.\n", strerror(errno
));
152 if (kill(init_pid
, SIGHUP
) != 0) {
156 log_error(LOG_WARNING
,
157 "Could not signal init: %s.\n",
163 bad_error("kill", errno
);
169 if ((ret
= fs_is_read_only("/etc/svc", &fsid
)) != 1) {
171 log_error(LOG_WARNING
, gettext("couldn't check status "
172 "of /etc/svc filesystem: %s\n"), strerror(errno
));
175 * Take pending snapshots and create a svc.startd instance.
177 (void) startd_thread_create(restarter_post_fsminimal_thread
,
183 special_single_post_online(void)
187 log_framework(LOG_DEBUG
, "special_single_post_online hook executed\n");
190 * Un-set the special reconfig reboot property.
192 r
= libscf_set_reconfig(0);
201 log_error(LOG_WARNING
, "Could not clear reconfiguration "
202 "property: %s.\n", strerror(r
));
206 bad_error("libscf_set_reconfig", r
);
209 if (booting_to_single_user
)
210 (void) startd_thread_create(single_user_thread
, NULL
);
213 static service_hook_assn_t special_svcs
[] = {
214 { "svc:/system/filesystem/root:default",
215 special_null_transition
,
216 special_fsroot_post_online
,
217 special_null_transition
},
218 { "svc:/system/filesystem/minimal:default",
219 special_null_transition
,
220 special_fsminimal_post_online
,
221 special_null_transition
},
222 { "svc:/milestone/single-user:default",
223 special_null_transition
,
224 special_single_post_online
,
225 special_null_transition
},
229 special_online_hooks_get(const char *fmri
, instance_hook_t
*pre_onp
,
230 instance_hook_t
*post_onp
, instance_hook_t
*post_offp
)
234 for (i
= 0; i
< sizeof (special_svcs
) / sizeof (service_hook_assn_t
);
236 if (strcmp(fmri
, special_svcs
[i
].sh_fmri
) == 0) {
237 *pre_onp
= special_svcs
[i
].sh_pre_online_hook
;
238 *post_onp
= special_svcs
[i
].sh_post_online_hook
;
239 *post_offp
= special_svcs
[i
].sh_post_offline_hook
;
243 *pre_onp
= *post_onp
= *post_offp
= special_null_transition
;