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) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 #ifndef _ZONEADMD_H 27 #define _ZONEADMD_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <libdladm.h> 34 35 /* 36 * Multi-threaded programs should avoid MT-unsafe library calls (i.e., any- 37 * thing which could try to acquire a user-level lock unprotected by an atfork 38 * handler) between fork(2) and exec(2). See the pthread_atfork(3THR) man 39 * page for details. In particular, we want to avoid calls to zerror() in 40 * such situations, as it calls setlocale(3c) which is susceptible to such 41 * problems. So instead we have the child use one of the special exit codes 42 * below when needed, and the parent look out for such possibilities and call 43 * zerror() there. 44 * 45 * Since 0, 1 and 2 are generally used for success, general error, and usage, 46 * we start with 3. 47 */ 48 #define ZEXIT_FORK 3 49 #define ZEXIT_EXEC 4 50 #define ZEXIT_ZONE_ENTER 5 51 52 #define DEVFSADM "devfsadm" 53 #define DEVFSADM_PATH "/usr/sbin/devfsadm" 54 55 #define EXEC_PREFIX "exec " 56 #define EXEC_LEN (strlen(EXEC_PREFIX)) 57 58 #define CLUSTER_BRAND_NAME "cluster" 59 #define LABELED_BRAND_NAME "labeled" 60 61 /* 0755 is the default directory mode. */ 62 #define DEFAULT_DIR_MODE \ 63 (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) 64 #define DEFAULT_DIR_USER -1 /* user ID for chown: -1 means don't change */ 65 #define DEFAULT_DIR_GROUP -1 /* grp ID for chown: -1 means don't change */ 66 67 68 typedef struct zlog { 69 FILE *logfile; /* file to log to */ 70 71 /* 72 * The following are used if logging to a buffer. 73 */ 74 char *log; /* remaining log */ 75 size_t loglen; /* size of remaining log */ 76 char *buf; /* underlying storage */ 77 size_t buflen; /* total len of 'buf' */ 78 char *locale; /* locale to use for gettext() */ 79 } zlog_t; 80 81 extern zlog_t logsys; 82 83 extern mutex_t lock; 84 extern mutex_t msglock; 85 extern boolean_t in_death_throes; 86 extern boolean_t bringup_failure_recovery; 87 extern char *zone_name; 88 extern char pool_name[MAXNAMELEN]; 89 extern char brand_name[MAXNAMELEN]; 90 extern char default_brand[MAXNAMELEN]; 91 extern char boot_args[BOOTARGS_MAX]; 92 extern char bad_boot_arg[BOOTARGS_MAX]; 93 extern boolean_t zone_isnative; 94 extern boolean_t zone_iscluster; 95 extern dladm_handle_t dld_handle; 96 97 extern void zerror(zlog_t *, boolean_t, const char *, ...); 98 extern char *localize_msg(char *locale, const char *msg); 99 100 /* 101 * Eventstream interfaces. 102 */ 103 typedef enum { 104 Z_EVT_NULL = 0, 105 Z_EVT_ZONE_BOOTING, 106 Z_EVT_ZONE_REBOOTING, 107 Z_EVT_ZONE_HALTED, 108 Z_EVT_ZONE_READIED, 109 Z_EVT_ZONE_UNINSTALLING, 110 Z_EVT_ZONE_BOOTFAILED, 111 Z_EVT_ZONE_BADARGS 112 } zone_evt_t; 113 114 extern int eventstream_init(); 115 extern void eventstream_write(zone_evt_t evt); 116 117 /* 118 * Zone mount styles. Boot is the standard mount we do when booting the zone, 119 * scratch is the standard scratch zone mount for upgrade and update is a 120 * variation on the scratch zone where we don't lofs mount the zone's /etc 121 * and /var back into the scratch zone so that we can then do an 122 * 'update on attach' within the scratch zone. 123 */ 124 typedef enum { 125 Z_MNT_BOOT = 0, 126 Z_MNT_SCRATCH, 127 Z_MNT_UPDATE 128 } zone_mnt_t; 129 130 /* 131 * Virtual platform interfaces. 132 */ 133 extern zoneid_t vplat_create(zlog_t *, zone_mnt_t); 134 extern int vplat_bringup(zlog_t *, zone_mnt_t, zoneid_t); 135 extern int vplat_teardown(zlog_t *, boolean_t, boolean_t); 136 extern int vplat_get_iptype(zlog_t *, zone_iptype_t *); 137 138 /* 139 * Filesystem mounting interfaces. 140 */ 141 extern int valid_mount_path(zlog_t *, const char *, const char *, 142 const char *, const char *); 143 extern int make_one_dir(zlog_t *, const char *, const char *, 144 mode_t, uid_t, gid_t); 145 extern void resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen); 146 147 /* 148 * Console subsystem routines. 149 */ 150 extern int init_console(zlog_t *); 151 extern void serve_console(zlog_t *); 152 153 /* 154 * Contract handling. 155 */ 156 extern int init_template(void); 157 158 /* 159 * Routine to manage child processes. 160 */ 161 extern int do_subproc(zlog_t *, char *, char **); 162 163 #ifdef __cplusplus 164 } 165 #endif 166 167 #endif /* _ZONEADMD_H */ 168