1*10d63b7dSRichard Lowe /* 2*10d63b7dSRichard Lowe * CDDL HEADER START 3*10d63b7dSRichard Lowe * 4*10d63b7dSRichard Lowe * The contents of this file are subject to the terms of the 5*10d63b7dSRichard Lowe * Common Development and Distribution License (the "License"). 6*10d63b7dSRichard Lowe * You may not use this file except in compliance with the License. 7*10d63b7dSRichard Lowe * 8*10d63b7dSRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*10d63b7dSRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*10d63b7dSRichard Lowe * See the License for the specific language governing permissions 11*10d63b7dSRichard Lowe * and limitations under the License. 12*10d63b7dSRichard Lowe * 13*10d63b7dSRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*10d63b7dSRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*10d63b7dSRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*10d63b7dSRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*10d63b7dSRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*10d63b7dSRichard Lowe * 19*10d63b7dSRichard Lowe * CDDL HEADER END 20*10d63b7dSRichard Lowe */ 21*10d63b7dSRichard Lowe /* 22*10d63b7dSRichard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 23*10d63b7dSRichard Lowe * Use is subject to license terms. 24*10d63b7dSRichard Lowe */ 25*10d63b7dSRichard Lowe 26*10d63b7dSRichard Lowe 27*10d63b7dSRichard Lowe /* 28*10d63b7dSRichard Lowe * mksh.cc 29*10d63b7dSRichard Lowe * 30*10d63b7dSRichard Lowe * Execute the command(s) of one Make or DMake rule 31*10d63b7dSRichard Lowe */ 32*10d63b7dSRichard Lowe 33*10d63b7dSRichard Lowe /* 34*10d63b7dSRichard Lowe * Included files 35*10d63b7dSRichard Lowe */ 36*10d63b7dSRichard Lowe #include <mksh/dosys.h> /* redirect_io() */ 37*10d63b7dSRichard Lowe #include <mksh/misc.h> /* retmem() */ 38*10d63b7dSRichard Lowe #include <mksh/mksh.h> 39*10d63b7dSRichard Lowe #include <errno.h> 40*10d63b7dSRichard Lowe #include <signal.h> 41*10d63b7dSRichard Lowe 42*10d63b7dSRichard Lowe 43*10d63b7dSRichard Lowe /* 44*10d63b7dSRichard Lowe * Workaround for NFS bug. Sometimes, when running 'chdir' on a remote 45*10d63b7dSRichard Lowe * dmake server, it fails with "Stale NFS file handle" error. 46*10d63b7dSRichard Lowe * The second attempt seems to work. 47*10d63b7dSRichard Lowe */ 48*10d63b7dSRichard Lowe int 49*10d63b7dSRichard Lowe my_chdir(char * dir) { 50*10d63b7dSRichard Lowe int res = chdir(dir); 51*10d63b7dSRichard Lowe if (res != 0 && (errno == ESTALE || errno == EAGAIN)) { 52*10d63b7dSRichard Lowe /* Stale NFS file handle. Try again */ 53*10d63b7dSRichard Lowe res = chdir(dir); 54*10d63b7dSRichard Lowe } 55*10d63b7dSRichard Lowe return res; 56*10d63b7dSRichard Lowe } 57*10d63b7dSRichard Lowe 58*10d63b7dSRichard Lowe 59*10d63b7dSRichard Lowe /* 60*10d63b7dSRichard Lowe * File table of contents 61*10d63b7dSRichard Lowe */ 62*10d63b7dSRichard Lowe static void change_sunpro_dependencies_value(char *oldpath, char *newpath); 63*10d63b7dSRichard Lowe static void init_mksh_globals(char *shell); 64*10d63b7dSRichard Lowe static void set_env_vars(char *env_list[]); 65*10d63b7dSRichard Lowe 66*10d63b7dSRichard Lowe 67*10d63b7dSRichard Lowe static void 68*10d63b7dSRichard Lowe set_env_vars(char *env_list[]) 69*10d63b7dSRichard Lowe { 70*10d63b7dSRichard Lowe char **env_list_p; 71*10d63b7dSRichard Lowe 72*10d63b7dSRichard Lowe for (env_list_p = env_list; 73*10d63b7dSRichard Lowe *env_list_p != (char *) NULL; 74*10d63b7dSRichard Lowe env_list_p++) { 75*10d63b7dSRichard Lowe putenv(*env_list_p); 76*10d63b7dSRichard Lowe } 77*10d63b7dSRichard Lowe } 78*10d63b7dSRichard Lowe 79*10d63b7dSRichard Lowe static void 80*10d63b7dSRichard Lowe init_mksh_globals(char *shell) 81*10d63b7dSRichard Lowe { 82*10d63b7dSRichard Lowe /* 83*10d63b7dSRichard Lowe MBSTOWCS(wcs_buffer, "SHELL"); 84*10d63b7dSRichard Lowe shell_name = GETNAME(wcs_buffer, FIND_LENGTH); 85*10d63b7dSRichard Lowe MBSTOWCS(wcs_buffer, shell); 86*10d63b7dSRichard Lowe (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false); 87*10d63b7dSRichard Lowe */ 88*10d63b7dSRichard Lowe char * dmake_shell; 89*10d63b7dSRichard Lowe if ((dmake_shell = getenv("DMAKE_SHELL")) == NULL) { 90*10d63b7dSRichard Lowe dmake_shell = shell; 91*10d63b7dSRichard Lowe } 92*10d63b7dSRichard Lowe MBSTOWCS(wcs_buffer, dmake_shell); 93*10d63b7dSRichard Lowe shell_name = GETNAME(wcs_buffer, FIND_LENGTH); 94*10d63b7dSRichard Lowe } 95*10d63b7dSRichard Lowe 96*10d63b7dSRichard Lowe /* 97*10d63b7dSRichard Lowe * Change the pathname in the value of the SUNPRO_DEPENDENCIES env variable 98*10d63b7dSRichard Lowe * from oldpath to newpath. 99*10d63b7dSRichard Lowe */ 100*10d63b7dSRichard Lowe static void 101*10d63b7dSRichard Lowe change_sunpro_dependencies_value(char *oldpath, char *newpath) 102*10d63b7dSRichard Lowe { 103*10d63b7dSRichard Lowe char buf[MAXPATHLEN]; 104*10d63b7dSRichard Lowe static char *env; 105*10d63b7dSRichard Lowe int length; 106*10d63b7dSRichard Lowe int oldpathlen; 107*10d63b7dSRichard Lowe char *sp_dep_value; 108*10d63b7dSRichard Lowe 109*10d63b7dSRichard Lowe /* check if SUNPRO_DEPENDENCIES is set in the environment */ 110*10d63b7dSRichard Lowe if ((sp_dep_value = getenv("SUNPRO_DEPENDENCIES")) != NULL) { 111*10d63b7dSRichard Lowe oldpathlen = strlen(oldpath); 112*10d63b7dSRichard Lowe /* check if oldpath is indeed in the value of SUNPRO_DEPENDENCIES */ 113*10d63b7dSRichard Lowe if (strncmp(oldpath, sp_dep_value, oldpathlen) == 0) { 114*10d63b7dSRichard Lowe (void) sprintf(buf, 115*10d63b7dSRichard Lowe "%s%s", 116*10d63b7dSRichard Lowe newpath, 117*10d63b7dSRichard Lowe sp_dep_value + oldpathlen); 118*10d63b7dSRichard Lowe length = 2 + 119*10d63b7dSRichard Lowe strlen("SUNPRO_DEPENDENCIES") + 120*10d63b7dSRichard Lowe strlen(buf); 121*10d63b7dSRichard Lowe env = getmem(length); 122*10d63b7dSRichard Lowe (void) sprintf(env, 123*10d63b7dSRichard Lowe "%s=%s", 124*10d63b7dSRichard Lowe "SUNPRO_DEPENDENCIES", 125*10d63b7dSRichard Lowe buf); 126*10d63b7dSRichard Lowe (void) putenv(env); 127*10d63b7dSRichard Lowe } 128*10d63b7dSRichard Lowe } 129*10d63b7dSRichard Lowe } 130*10d63b7dSRichard Lowe 131*10d63b7dSRichard Lowe 132