10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*238Sseizo * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/mman.h> 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <fcntl.h> 310Sstevel@tonic-gate #include <unistd.h> 320Sstevel@tonic-gate #include <errno.h> 330Sstevel@tonic-gate #include <stdio.h> 340Sstevel@tonic-gate #include <string.h> 350Sstevel@tonic-gate #include "rtc.h" 360Sstevel@tonic-gate #include "_crle.h" 370Sstevel@tonic-gate #include "msg.h" 380Sstevel@tonic-gate 390Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 400Sstevel@tonic-gate 410Sstevel@tonic-gate #define MAXNBKTS 10007 420Sstevel@tonic-gate 430Sstevel@tonic-gate static const int hashsize[] = { 440Sstevel@tonic-gate 3, 7, 13, 31, 53, 67, 83, 97, 450Sstevel@tonic-gate 101, 151, 211, 251, 307, 353, 401, 457, 503, 460Sstevel@tonic-gate 557, 601, 653, 701, 751, 809, 859, 907, 953, 470Sstevel@tonic-gate 1009, 1103, 1201, 1301, 1409, 1511, 1601, 1709, 1801, 480Sstevel@tonic-gate 1901, 2003, 2111, 2203, 2309, 2411, 2503, 2609, 2707, 490Sstevel@tonic-gate 2801, 2903, 3001, 3109, 3203, 3301, 3407, 3511, 3607, 500Sstevel@tonic-gate 3701, 3803, 3907, 4001, 5003, 6101, 7001, 8101, 9001, 510Sstevel@tonic-gate MAXNBKTS 520Sstevel@tonic-gate }; 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Generate a configuration file from the internal configuration information. 560Sstevel@tonic-gate * (very link-editor like). 570Sstevel@tonic-gate */ 58*238Sseizo int 590Sstevel@tonic-gate genconfig(Crle_desc * crle) 600Sstevel@tonic-gate { 610Sstevel@tonic-gate int ndx, bkt; 620Sstevel@tonic-gate size_t size, hashoff = 0, stroff = 0, objoff = 0; 630Sstevel@tonic-gate size_t diroff = 0, fileoff = 0, envoff = 0; 640Sstevel@tonic-gate size_t fltroff = 0, flteoff = 0; 650Sstevel@tonic-gate Addr addr; 660Sstevel@tonic-gate Rtc_head *head; 670Sstevel@tonic-gate Word *hashtbl, * hashbkt, * hashchn, hashbkts = 0; 680Sstevel@tonic-gate char *strtbl, *_strtbl; 690Sstevel@tonic-gate Rtc_obj *objtbl; 700Sstevel@tonic-gate Rtc_dir *dirtbl; 710Sstevel@tonic-gate Rtc_file *filetbl; 720Sstevel@tonic-gate Rtc_env *envtbl; 730Sstevel@tonic-gate Rtc_fltr *fltrtbl; 740Sstevel@tonic-gate Rtc_flte *fltetbl, * _fltetbl; 750Sstevel@tonic-gate Hash_tbl *stbl = crle->c_strtbl; 760Sstevel@tonic-gate Hash_ent *ent; 770Sstevel@tonic-gate 780Sstevel@tonic-gate /* 790Sstevel@tonic-gate * Establish the size of the configuration file. 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate size = S_ROUND(sizeof (Rtc_head), sizeof (Word)); 820Sstevel@tonic-gate 830Sstevel@tonic-gate if (crle->c_hashstrnum) { 840Sstevel@tonic-gate hashoff = size; 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * Increment the hash string number to account for an initial 880Sstevel@tonic-gate * null entry. Indexes start at 1 to simplify hash lookup. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate crle->c_hashstrnum++; 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* 930Sstevel@tonic-gate * Determine the hash table size. Establish the number of 940Sstevel@tonic-gate * buckets from the number of strings, the number of chains is 950Sstevel@tonic-gate * equivalent to the number of objects, and two entries for the 960Sstevel@tonic-gate * nbucket and nchain entries. 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate for (ndx = 0; ndx < (sizeof (hashsize) / sizeof (int)); ndx++) { 990Sstevel@tonic-gate if (crle->c_hashstrnum > hashsize[ndx]) 1000Sstevel@tonic-gate continue; 1010Sstevel@tonic-gate hashbkts = hashsize[ndx]; 1020Sstevel@tonic-gate break; 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate if (hashbkts == 0) 1050Sstevel@tonic-gate hashbkts = MAXNBKTS; 1060Sstevel@tonic-gate size += ((2 + hashbkts + crle->c_hashstrnum) * sizeof (Word)); 1070Sstevel@tonic-gate size = S_ROUND(size, sizeof (Lword)); 1080Sstevel@tonic-gate objoff = size; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* 1110Sstevel@tonic-gate * Add the object table size (account for an 8-byte alignment 1120Sstevel@tonic-gate * requirement for each object). 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate size += (crle->c_hashstrnum * 1150Sstevel@tonic-gate S_ROUND(sizeof (Rtc_obj), sizeof (Lword))); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Add the file descriptor arrays. 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate fileoff = size; 1210Sstevel@tonic-gate size += S_ROUND((crle->c_filenum * sizeof (Rtc_file)), 1220Sstevel@tonic-gate sizeof (Word)); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Add the directory descriptor array. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate diroff = size; 1280Sstevel@tonic-gate size += S_ROUND((crle->c_dirnum * sizeof (Rtc_dir)), 1290Sstevel@tonic-gate sizeof (Word)); 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Add any environment string array (insure zero last entry). 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate if (crle->c_envnum) { 1360Sstevel@tonic-gate envoff = size; 1370Sstevel@tonic-gate size += S_ROUND(((crle->c_envnum + 1) * sizeof (Rtc_env)), 1380Sstevel@tonic-gate sizeof (Word)); 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Add any filter/filtee association arrays (insure zero last entry for 1430Sstevel@tonic-gate * the filter array, the filtee arrays are already accounted for). 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate if (crle->c_fltrnum) { 1460Sstevel@tonic-gate fltroff = size; 1470Sstevel@tonic-gate size += S_ROUND(((crle->c_fltrnum + 1) * sizeof (Rtc_fltr)), 1480Sstevel@tonic-gate sizeof (Word)); 1490Sstevel@tonic-gate flteoff = size; 1500Sstevel@tonic-gate size += S_ROUND((crle->c_fltenum * sizeof (Rtc_flte)), 1510Sstevel@tonic-gate sizeof (Word)); 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * Add the string table size (this may contain library and/or secure 1560Sstevel@tonic-gate * path strings, in addition to any directory/file strings). 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate if (crle->c_strsize) { 1590Sstevel@tonic-gate stroff = size; 1600Sstevel@tonic-gate size += S_ROUND(crle->c_strsize, sizeof (Word)); 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Truncate our temporary file now that we know its size and map it. 1650Sstevel@tonic-gate */ 1660Sstevel@tonic-gate if (ftruncate(crle->c_tempfd, size) == -1) { 1670Sstevel@tonic-gate int err = errno; 1680Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 1690Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 1700Sstevel@tonic-gate (void) close(crle->c_tempfd); 1710Sstevel@tonic-gate return (1); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate if ((addr = (Addr)mmap(0, size, (PROT_READ | PROT_WRITE), MAP_SHARED, 1740Sstevel@tonic-gate crle->c_tempfd, 0)) == (Addr)-1) { 1750Sstevel@tonic-gate int err = errno; 1760Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), 1770Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 1780Sstevel@tonic-gate (void) close(crle->c_tempfd); 1790Sstevel@tonic-gate return (1); 1800Sstevel@tonic-gate } 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * Save the mapped files info for possible dldump(3dl) updates. 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate crle->c_tempaddr = addr; 1860Sstevel@tonic-gate crle->c_tempsize = size; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* 1890Sstevel@tonic-gate * Establish the real address of each of the structures within the file. 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate head = (Rtc_head *)addr; 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate head->ch_hash = hashoff; 1940Sstevel@tonic-gate /* LINTED */ 1950Sstevel@tonic-gate hashtbl = (Word *)((char *)head->ch_hash + addr); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate head->ch_obj = objoff; 1980Sstevel@tonic-gate /* LINTED */ 1990Sstevel@tonic-gate objtbl = (Rtc_obj *)((char *)head->ch_obj + addr); 2000Sstevel@tonic-gate objtbl = (Rtc_obj *)S_ROUND((int)(objtbl + 1), sizeof (Lword)); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate head->ch_file = fileoff; 2030Sstevel@tonic-gate /* LINTED */ 2040Sstevel@tonic-gate filetbl = (Rtc_file *)((char *)head->ch_file + addr); 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate head->ch_dir = diroff; 2070Sstevel@tonic-gate /* LINTED */ 2080Sstevel@tonic-gate dirtbl = (Rtc_dir *)((char *)head->ch_dir + addr); 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate head->ch_env = envoff; 2110Sstevel@tonic-gate /* LINTED */ 2120Sstevel@tonic-gate envtbl = (Rtc_env *)((char *)head->ch_env + addr); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate head->ch_fltr = fltroff; 2150Sstevel@tonic-gate /* LINTED */ 2160Sstevel@tonic-gate fltrtbl = (Rtc_fltr *)((char *)head->ch_fltr + addr); 2170Sstevel@tonic-gate head->ch_flte = flteoff; 2180Sstevel@tonic-gate /* LINTED */ 2190Sstevel@tonic-gate fltetbl = _fltetbl = (Rtc_flte *)((char *)head->ch_flte + addr); 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate head->ch_str = stroff; 2220Sstevel@tonic-gate strtbl = _strtbl = (char *)((char *)head->ch_str + addr); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate /* 2250Sstevel@tonic-gate * Fill in additional basic header information. 2260Sstevel@tonic-gate */ 2270Sstevel@tonic-gate head->ch_version = RTC_VER_CURRENT; 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate if (crle->c_flags & CRLE_ALTER) 2300Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_ALTER; 2310Sstevel@tonic-gate if (crle->c_flags & CRLE_DUMP) { 2320Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_IGNORE; 2330Sstevel@tonic-gate head->ch_dlflags = crle->c_dlflags; 2340Sstevel@tonic-gate } 2350Sstevel@tonic-gate if (crle->c_class == ELFCLASS64) 2360Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_64; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 2390Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_UPM; 2400Sstevel@tonic-gate #endif 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * If we have a hash table then there are directory and file entries 2430Sstevel@tonic-gate * to process. 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate if (crle->c_hashstrnum) { 2460Sstevel@tonic-gate hashtbl[0] = hashbkts; 2470Sstevel@tonic-gate hashtbl[1] = crle->c_hashstrnum; 2480Sstevel@tonic-gate hashbkt = &hashtbl[2]; 2490Sstevel@tonic-gate hashchn = &hashtbl[2 + hashbkts]; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * Insure all hash chain and directory/filename table entries 2530Sstevel@tonic-gate * are cleared. 2540Sstevel@tonic-gate */ 2550Sstevel@tonic-gate (void) memset(hashchn, 0, (crle->c_hashstrnum * sizeof (Word))); 2560Sstevel@tonic-gate (void) memset(dirtbl, 0, (strtbl - (char *)dirtbl)); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * Loop through the current string table list inspecting only 2600Sstevel@tonic-gate * directories. 2610Sstevel@tonic-gate */ 2620Sstevel@tonic-gate for (ndx = 1, bkt = 0; bkt < stbl->t_size; bkt++) { 2630Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 2640Sstevel@tonic-gate Word hashval; 2650Sstevel@tonic-gate Hash_obj *obj = ent->e_obj; 2660Sstevel@tonic-gate char *dir = (char *)ent->e_key; 2670Sstevel@tonic-gate Rtc_dir *_dirtbl; 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate /* 2700Sstevel@tonic-gate * Skip any empty and non-directory entries. 2710Sstevel@tonic-gate */ 2720Sstevel@tonic-gate if ((obj == 0) || 2730Sstevel@tonic-gate ((obj->o_flags & RTC_OBJ_DIRENT) == 0)) 2740Sstevel@tonic-gate continue; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* 2770Sstevel@tonic-gate * Assign basic object attributes. 2780Sstevel@tonic-gate */ 2790Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 2800Sstevel@tonic-gate objtbl->co_id = ent->e_id; 2810Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 2820Sstevel@tonic-gate objtbl->co_info = obj->o_info; 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate ent->e_cobj = objtbl; 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* 2870Sstevel@tonic-gate * Assign the directory name (from its key), 2880Sstevel@tonic-gate * and copy its name to the string table. 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate objtbl->co_name = (Addr)(_strtbl - strtbl); 2910Sstevel@tonic-gate (void) strcpy(_strtbl, dir); 2920Sstevel@tonic-gate _strtbl += strlen(dir) + 1; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /* 2950Sstevel@tonic-gate * Establish an entry in the directory table and 2960Sstevel@tonic-gate * reserve space for its associated filename 2970Sstevel@tonic-gate * entries (note, we add a trailing null file 2980Sstevel@tonic-gate * entry to simplify later inspection of the 2990Sstevel@tonic-gate * final configuration file. 3000Sstevel@tonic-gate */ 3010Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 3020Sstevel@tonic-gate _dirtbl->cd_file = 3030Sstevel@tonic-gate (Word)((char *)filetbl - addr); 3040Sstevel@tonic-gate _dirtbl->cd_obj = 3050Sstevel@tonic-gate (Word)((char *)objtbl - addr); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* LINTED */ 3080Sstevel@tonic-gate filetbl = (Rtc_file *)((char *)filetbl + 3090Sstevel@tonic-gate ((ent->e_cnt + 1) * sizeof (Rtc_file))); 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate /* 3120Sstevel@tonic-gate * Add this object to the hash table. 3130Sstevel@tonic-gate */ 3140Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 3150Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 3160Sstevel@tonic-gate hashbkt[hashval] = ndx++; 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate /* 3190Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 3200Sstevel@tonic-gate * falls on an 8-byte boundary). 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate objtbl = (Rtc_obj *)S_ROUND((int)(objtbl + 1), 3230Sstevel@tonic-gate sizeof (Lword)); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* 3280Sstevel@tonic-gate * Now collect all pathnames. These are typically full 3290Sstevel@tonic-gate * pathnames, but may also be relative. Simple filenames are 3300Sstevel@tonic-gate * recorded as offsets into these pathnames, thus we need to 3310Sstevel@tonic-gate * establish the new pathname first. 3320Sstevel@tonic-gate */ 3330Sstevel@tonic-gate for (bkt = 0; bkt < stbl->t_size; bkt++) { 3340Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 3350Sstevel@tonic-gate Word hashval; 3360Sstevel@tonic-gate Hash_obj *obj = ent->e_obj; 3370Sstevel@tonic-gate char *file = (char *)ent->e_key; 3380Sstevel@tonic-gate char *_str; 3390Sstevel@tonic-gate Rtc_dir *_dirtbl; 3400Sstevel@tonic-gate Rtc_file *_filetbl; 3410Sstevel@tonic-gate int _id; 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* 3440Sstevel@tonic-gate * Skip empty and directory entries, and any 3450Sstevel@tonic-gate * simple filename entries. 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate if ((obj == 0) || 3480Sstevel@tonic-gate (obj->o_flags & RTC_OBJ_DIRENT) || 3490Sstevel@tonic-gate (ent->e_off)) 3500Sstevel@tonic-gate continue; 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate /* 3530Sstevel@tonic-gate * Assign basic object attributes. 3540Sstevel@tonic-gate */ 3550Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 3560Sstevel@tonic-gate objtbl->co_id = ent->e_id; 3570Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 3580Sstevel@tonic-gate objtbl->co_info = obj->o_info; 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate ent->e_cobj = objtbl; 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate /* 3630Sstevel@tonic-gate * Assign the file name (from its key), 3640Sstevel@tonic-gate * and copy its name to the string table. 3650Sstevel@tonic-gate */ 3660Sstevel@tonic-gate objtbl->co_name = (Addr)(_strtbl - strtbl); 3670Sstevel@tonic-gate (void) strcpy(_strtbl, file); 3680Sstevel@tonic-gate _strtbl += strlen(file) + 1; 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate /* 3710Sstevel@tonic-gate * Add this file to its associated directory. 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 3740Sstevel@tonic-gate /* LINTED */ 3750Sstevel@tonic-gate _filetbl = (Rtc_file *) 3760Sstevel@tonic-gate ((char *)_dirtbl->cd_file + addr); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate _id = --ent->e_dir->e_cnt; 3790Sstevel@tonic-gate _filetbl[_id].cf_obj = 3800Sstevel@tonic-gate (Word)((char *)objtbl - addr); 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * If object has an alternative, record it in 3840Sstevel@tonic-gate * the string table and assign the alternate 3850Sstevel@tonic-gate * pointer. The new alternative offset is 3860Sstevel@tonic-gate * retained for reuse in other filename entries. 3870Sstevel@tonic-gate */ 3880Sstevel@tonic-gate if ((objtbl->co_flags & RTC_OBJ_ALTER) && 3890Sstevel@tonic-gate (obj->o_calter == 0)) { 3900Sstevel@tonic-gate _str = obj->o_alter; 3910Sstevel@tonic-gate objtbl->co_alter = obj->o_calter = 3920Sstevel@tonic-gate (Addr)(_strtbl - strtbl); 3930Sstevel@tonic-gate (void) strcpy(_strtbl, _str); 3940Sstevel@tonic-gate _strtbl += strlen(_str) + 1; 3950Sstevel@tonic-gate } else 3960Sstevel@tonic-gate objtbl->co_alter = obj->o_calter; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /* 3990Sstevel@tonic-gate * If object identifies the specific application 4000Sstevel@tonic-gate * for which this cache is relevant, record it 4010Sstevel@tonic-gate * in the header. 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate if ((objtbl->co_flags & 4040Sstevel@tonic-gate (RTC_OBJ_APP | RTC_OBJ_REALPTH)) == 4050Sstevel@tonic-gate (RTC_OBJ_APP | RTC_OBJ_REALPTH)) 4060Sstevel@tonic-gate head->ch_app = _filetbl[_id].cf_obj; 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate /* 4090Sstevel@tonic-gate * Add this object to the hash table. 4100Sstevel@tonic-gate */ 4110Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 4120Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 4130Sstevel@tonic-gate hashbkt[hashval] = ndx++; 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 4170Sstevel@tonic-gate * falls on an 8-byte boundary). 4180Sstevel@tonic-gate */ 4190Sstevel@tonic-gate objtbl = (Rtc_obj *)S_ROUND((int)(objtbl + 1), 4200Sstevel@tonic-gate sizeof (Lword)); 4210Sstevel@tonic-gate } 4220Sstevel@tonic-gate } 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate /* 4250Sstevel@tonic-gate * Finally pick off any simple filenames. 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate for (bkt = 0; bkt < stbl->t_size; bkt++) { 4280Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 4290Sstevel@tonic-gate Word hashval; 4300Sstevel@tonic-gate Hash_obj * obj = ent->e_obj; 4310Sstevel@tonic-gate Rtc_dir * _dirtbl; 4320Sstevel@tonic-gate Rtc_file * _filetbl; 4330Sstevel@tonic-gate int _id; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate /* 4360Sstevel@tonic-gate * Skip everything except simple filenames. 4370Sstevel@tonic-gate */ 4380Sstevel@tonic-gate if (ent->e_off == 0) 4390Sstevel@tonic-gate continue; 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* 4420Sstevel@tonic-gate * Assign basic object attributes. 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 4450Sstevel@tonic-gate objtbl->co_id = ent->e_id; 4460Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 4470Sstevel@tonic-gate objtbl->co_info = obj->o_info; 4480Sstevel@tonic-gate objtbl->co_alter = obj->o_calter; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate ent->e_cobj = objtbl; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate /* 4530Sstevel@tonic-gate * Assign the file name from its full name. 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate objtbl->co_name = (Addr)((char *) 4560Sstevel@tonic-gate ent->e_path->e_cobj->co_name + ent->e_off); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* 4590Sstevel@tonic-gate * Add this file to its associated directory. 4600Sstevel@tonic-gate */ 4610Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 4620Sstevel@tonic-gate /* LINTED */ 4630Sstevel@tonic-gate _filetbl = (Rtc_file *) 4640Sstevel@tonic-gate ((char *)_dirtbl->cd_file + addr); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate _id = --ent->e_dir->e_cnt; 4670Sstevel@tonic-gate _filetbl[_id].cf_obj = 4680Sstevel@tonic-gate (Word)((char *)objtbl - addr); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * Add this object to the hash table. 4720Sstevel@tonic-gate */ 4730Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 4740Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 4750Sstevel@tonic-gate hashbkt[hashval] = ndx++; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* 4780Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 4790Sstevel@tonic-gate * falls on an 8-byte boundary). 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate objtbl = (Rtc_obj *)S_ROUND((int)(objtbl + 1), 4820Sstevel@tonic-gate sizeof (Lword)); 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* 4880Sstevel@tonic-gate * Add any library, or secure path definitions. 4890Sstevel@tonic-gate */ 4900Sstevel@tonic-gate if (crle->c_edlibpath) { 4910Sstevel@tonic-gate head->ch_edlibpath = head->ch_str + (_strtbl - strtbl); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_edlibpath); 4940Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_edlibpath) + 1; 4950Sstevel@tonic-gate } else 4960Sstevel@tonic-gate head->ch_edlibpath = 0; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate if (crle->c_adlibpath) { 4990Sstevel@tonic-gate head->ch_adlibpath = head->ch_str + (_strtbl - strtbl); 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_adlibpath); 5020Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_adlibpath) + 1; 5030Sstevel@tonic-gate } else 5040Sstevel@tonic-gate head->ch_adlibpath = 0; 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate if (crle->c_eslibpath) { 5070Sstevel@tonic-gate head->ch_eslibpath = head->ch_str + (_strtbl - strtbl); 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_eslibpath); 5100Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_eslibpath) + 1; 5110Sstevel@tonic-gate } else 5120Sstevel@tonic-gate head->ch_eslibpath = 0; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate if (crle->c_aslibpath) { 5150Sstevel@tonic-gate head->ch_aslibpath = head->ch_str + (_strtbl - strtbl); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_aslibpath); 5180Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_aslibpath) + 1; 5190Sstevel@tonic-gate } else 5200Sstevel@tonic-gate head->ch_aslibpath = 0; 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /* 5230Sstevel@tonic-gate * Add any environment variable entries. 5240Sstevel@tonic-gate */ 5250Sstevel@tonic-gate if (crle->c_envnum) { 5260Sstevel@tonic-gate Env_desc * env; 5270Sstevel@tonic-gate Listnode * lnp; 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate for (LIST_TRAVERSE(&(crle->c_env), lnp, env)) { 5300Sstevel@tonic-gate envtbl->env_str = head->ch_str + (_strtbl - strtbl); 5310Sstevel@tonic-gate envtbl->env_flags = env->e_flags; 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate (void) strcpy(_strtbl, env->e_str); 5340Sstevel@tonic-gate _strtbl += env->e_totsz; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate envtbl++; 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate envtbl->env_str = 0; 5390Sstevel@tonic-gate envtbl->env_flags = 0; 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate /* 5430Sstevel@tonic-gate * Add any filter/filtee association entries. 5440Sstevel@tonic-gate */ 5450Sstevel@tonic-gate if (crle->c_fltrnum) { 5460Sstevel@tonic-gate Flt_desc * flt; 5470Sstevel@tonic-gate Listnode * lnp1; 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate for (LIST_TRAVERSE(&(crle->c_flt), lnp1, flt)) { 5500Sstevel@tonic-gate Hash_ent * flte; 5510Sstevel@tonic-gate Listnode * lnp2; 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate /* 5540Sstevel@tonic-gate * Establish the filter name, and filtee string, as 5550Sstevel@tonic-gate * offsets into the configuration files string table. 5560Sstevel@tonic-gate * Establish the filtee as the offset into the filtee 5570Sstevel@tonic-gate * table. 5580Sstevel@tonic-gate */ 5590Sstevel@tonic-gate fltrtbl->fr_filter = flt->f_fent->e_cobj->co_name; 5600Sstevel@tonic-gate fltrtbl->fr_string = _strtbl - strtbl; 5610Sstevel@tonic-gate (void) strcpy(_strtbl, flt->f_str); 5620Sstevel@tonic-gate _strtbl += flt->f_strsz; 5630Sstevel@tonic-gate fltrtbl->fr_filtee = ((Word)_fltetbl - (Word)fltetbl); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate for (LIST_TRAVERSE(&(flt->f_filtee), lnp2, flte)) { 5660Sstevel@tonic-gate /* 5670Sstevel@tonic-gate * Establish the filtee name as the offset into 5680Sstevel@tonic-gate * the configuration files string table. 5690Sstevel@tonic-gate */ 5700Sstevel@tonic-gate _fltetbl->fe_filtee = flte->e_cobj->co_name; 5710Sstevel@tonic-gate _fltetbl++; 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate _fltetbl->fe_filtee = 0; 5740Sstevel@tonic-gate _fltetbl++, fltrtbl++; 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate fltrtbl->fr_filter = 0; 5770Sstevel@tonic-gate fltrtbl->fr_filtee = 0; 5780Sstevel@tonic-gate } 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate /* 5810Sstevel@tonic-gate * Flush everything out. 5820Sstevel@tonic-gate */ 5830Sstevel@tonic-gate (void) close(crle->c_tempfd); 5840Sstevel@tonic-gate if (msync((void *)addr, size, MS_ASYNC) == -1) { 5850Sstevel@tonic-gate int err = errno; 5860Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 5870Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 5880Sstevel@tonic-gate return (1); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate return (0); 5920Sstevel@tonic-gate } 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate /* 5950Sstevel@tonic-gate * Update a configuration file. If dldump()'ed images have been created then 5960Sstevel@tonic-gate * the memory reservation of those images is added to the configuration file. 5970Sstevel@tonic-gate * The temporary file is then moved into its final resting place. 5980Sstevel@tonic-gate */ 599*238Sseizo int 6000Sstevel@tonic-gate updateconfig(Crle_desc * crle) 6010Sstevel@tonic-gate { 6020Sstevel@tonic-gate Rtc_head * head = (Rtc_head *)crle->c_tempaddr; 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate if (crle->c_flags & CRLE_DUMP) { 6050Sstevel@tonic-gate head->ch_cnflags &= ~RTC_HDR_IGNORE; 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate if (msync((void *)crle->c_tempaddr, crle->c_tempsize, 6080Sstevel@tonic-gate MS_ASYNC) == -1) { 6090Sstevel@tonic-gate int err = errno; 6100Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 6110Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 6120Sstevel@tonic-gate return (1); 6130Sstevel@tonic-gate } 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate /* 6170Sstevel@tonic-gate * If an original configuration file exists, remove it. 6180Sstevel@tonic-gate */ 6190Sstevel@tonic-gate if (crle->c_flags & CRLE_EXISTS) 6200Sstevel@tonic-gate (void) unlink(crle->c_confil); 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate /* 6230Sstevel@tonic-gate * Move the config file to its final resting place. If the two files 6240Sstevel@tonic-gate * exist on the same filesystem a rename is sufficient. 6250Sstevel@tonic-gate */ 6260Sstevel@tonic-gate if (crle->c_flags & CRLE_DIFFDEV) { 6270Sstevel@tonic-gate int fd; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate if ((fd = open(crle->c_confil, (O_RDWR | O_CREAT | O_TRUNC), 6300Sstevel@tonic-gate 0666)) == -1) { 6310Sstevel@tonic-gate int err = errno; 6320Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), 6330Sstevel@tonic-gate crle->c_name, crle->c_confil, strerror(err)); 6340Sstevel@tonic-gate return (1); 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate if (write(fd, (void *)crle->c_tempaddr, crle->c_tempsize) != 6370Sstevel@tonic-gate crle->c_tempsize) { 6380Sstevel@tonic-gate int err = errno; 6390Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_WRITE), 6400Sstevel@tonic-gate crle->c_name, crle->c_confil, strerror(err)); 6410Sstevel@tonic-gate return (1); 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate (void) close(fd); 6440Sstevel@tonic-gate (void) unlink(crle->c_tempname); 6450Sstevel@tonic-gate } else 6460Sstevel@tonic-gate (void) rename(crle->c_tempname, crle->c_confil); 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate return (0); 6490Sstevel@tonic-gate } 650