Changeset View
Changeset View
Standalone View
Standalone View
bin/sh/main.c
Show First 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | |||||
* Read /etc/profile or .profile. Return on error. | * Read /etc/profile or .profile. Return on error. | ||||
*/ | */ | ||||
static void | static void | ||||
read_profile(const char *name) | read_profile(const char *name) | ||||
{ | { | ||||
int fd; | int fd; | ||||
const char *expandedname; | const char *expandedname; | ||||
int oflags = O_RDONLY | O_CLOEXEC; | |||||
if (verifyflag) | |||||
oflags |= O_VERIFY; | |||||
expandedname = expandstr(name); | expandedname = expandstr(name); | ||||
if (expandedname == NULL) | if (expandedname == NULL) | ||||
return; | return; | ||||
INTOFF; | INTOFF; | ||||
if ((fd = open(expandedname, O_RDONLY | O_CLOEXEC)) >= 0) | if ((fd = open(expandedname, oflags)) >= 0) | ||||
setinputfd(fd, 1); | setinputfd(fd, 1); | ||||
INTON; | INTON; | ||||
if (fd < 0) | if (fd < 0) | ||||
return; | return; | ||||
cmdloop(0); | cmdloop(0); | ||||
popfile(); | popfile(); | ||||
} | } | ||||
/* | /* | ||||
* Read a file containing shell functions. | * Read a file containing shell functions. | ||||
*/ | */ | ||||
void | void | ||||
readcmdfile(const char *name) | readcmdfile(const char *name, int verify) | ||||
{ | { | ||||
setinputfile(name, 1); | setinputfile(name, 1, verify); | ||||
cmdloop(0); | cmdloop(0); | ||||
popfile(); | popfile(); | ||||
} | } | ||||
/* | /* | ||||
* Take commands from a file. To be compatible we should do a path | * Take commands from a file. To be compatible we should do a path | ||||
Show All 38 Lines | dotcmd(int argc, char **argv) | ||||
/* | /* | ||||
* Because we have historically not supported any options, | * Because we have historically not supported any options, | ||||
* only treat "--" specially. | * only treat "--" specially. | ||||
*/ | */ | ||||
filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1]; | filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1]; | ||||
fullname = find_dot_file(filename); | fullname = find_dot_file(filename); | ||||
setinputfile(fullname, 1); | setinputfile(fullname, 1, -1 /* verify */); | ||||
commandname = fullname; | commandname = fullname; | ||||
cmdloop(0); | cmdloop(0); | ||||
popfile(); | popfile(); | ||||
return exitstatus; | return exitstatus; | ||||
} | } | ||||
int | int | ||||
Show All 9 Lines |