summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-02-11 08:23:10 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-02-11 08:23:10 +0000
commit1a0c2aa6bbaa9b709a2af4d560c66789686d7805 (patch)
treea71e0b0376dffa0a40cdc4027f6f2fce4d56655f /src/main.c
parent020f508dbe284a6e15ec30754d145d0cbdc502da (diff)
parent034f947f03e15c6f73bda708c5488042a98928ca (diff)
downloadplatform_external_mksh-pie-release.tar.gz
platform_external_mksh-pie-release.tar.bz2
platform_external_mksh-pie-release.zip
Snap for 4598635 from 034f947f03e15c6f73bda708c5488042a98928ca to pi-releaseandroid-wear-9.0.0_r9android-wear-9.0.0_r8android-wear-9.0.0_r7android-wear-9.0.0_r6android-wear-9.0.0_r5android-wear-9.0.0_r4android-wear-9.0.0_r30android-wear-9.0.0_r3android-wear-9.0.0_r29android-wear-9.0.0_r28android-wear-9.0.0_r27android-wear-9.0.0_r26android-wear-9.0.0_r25android-wear-9.0.0_r24android-wear-9.0.0_r23android-wear-9.0.0_r22android-wear-9.0.0_r21android-wear-9.0.0_r20android-wear-9.0.0_r2android-wear-9.0.0_r19android-wear-9.0.0_r18android-wear-9.0.0_r17android-wear-9.0.0_r16android-wear-9.0.0_r15android-wear-9.0.0_r14android-wear-9.0.0_r13android-wear-9.0.0_r12android-wear-9.0.0_r11android-wear-9.0.0_r10android-wear-9.0.0_r1android-vts-9.0_r9android-vts-9.0_r8android-vts-9.0_r7android-vts-9.0_r6android-vts-9.0_r5android-vts-9.0_r4android-vts-9.0_r18android-vts-9.0_r17android-vts-9.0_r16android-vts-9.0_r15android-vts-9.0_r14android-vts-9.0_r13android-vts-9.0_r12android-vts-9.0_r11android-vts-9.0_r10android-security-9.0.0_r71android-security-9.0.0_r70android-security-9.0.0_r69android-security-9.0.0_r68android-security-9.0.0_r67android-security-9.0.0_r66android-security-9.0.0_r65android-security-9.0.0_r64android-security-9.0.0_r63android-security-9.0.0_r62android-cts-9.0_r9android-cts-9.0_r8android-cts-9.0_r7android-cts-9.0_r6android-cts-9.0_r5android-cts-9.0_r4android-cts-9.0_r3android-cts-9.0_r2android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11android-cts-9.0_r10android-cts-9.0_r1android-9.0.0_r9android-9.0.0_r8android-9.0.0_r7android-9.0.0_r61android-9.0.0_r60android-9.0.0_r6android-9.0.0_r59android-9.0.0_r58android-9.0.0_r57android-9.0.0_r56android-9.0.0_r55android-9.0.0_r54android-9.0.0_r53android-9.0.0_r52android-9.0.0_r51android-9.0.0_r50android-9.0.0_r5android-9.0.0_r49android-9.0.0_r48android-9.0.0_r3android-9.0.0_r2android-9.0.0_r18android-9.0.0_r17android-9.0.0_r10android-9.0.0_r1security-pi-releasepie-vts-releasepie-security-releasepie-s2-releasepie-release-2pie-releasepie-r2-s2-releasepie-r2-s1-releasepie-r2-releasepie-platform-releasepie-gsipie-cuttlefish-testingpie-cts-release
Change-Id: I503b8ca4a49f5a2f2184c729264229bdf75a3249
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c131
1 files changed, 113 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
index b4d7244..ad20c94 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,7 +5,7 @@
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
- * 2011, 2012, 2013, 2014, 2015, 2016, 2017
+ * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@@ -34,9 +34,7 @@
#include <locale.h>
#endif
-__RCSID("$MirOS: src/bin/mksh/main.c,v 1.342 2017/04/28 11:13:47 tg Exp $");
-
-extern char **environ;
+__RCSID("$MirOS: src/bin/mksh/main.c,v 1.347 2018/01/13 21:45:07 tg Exp $");
#ifndef MKSHRC_PATH
#define MKSHRC_PATH "~/.mkshrc"
@@ -52,6 +50,7 @@ void chvt_reinit(void);
static void reclaim(void);
static void remove_temps(struct temp *);
static mksh_uari_t rndsetup(void);
+static void init_environ(void);
#ifdef SIGWINCH
static void x_sigwinch(int);
#endif
@@ -242,10 +241,6 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
set_ifs(TC_IFSWS);
#ifdef __OS2__
- for (i = 0; i < 3; ++i)
- if (!isatty(i))
- setmode(i, O_BINARY);
-
os2_init(&argc, &argv);
#endif
@@ -401,14 +396,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
#endif
/* import environment */
- if (environ != NULL) {
- wp = (const char **)environ;
- while (*wp != NULL) {
- rndpush(*wp);
- typeset(*wp, IMPORT | EXPORT, 0, 0, 0);
- ++wp;
- }
- }
+ init_environ();
/* override default PATH regardless of environment */
#ifdef MKSH_DEFPATH_OVERRIDE
@@ -671,8 +659,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
if (Flag(FLOGIN))
include(substitute("$HOME/.profile", 0), 0, NULL, true);
if (Flag(FTALKING)) {
- cp = substitute(substitute("${ENV:-" MKSHRC_PATH "}",
- 0), DOTILDE);
+ cp = substitute("${ENV:-" MKSHRC_PATH "}", DOTILDE);
if (cp[0] != '\0')
include(cp, 0, NULL, true);
}
@@ -1987,3 +1974,111 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool forread)
mksh_tcset(fd, &cb);
}
+
+#ifdef MKSH_ENVDIR
+static void
+init_environ(void)
+{
+ char *xp;
+ ssize_t n;
+ XString xs;
+ struct shf *shf;
+ DIR *dirp;
+ struct dirent *dent;
+
+ if ((dirp = opendir(MKSH_ENVDIR)) == NULL) {
+ warningf(false, "cannot read environment from %s: %s",
+ MKSH_ENVDIR, cstrerror(errno));
+ return;
+ }
+ XinitN(xs, 256, ATEMP);
+ read_envfile:
+ errno = 0;
+ if ((dent = readdir(dirp)) != NULL) {
+ if (skip_varname(dent->d_name, true)[0] == '\0') {
+ xp = shf_smprintf(Tf_sSs, MKSH_ENVDIR, dent->d_name);
+ if (!(shf = shf_open(xp, O_RDONLY, 0, 0))) {
+ warningf(false,
+ "cannot read environment %s from %s: %s",
+ dent->d_name, MKSH_ENVDIR,
+ cstrerror(errno));
+ goto read_envfile;
+ }
+ afree(xp, ATEMP);
+ n = strlen(dent->d_name);
+ xp = Xstring(xs, xp);
+ XcheckN(xs, xp, n + 32);
+ memcpy(xp, dent->d_name, n);
+ xp += n;
+ *xp++ = '=';
+ while ((n = shf_read(xp, Xnleft(xs, xp), shf)) > 0) {
+ xp += n;
+ if (Xnleft(xs, xp) <= 0)
+ XcheckN(xs, xp, Xlength(xs, xp));
+ }
+ if (n < 0) {
+ warningf(false,
+ "cannot read environment %s from %s: %s",
+ dent->d_name, MKSH_ENVDIR,
+ cstrerror(shf_errno(shf)));
+ } else {
+ *xp = '\0';
+ xp = Xstring(xs, xp);
+ rndpush(xp);
+ typeset(xp, IMPORT | EXPORT, 0, 0, 0);
+ }
+ shf_close(shf);
+ }
+ goto read_envfile;
+ } else if (errno)
+ warningf(false, "cannot read environment from %s: %s",
+ MKSH_ENVDIR, cstrerror(errno));
+ closedir(dirp);
+ Xfree(xs, xp);
+}
+#else
+extern char **environ;
+
+static void
+init_environ(void)
+{
+ const char **wp;
+
+ if (environ == NULL)
+ return;
+
+ wp = (const char **)environ;
+ while (*wp != NULL) {
+ rndpush(*wp);
+ typeset(*wp, IMPORT | EXPORT, 0, 0, 0);
+ ++wp;
+ }
+}
+#endif
+
+#ifdef MKSH_EARLY_LOCALE_TRACKING
+void
+recheck_ctype(void)
+{
+ const char *ccp;
+
+ ccp = str_val(global("LC_ALL"));
+ if (ccp == null)
+ ccp = str_val(global("LC_CTYPE"));
+ if (ccp == null)
+ ccp = str_val(global("LANG"));
+ UTFMODE = isuc(ccp);
+#if HAVE_SETLOCALE_CTYPE
+ ccp = setlocale(LC_CTYPE, ccp);
+#if HAVE_LANGINFO_CODESET
+ if (!isuc(ccp))
+ ccp = nl_langinfo(CODESET);
+#endif
+ if (isuc(ccp))
+ UTFMODE = 1;
+#endif
+
+ if (Flag(FPOSIX))
+ warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompliant");
+}
+#endif