/* * We paper over, rather than fix, include-file bugs; this is a * very-early-use program on new machines. */ #include #include #include #include #include #include #include static void try(const char *path, char **av) { struct stat stb; char *osv0; const char *l; const char *pref; char *t; if ( (stat(path,&stb) >= 0) && ((stb.st_mode & S_IFMT) != S_IFLNK) && (access(path,X_OK) >= 0) ) { pref = (av[0][0] == '-') ? "-" : ""; l = rindex(path,'/'); if (l) { asprintf(&t,"%s%s",pref,l+1); } else { asprintf(&t,"%s%s",pref,path); } osv0 = av[0]; av[0] = t; execv(path,av); av[0] = osv0; free(t); } } int main(int, char **); int main(int ac, char **av) { struct passwd *pw; char *d; char *sp; (void)ac; pw = getpwnam("mouse"); d = strdup(pw?pw->pw_dir:"/home/mouse"); asprintf(&sp,"%s/lbin/mcsh",d); try(sp,av); free(sp); try("/bin/bash",av); try("/bin/sh",av); write(2,av[0],strlen(av[0])); write(2,": can't find a shell to use\n",28); exit(1); }