17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5c13de8f6Sab196087 * Common Development and Distribution License (the "License"). 6c13de8f6Sab196087 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*57ef7aa9SRod Evans * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/mman.h> 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <fcntl.h> 297c478bd9Sstevel@tonic-gate #include <unistd.h> 307c478bd9Sstevel@tonic-gate #include <errno.h> 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include "rtc.h" 347c478bd9Sstevel@tonic-gate #include "_crle.h" 357c478bd9Sstevel@tonic-gate #include "msg.h" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #define MAXNBKTS 10007 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate static const int hashsize[] = { 417c478bd9Sstevel@tonic-gate 3, 7, 13, 31, 53, 67, 83, 97, 427c478bd9Sstevel@tonic-gate 101, 151, 211, 251, 307, 353, 401, 457, 503, 437c478bd9Sstevel@tonic-gate 557, 601, 653, 701, 751, 809, 859, 907, 953, 447c478bd9Sstevel@tonic-gate 1009, 1103, 1201, 1301, 1409, 1511, 1601, 1709, 1801, 457c478bd9Sstevel@tonic-gate 1901, 2003, 2111, 2203, 2309, 2411, 2503, 2609, 2707, 467c478bd9Sstevel@tonic-gate 2801, 2903, 3001, 3109, 3203, 3301, 3407, 3511, 3607, 477c478bd9Sstevel@tonic-gate 3701, 3803, 3907, 4001, 5003, 6101, 7001, 8101, 9001, 487c478bd9Sstevel@tonic-gate MAXNBKTS 497c478bd9Sstevel@tonic-gate }; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * Generate a configuration file from the internal configuration information. 537c478bd9Sstevel@tonic-gate * (very link-editor like). 547c478bd9Sstevel@tonic-gate */ 55b3fbe5e6Sseizo int 567c478bd9Sstevel@tonic-gate genconfig(Crle_desc *crle) 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate int ndx, bkt; 597c478bd9Sstevel@tonic-gate size_t size, hashoff = 0, stroff = 0, objoff = 0; 607c478bd9Sstevel@tonic-gate size_t diroff = 0, fileoff = 0, envoff = 0; 617c478bd9Sstevel@tonic-gate size_t fltroff = 0, flteoff = 0; 627c478bd9Sstevel@tonic-gate Addr addr; 63c13de8f6Sab196087 Rtc_id *id; 647c478bd9Sstevel@tonic-gate Rtc_head *head; 657c478bd9Sstevel@tonic-gate Word *hashtbl, *hashbkt, *hashchn, hashbkts = 0; 667c478bd9Sstevel@tonic-gate char *strtbl, *_strtbl; 677c478bd9Sstevel@tonic-gate Rtc_obj *objtbl; 687c478bd9Sstevel@tonic-gate Rtc_dir *dirtbl; 697c478bd9Sstevel@tonic-gate Rtc_file *filetbl; 707c478bd9Sstevel@tonic-gate Rtc_env *envtbl; 717c478bd9Sstevel@tonic-gate Rtc_fltr *fltrtbl; 727c478bd9Sstevel@tonic-gate Rtc_flte *fltetbl, * _fltetbl; 737c478bd9Sstevel@tonic-gate Hash_tbl *stbl = crle->c_strtbl; 747c478bd9Sstevel@tonic-gate Hash_ent *ent; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * Establish the size of the configuration file. 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate size = S_ROUND(sizeof (Rtc_head), sizeof (Word)); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate if (crle->c_hashstrnum) { 827c478bd9Sstevel@tonic-gate hashoff = size; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Increment the hash string number to account for an initial 867c478bd9Sstevel@tonic-gate * null entry. Indexes start at 1 to simplify hash lookup. 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate crle->c_hashstrnum++; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Determine the hash table size. Establish the number of 927c478bd9Sstevel@tonic-gate * buckets from the number of strings, the number of chains is 937c478bd9Sstevel@tonic-gate * equivalent to the number of objects, and two entries for the 947c478bd9Sstevel@tonic-gate * nbucket and nchain entries. 957c478bd9Sstevel@tonic-gate */ 967c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < (sizeof (hashsize) / sizeof (int)); ndx++) { 977c478bd9Sstevel@tonic-gate if (crle->c_hashstrnum > hashsize[ndx]) 987c478bd9Sstevel@tonic-gate continue; 997c478bd9Sstevel@tonic-gate hashbkts = hashsize[ndx]; 1007c478bd9Sstevel@tonic-gate break; 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate if (hashbkts == 0) 1037c478bd9Sstevel@tonic-gate hashbkts = MAXNBKTS; 1047c478bd9Sstevel@tonic-gate size += ((2 + hashbkts + crle->c_hashstrnum) * sizeof (Word)); 1057c478bd9Sstevel@tonic-gate size = S_ROUND(size, sizeof (Lword)); 1067c478bd9Sstevel@tonic-gate objoff = size; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * Add the object table size (account for an 8-byte alignment 1107c478bd9Sstevel@tonic-gate * requirement for each object). 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate size += (crle->c_hashstrnum * 1137c478bd9Sstevel@tonic-gate S_ROUND(sizeof (Rtc_obj), sizeof (Lword))); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * Add the file descriptor arrays. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate fileoff = size; 1197c478bd9Sstevel@tonic-gate size += S_ROUND((crle->c_filenum * sizeof (Rtc_file)), 1207c478bd9Sstevel@tonic-gate sizeof (Word)); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * Add the directory descriptor array. 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate diroff = size; 1267c478bd9Sstevel@tonic-gate size += S_ROUND((crle->c_dirnum * sizeof (Rtc_dir)), 1277c478bd9Sstevel@tonic-gate sizeof (Word)); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Add any environment string array (insure zero last entry). 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate if (crle->c_envnum) { 1347c478bd9Sstevel@tonic-gate envoff = size; 1357c478bd9Sstevel@tonic-gate size += S_ROUND(((crle->c_envnum + 1) * sizeof (Rtc_env)), 1367c478bd9Sstevel@tonic-gate sizeof (Word)); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * Add any filter/filtee association arrays (insure zero last entry for 1417c478bd9Sstevel@tonic-gate * the filter array, the filtee arrays are already accounted for). 1427c478bd9Sstevel@tonic-gate */ 1437c478bd9Sstevel@tonic-gate if (crle->c_fltrnum) { 1447c478bd9Sstevel@tonic-gate fltroff = size; 1457c478bd9Sstevel@tonic-gate size += S_ROUND(((crle->c_fltrnum + 1) * sizeof (Rtc_fltr)), 1467c478bd9Sstevel@tonic-gate sizeof (Word)); 1477c478bd9Sstevel@tonic-gate flteoff = size; 1487c478bd9Sstevel@tonic-gate size += S_ROUND((crle->c_fltenum * sizeof (Rtc_flte)), 1497c478bd9Sstevel@tonic-gate sizeof (Word)); 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Add the string table size (this may contain library and/or secure 1547c478bd9Sstevel@tonic-gate * path strings, in addition to any directory/file strings). 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate if (crle->c_strsize) { 1577c478bd9Sstevel@tonic-gate stroff = size; 1587c478bd9Sstevel@tonic-gate size += S_ROUND(crle->c_strsize, sizeof (Word)); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 161c13de8f6Sab196087 /* Account for addition of Rtc_id block at the start */ 162c13de8f6Sab196087 if (crle->c_flags & CRLE_ADDID) 163c13de8f6Sab196087 size += sizeof (Rtc_id); 164c13de8f6Sab196087 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * Truncate our temporary file now that we know its size and map it. 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate if (ftruncate(crle->c_tempfd, size) == -1) { 1697c478bd9Sstevel@tonic-gate int err = errno; 1707c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 1717c478bd9Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 1727c478bd9Sstevel@tonic-gate (void) close(crle->c_tempfd); 1737c478bd9Sstevel@tonic-gate return (1); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate if ((addr = (Addr)mmap(0, size, (PROT_READ | PROT_WRITE), MAP_SHARED, 1767c478bd9Sstevel@tonic-gate crle->c_tempfd, 0)) == (Addr)-1) { 1777c478bd9Sstevel@tonic-gate int err = errno; 1787c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), 1797c478bd9Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 1807c478bd9Sstevel@tonic-gate (void) close(crle->c_tempfd); 1817c478bd9Sstevel@tonic-gate return (1); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * Save the mapped files info for possible dldump(3dl) updates. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate crle->c_tempaddr = addr; 1887c478bd9Sstevel@tonic-gate crle->c_tempsize = size; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 191c13de8f6Sab196087 * Rtc_id goes at the top, followed by the Rtc_head. We base 192c13de8f6Sab196087 * all offset calculations relative to Rtc_head, not from 193c13de8f6Sab196087 * the top of the file. This eases backwards compatability to 194c13de8f6Sab196087 * older versons that lacked the Rtc_id at the top. 1957c478bd9Sstevel@tonic-gate */ 196c13de8f6Sab196087 if (crle->c_flags & CRLE_ADDID) { 197c13de8f6Sab196087 /* The contents of the Rtc_id are all known at compile time */ 198c13de8f6Sab196087 static const Rtc_id id_template = { 199c13de8f6Sab196087 RTC_ID_MAG0, RTC_ID_MAG1, RTC_ID_MAG2, RTC_ID_MAG3, 200c13de8f6Sab196087 M_CLASS, M_DATA, M_MACH, 201c13de8f6Sab196087 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; 202c13de8f6Sab196087 203c13de8f6Sab196087 id = (Rtc_id *) addr; 204c13de8f6Sab196087 *id = id_template; /* Fill in the Rtc_id data */ 205c13de8f6Sab196087 addr += sizeof (Rtc_id); 206c13de8f6Sab196087 } else { 207c13de8f6Sab196087 id = NULL; 208c13de8f6Sab196087 } 209c13de8f6Sab196087 crle->c_tempheadaddr = addr; 2107c478bd9Sstevel@tonic-gate head = (Rtc_head *)addr; 2117c478bd9Sstevel@tonic-gate 212c13de8f6Sab196087 /* 213c13de8f6Sab196087 * Establish the real address of each of the structures within the file. 214c13de8f6Sab196087 */ 2157c478bd9Sstevel@tonic-gate head->ch_hash = hashoff; 2167c478bd9Sstevel@tonic-gate /* LINTED */ 217c13de8f6Sab196087 hashtbl = (Word *)(CAST_PTRINT(char *, head->ch_hash) + addr); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate head->ch_obj = objoff; 2207c478bd9Sstevel@tonic-gate /* LINTED */ 221c13de8f6Sab196087 objtbl = (Rtc_obj *)(CAST_PTRINT(char *, head->ch_obj) + addr); 222c13de8f6Sab196087 objtbl = (Rtc_obj *)S_ROUND((uintptr_t)(objtbl + 1), sizeof (Lword)); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate head->ch_file = fileoff; 2257c478bd9Sstevel@tonic-gate /* LINTED */ 226c13de8f6Sab196087 filetbl = (Rtc_file *)(CAST_PTRINT(char *, head->ch_file) + addr); 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate head->ch_dir = diroff; 2297c478bd9Sstevel@tonic-gate /* LINTED */ 230c13de8f6Sab196087 dirtbl = (Rtc_dir *)(CAST_PTRINT(char *, head->ch_dir) + addr); 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate head->ch_env = envoff; 2337c478bd9Sstevel@tonic-gate /* LINTED */ 234c13de8f6Sab196087 envtbl = (Rtc_env *)(CAST_PTRINT(char *, head->ch_env) + addr); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate head->ch_fltr = fltroff; 2377c478bd9Sstevel@tonic-gate /* LINTED */ 238c13de8f6Sab196087 fltrtbl = (Rtc_fltr *)(CAST_PTRINT(char *, head->ch_fltr) + addr); 2397c478bd9Sstevel@tonic-gate head->ch_flte = flteoff; 2407c478bd9Sstevel@tonic-gate /* LINTED */ 241*57ef7aa9SRod Evans fltetbl = _fltetbl = (Rtc_flte *)(CAST_PTRINT(char *, head->ch_flte) + 242*57ef7aa9SRod Evans addr); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate head->ch_str = stroff; 245c13de8f6Sab196087 strtbl = _strtbl = (char *)(CAST_PTRINT(char *, head->ch_str) + addr); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * Fill in additional basic header information. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate head->ch_version = RTC_VER_CURRENT; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_ALTER) 2537c478bd9Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_ALTER; 2547c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_DUMP) { 2557c478bd9Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_IGNORE; 2567c478bd9Sstevel@tonic-gate head->ch_dlflags = crle->c_dlflags; 2577c478bd9Sstevel@tonic-gate } 258c13de8f6Sab196087 #ifdef _ELF64 2597c478bd9Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_64; 260c13de8f6Sab196087 #endif 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 2637c478bd9Sstevel@tonic-gate head->ch_cnflags |= RTC_HDR_UPM; 2647c478bd9Sstevel@tonic-gate #endif 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * If we have a hash table then there are directory and file entries 2677c478bd9Sstevel@tonic-gate * to process. 2687c478bd9Sstevel@tonic-gate */ 2697c478bd9Sstevel@tonic-gate if (crle->c_hashstrnum) { 2707c478bd9Sstevel@tonic-gate hashtbl[0] = hashbkts; 2717c478bd9Sstevel@tonic-gate hashtbl[1] = crle->c_hashstrnum; 2727c478bd9Sstevel@tonic-gate hashbkt = &hashtbl[2]; 2737c478bd9Sstevel@tonic-gate hashchn = &hashtbl[2 + hashbkts]; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * Insure all hash chain and directory/filename table entries 2777c478bd9Sstevel@tonic-gate * are cleared. 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate (void) memset(hashchn, 0, (crle->c_hashstrnum * sizeof (Word))); 2807c478bd9Sstevel@tonic-gate (void) memset(dirtbl, 0, (strtbl - (char *)dirtbl)); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate /* 2837c478bd9Sstevel@tonic-gate * Loop through the current string table list inspecting only 2847c478bd9Sstevel@tonic-gate * directories. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate for (ndx = 1, bkt = 0; bkt < stbl->t_size; bkt++) { 2877c478bd9Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 2887c478bd9Sstevel@tonic-gate Word hashval; 2897c478bd9Sstevel@tonic-gate Hash_obj *obj = ent->e_obj; 2907c478bd9Sstevel@tonic-gate char *dir = (char *)ent->e_key; 2917c478bd9Sstevel@tonic-gate Rtc_dir *_dirtbl; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * Skip any empty and non-directory entries. 2957c478bd9Sstevel@tonic-gate */ 296*57ef7aa9SRod Evans if ((obj == NULL) || 2977c478bd9Sstevel@tonic-gate ((obj->o_flags & RTC_OBJ_DIRENT) == 0)) 2987c478bd9Sstevel@tonic-gate continue; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Assign basic object attributes. 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 3047c478bd9Sstevel@tonic-gate objtbl->co_id = ent->e_id; 3057c478bd9Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 3067c478bd9Sstevel@tonic-gate objtbl->co_info = obj->o_info; 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate ent->e_cobj = objtbl; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * Assign the directory name (from its key), 3127c478bd9Sstevel@tonic-gate * and copy its name to the string table. 3137c478bd9Sstevel@tonic-gate */ 3147c478bd9Sstevel@tonic-gate objtbl->co_name = (Addr)(_strtbl - strtbl); 3157c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, dir); 3167c478bd9Sstevel@tonic-gate _strtbl += strlen(dir) + 1; 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate /* 3197c478bd9Sstevel@tonic-gate * Establish an entry in the directory table and 3207c478bd9Sstevel@tonic-gate * reserve space for its associated filename 3217c478bd9Sstevel@tonic-gate * entries (note, we add a trailing null file 3227c478bd9Sstevel@tonic-gate * entry to simplify later inspection of the 3237c478bd9Sstevel@tonic-gate * final configuration file. 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 3267c478bd9Sstevel@tonic-gate _dirtbl->cd_file = 327c13de8f6Sab196087 CAST_PTRINT(Word, ((char *)filetbl- addr)); 3287c478bd9Sstevel@tonic-gate _dirtbl->cd_obj = 329c13de8f6Sab196087 CAST_PTRINT(Word, ((char *)objtbl - addr)); 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate /* LINTED */ 3327c478bd9Sstevel@tonic-gate filetbl = (Rtc_file *)((char *)filetbl + 3337c478bd9Sstevel@tonic-gate ((ent->e_cnt + 1) * sizeof (Rtc_file))); 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * Add this object to the hash table. 3377c478bd9Sstevel@tonic-gate */ 3387c478bd9Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 3397c478bd9Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 3407c478bd9Sstevel@tonic-gate hashbkt[hashval] = ndx++; 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate /* 3437c478bd9Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 3447c478bd9Sstevel@tonic-gate * falls on an 8-byte boundary). 3457c478bd9Sstevel@tonic-gate */ 346*57ef7aa9SRod Evans objtbl = 347*57ef7aa9SRod Evans (Rtc_obj *)S_ROUND((uintptr_t)(objtbl + 1), 3487c478bd9Sstevel@tonic-gate sizeof (Lword)); 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate /* 3537c478bd9Sstevel@tonic-gate * Now collect all pathnames. These are typically full 3547c478bd9Sstevel@tonic-gate * pathnames, but may also be relative. Simple filenames are 3557c478bd9Sstevel@tonic-gate * recorded as offsets into these pathnames, thus we need to 3567c478bd9Sstevel@tonic-gate * establish the new pathname first. 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate for (bkt = 0; bkt < stbl->t_size; bkt++) { 3597c478bd9Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 3607c478bd9Sstevel@tonic-gate Word hashval; 3617c478bd9Sstevel@tonic-gate Hash_obj *obj = ent->e_obj; 3627c478bd9Sstevel@tonic-gate char *file = (char *)ent->e_key; 3637c478bd9Sstevel@tonic-gate char *_str; 3647c478bd9Sstevel@tonic-gate Rtc_dir *_dirtbl; 3657c478bd9Sstevel@tonic-gate Rtc_file *_filetbl; 3667c478bd9Sstevel@tonic-gate int _id; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* 3697c478bd9Sstevel@tonic-gate * Skip empty and directory entries, and any 3707c478bd9Sstevel@tonic-gate * simple filename entries. 3717c478bd9Sstevel@tonic-gate */ 372*57ef7aa9SRod Evans if ((obj == NULL) || 3737c478bd9Sstevel@tonic-gate (obj->o_flags & RTC_OBJ_DIRENT) || 3747c478bd9Sstevel@tonic-gate (ent->e_off)) 3757c478bd9Sstevel@tonic-gate continue; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* 3787c478bd9Sstevel@tonic-gate * Assign basic object attributes. 3797c478bd9Sstevel@tonic-gate */ 3807c478bd9Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 3817c478bd9Sstevel@tonic-gate objtbl->co_id = ent->e_id; 3827c478bd9Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 3837c478bd9Sstevel@tonic-gate objtbl->co_info = obj->o_info; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate ent->e_cobj = objtbl; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * Assign the file name (from its key), 3897c478bd9Sstevel@tonic-gate * and copy its name to the string table. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate objtbl->co_name = (Addr)(_strtbl - strtbl); 3927c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, file); 3937c478bd9Sstevel@tonic-gate _strtbl += strlen(file) + 1; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * Add this file to its associated directory. 3977c478bd9Sstevel@tonic-gate */ 3987c478bd9Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 3997c478bd9Sstevel@tonic-gate /* LINTED */ 400*57ef7aa9SRod Evans _filetbl = (Rtc_file *)(CAST_PTRINT(char *, 401*57ef7aa9SRod Evans _dirtbl->cd_file) + addr); 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate _id = --ent->e_dir->e_cnt; 4047c478bd9Sstevel@tonic-gate _filetbl[_id].cf_obj = 405c13de8f6Sab196087 CAST_PTRINT(Word, ((char *)objtbl - addr)); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate /* 4087c478bd9Sstevel@tonic-gate * If object has an alternative, record it in 4097c478bd9Sstevel@tonic-gate * the string table and assign the alternate 4107c478bd9Sstevel@tonic-gate * pointer. The new alternative offset is 4117c478bd9Sstevel@tonic-gate * retained for reuse in other filename entries. 4127c478bd9Sstevel@tonic-gate */ 4137c478bd9Sstevel@tonic-gate if ((objtbl->co_flags & RTC_OBJ_ALTER) && 4147c478bd9Sstevel@tonic-gate (obj->o_calter == 0)) { 4157c478bd9Sstevel@tonic-gate _str = obj->o_alter; 4167c478bd9Sstevel@tonic-gate objtbl->co_alter = obj->o_calter = 4177c478bd9Sstevel@tonic-gate (Addr)(_strtbl - strtbl); 4187c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, _str); 4197c478bd9Sstevel@tonic-gate _strtbl += strlen(_str) + 1; 4207c478bd9Sstevel@tonic-gate } else 4217c478bd9Sstevel@tonic-gate objtbl->co_alter = obj->o_calter; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate /* 4247c478bd9Sstevel@tonic-gate * If object identifies the specific application 4257c478bd9Sstevel@tonic-gate * for which this cache is relevant, record it 4267c478bd9Sstevel@tonic-gate * in the header. 4277c478bd9Sstevel@tonic-gate */ 4287c478bd9Sstevel@tonic-gate if ((objtbl->co_flags & 4297c478bd9Sstevel@tonic-gate (RTC_OBJ_APP | RTC_OBJ_REALPTH)) == 4307c478bd9Sstevel@tonic-gate (RTC_OBJ_APP | RTC_OBJ_REALPTH)) 4317c478bd9Sstevel@tonic-gate head->ch_app = _filetbl[_id].cf_obj; 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Add this object to the hash table. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 4377c478bd9Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 4387c478bd9Sstevel@tonic-gate hashbkt[hashval] = ndx++; 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 4427c478bd9Sstevel@tonic-gate * falls on an 8-byte boundary). 4437c478bd9Sstevel@tonic-gate */ 444c13de8f6Sab196087 objtbl = (Rtc_obj *) 445c13de8f6Sab196087 S_ROUND((uintptr_t)(objtbl + 1), 4467c478bd9Sstevel@tonic-gate sizeof (Lword)); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate /* 4517c478bd9Sstevel@tonic-gate * Finally pick off any simple filenames. 4527c478bd9Sstevel@tonic-gate */ 4537c478bd9Sstevel@tonic-gate for (bkt = 0; bkt < stbl->t_size; bkt++) { 4547c478bd9Sstevel@tonic-gate for (ent = stbl->t_entry[bkt]; ent; ent = ent->e_next) { 4557c478bd9Sstevel@tonic-gate Word hashval; 4567c478bd9Sstevel@tonic-gate Hash_obj * obj = ent->e_obj; 4577c478bd9Sstevel@tonic-gate Rtc_dir * _dirtbl; 4587c478bd9Sstevel@tonic-gate Rtc_file * _filetbl; 4597c478bd9Sstevel@tonic-gate int _id; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* 4627c478bd9Sstevel@tonic-gate * Skip everything except simple filenames. 4637c478bd9Sstevel@tonic-gate */ 4647c478bd9Sstevel@tonic-gate if (ent->e_off == 0) 4657c478bd9Sstevel@tonic-gate continue; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate /* 4687c478bd9Sstevel@tonic-gate * Assign basic object attributes. 4697c478bd9Sstevel@tonic-gate */ 4707c478bd9Sstevel@tonic-gate objtbl->co_hash = ent->e_hash; 4717c478bd9Sstevel@tonic-gate objtbl->co_id = ent->e_id; 4727c478bd9Sstevel@tonic-gate objtbl->co_flags = obj->o_flags | ent->e_flags; 4737c478bd9Sstevel@tonic-gate objtbl->co_info = obj->o_info; 4747c478bd9Sstevel@tonic-gate objtbl->co_alter = obj->o_calter; 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate ent->e_cobj = objtbl; 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* 4797c478bd9Sstevel@tonic-gate * Assign the file name from its full name. 4807c478bd9Sstevel@tonic-gate */ 481c13de8f6Sab196087 objtbl->co_name = (Addr)(CAST_PTRINT(char *, 482c13de8f6Sab196087 ent->e_path->e_cobj->co_name) + ent->e_off); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate /* 4857c478bd9Sstevel@tonic-gate * Add this file to its associated directory. 4867c478bd9Sstevel@tonic-gate */ 4877c478bd9Sstevel@tonic-gate _dirtbl = &dirtbl[ent->e_id - 1]; 4887c478bd9Sstevel@tonic-gate /* LINTED */ 4897c478bd9Sstevel@tonic-gate _filetbl = (Rtc_file *) 490c13de8f6Sab196087 (CAST_PTRINT(char *, _dirtbl->cd_file) + 491c13de8f6Sab196087 addr); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate _id = --ent->e_dir->e_cnt; 4947c478bd9Sstevel@tonic-gate _filetbl[_id].cf_obj = 495c13de8f6Sab196087 CAST_PTRINT(Word, ((char *)objtbl - addr)); 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /* 4987c478bd9Sstevel@tonic-gate * Add this object to the hash table. 4997c478bd9Sstevel@tonic-gate */ 5007c478bd9Sstevel@tonic-gate hashval = ent->e_hash % hashbkts; 5017c478bd9Sstevel@tonic-gate hashchn[ndx] = hashbkt[hashval]; 5027c478bd9Sstevel@tonic-gate hashbkt[hashval] = ndx++; 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* 5057c478bd9Sstevel@tonic-gate * Increment Rt_obj pointer (make sure pointer 5067c478bd9Sstevel@tonic-gate * falls on an 8-byte boundary). 5077c478bd9Sstevel@tonic-gate */ 508c13de8f6Sab196087 objtbl = (Rtc_obj *) 509c13de8f6Sab196087 S_ROUND((uintptr_t)(objtbl + 1), 5107c478bd9Sstevel@tonic-gate sizeof (Lword)); 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate /* 5167c478bd9Sstevel@tonic-gate * Add any library, or secure path definitions. 5177c478bd9Sstevel@tonic-gate */ 5187c478bd9Sstevel@tonic-gate if (crle->c_edlibpath) { 5197c478bd9Sstevel@tonic-gate head->ch_edlibpath = head->ch_str + (_strtbl - strtbl); 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_edlibpath); 5227c478bd9Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_edlibpath) + 1; 5237c478bd9Sstevel@tonic-gate } else 5247c478bd9Sstevel@tonic-gate head->ch_edlibpath = 0; 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate if (crle->c_adlibpath) { 5277c478bd9Sstevel@tonic-gate head->ch_adlibpath = head->ch_str + (_strtbl - strtbl); 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_adlibpath); 5307c478bd9Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_adlibpath) + 1; 5317c478bd9Sstevel@tonic-gate } else 5327c478bd9Sstevel@tonic-gate head->ch_adlibpath = 0; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate if (crle->c_eslibpath) { 5357c478bd9Sstevel@tonic-gate head->ch_eslibpath = head->ch_str + (_strtbl - strtbl); 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_eslibpath); 5387c478bd9Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_eslibpath) + 1; 5397c478bd9Sstevel@tonic-gate } else 5407c478bd9Sstevel@tonic-gate head->ch_eslibpath = 0; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate if (crle->c_aslibpath) { 5437c478bd9Sstevel@tonic-gate head->ch_aslibpath = head->ch_str + (_strtbl - strtbl); 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, crle->c_aslibpath); 5467c478bd9Sstevel@tonic-gate _strtbl += strlen((char *)crle->c_aslibpath) + 1; 5477c478bd9Sstevel@tonic-gate } else 5487c478bd9Sstevel@tonic-gate head->ch_aslibpath = 0; 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate /* 5517c478bd9Sstevel@tonic-gate * Add any environment variable entries. 5527c478bd9Sstevel@tonic-gate */ 5537c478bd9Sstevel@tonic-gate if (crle->c_envnum) { 5547c478bd9Sstevel@tonic-gate Env_desc *env; 555*57ef7aa9SRod Evans Aliste idx; 5567c478bd9Sstevel@tonic-gate 557*57ef7aa9SRod Evans for (APLIST_TRAVERSE(crle->c_env, idx, env)) { 5587c478bd9Sstevel@tonic-gate envtbl->env_str = head->ch_str + (_strtbl - strtbl); 5597c478bd9Sstevel@tonic-gate envtbl->env_flags = env->e_flags; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, env->e_str); 5627c478bd9Sstevel@tonic-gate _strtbl += env->e_totsz; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate envtbl++; 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate envtbl->env_str = 0; 5677c478bd9Sstevel@tonic-gate envtbl->env_flags = 0; 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* 5717c478bd9Sstevel@tonic-gate * Add any filter/filtee association entries. 5727c478bd9Sstevel@tonic-gate */ 5737c478bd9Sstevel@tonic-gate if (crle->c_fltrnum) { 5747c478bd9Sstevel@tonic-gate Flt_desc *flt; 575*57ef7aa9SRod Evans Aliste idx1; 5767c478bd9Sstevel@tonic-gate 577*57ef7aa9SRod Evans for (APLIST_TRAVERSE(crle->c_flt, idx1, flt)) { 5787c478bd9Sstevel@tonic-gate Hash_ent *flte; 579*57ef7aa9SRod Evans Aliste idx2; 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * Establish the filter name, and filtee string, as 5837c478bd9Sstevel@tonic-gate * offsets into the configuration files string table. 5847c478bd9Sstevel@tonic-gate * Establish the filtee as the offset into the filtee 5857c478bd9Sstevel@tonic-gate * table. 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate fltrtbl->fr_filter = flt->f_fent->e_cobj->co_name; 5887c478bd9Sstevel@tonic-gate fltrtbl->fr_string = _strtbl - strtbl; 5897c478bd9Sstevel@tonic-gate (void) strcpy(_strtbl, flt->f_str); 5907c478bd9Sstevel@tonic-gate _strtbl += flt->f_strsz; 591c13de8f6Sab196087 fltrtbl->fr_filtee = (Word) 592c13de8f6Sab196087 ((uintptr_t)_fltetbl - (uintptr_t)fltetbl); 5937c478bd9Sstevel@tonic-gate 594*57ef7aa9SRod Evans for (APLIST_TRAVERSE(flt->f_filtee, idx2, flte)) { 5957c478bd9Sstevel@tonic-gate /* 5967c478bd9Sstevel@tonic-gate * Establish the filtee name as the offset into 5977c478bd9Sstevel@tonic-gate * the configuration files string table. 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate _fltetbl->fe_filtee = flte->e_cobj->co_name; 6007c478bd9Sstevel@tonic-gate _fltetbl++; 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate _fltetbl->fe_filtee = 0; 6037c478bd9Sstevel@tonic-gate _fltetbl++, fltrtbl++; 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate fltrtbl->fr_filter = 0; 6067c478bd9Sstevel@tonic-gate fltrtbl->fr_filtee = 0; 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* 6107c478bd9Sstevel@tonic-gate * Flush everything out. 6117c478bd9Sstevel@tonic-gate */ 6127c478bd9Sstevel@tonic-gate (void) close(crle->c_tempfd); 613c13de8f6Sab196087 if (msync((void *)crle->c_tempaddr, crle->c_tempsize, MS_ASYNC) == -1) { 6147c478bd9Sstevel@tonic-gate int err = errno; 6157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 6167c478bd9Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 6177c478bd9Sstevel@tonic-gate return (1); 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate return (0); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate /* 6247c478bd9Sstevel@tonic-gate * Update a configuration file. If dldump()'ed images have been created then 6257c478bd9Sstevel@tonic-gate * the memory reservation of those images is added to the configuration file. 6267c478bd9Sstevel@tonic-gate * The temporary file is then moved into its final resting place. 6277c478bd9Sstevel@tonic-gate */ 628b3fbe5e6Sseizo int 6297c478bd9Sstevel@tonic-gate updateconfig(Crle_desc * crle) 6307c478bd9Sstevel@tonic-gate { 631c13de8f6Sab196087 Rtc_head *head = (Rtc_head *)crle->c_tempheadaddr; 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_DUMP) { 6347c478bd9Sstevel@tonic-gate head->ch_cnflags &= ~RTC_HDR_IGNORE; 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate if (msync((void *)crle->c_tempaddr, crle->c_tempsize, 6377c478bd9Sstevel@tonic-gate MS_ASYNC) == -1) { 6387c478bd9Sstevel@tonic-gate int err = errno; 6397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_TRUNC), 6407c478bd9Sstevel@tonic-gate crle->c_name, crle->c_tempname, strerror(err)); 6417c478bd9Sstevel@tonic-gate return (1); 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /* 6467c478bd9Sstevel@tonic-gate * If an original configuration file exists, remove it. 6477c478bd9Sstevel@tonic-gate */ 6487c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_EXISTS) 6497c478bd9Sstevel@tonic-gate (void) unlink(crle->c_confil); 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate /* 6527c478bd9Sstevel@tonic-gate * Move the config file to its final resting place. If the two files 6537c478bd9Sstevel@tonic-gate * exist on the same filesystem a rename is sufficient. 6547c478bd9Sstevel@tonic-gate */ 6557c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_DIFFDEV) { 6567c478bd9Sstevel@tonic-gate int fd; 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate if ((fd = open(crle->c_confil, (O_RDWR | O_CREAT | O_TRUNC), 6597c478bd9Sstevel@tonic-gate 0666)) == -1) { 6607c478bd9Sstevel@tonic-gate int err = errno; 6617c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), 6627c478bd9Sstevel@tonic-gate crle->c_name, crle->c_confil, strerror(err)); 6637c478bd9Sstevel@tonic-gate return (1); 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate if (write(fd, (void *)crle->c_tempaddr, crle->c_tempsize) != 6667c478bd9Sstevel@tonic-gate crle->c_tempsize) { 6677c478bd9Sstevel@tonic-gate int err = errno; 6687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_WRITE), 6697c478bd9Sstevel@tonic-gate crle->c_name, crle->c_confil, strerror(err)); 6707c478bd9Sstevel@tonic-gate return (1); 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate (void) close(fd); 6737c478bd9Sstevel@tonic-gate (void) unlink(crle->c_tempname); 6747c478bd9Sstevel@tonic-gate } else 6757c478bd9Sstevel@tonic-gate (void) rename(crle->c_tempname, crle->c_confil); 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate return (0); 6787c478bd9Sstevel@tonic-gate } 679