use login -f as default command.

This commit is contained in:
Kelvin Sherlock 2018-05-12 11:05:41 -04:00
parent bcc69350e1
commit b838f724d8
1 changed files with 35 additions and 37 deletions

View File

@ -7,6 +7,7 @@
#include <gsos.h> #include <gsos.h>
#include <Locator.h> #include <Locator.h>
#include <Memory.h> #include <Memory.h>
#include <shell.h>
#include <texttool.h> #include <texttool.h>
#include <errno.h> #include <errno.h>
@ -19,6 +20,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <pwd.h>
#include <gno/gno.h> #include <gno/gno.h>
#include <gno/kerntool.h> #include <gno/kerntool.h>
@ -101,10 +103,17 @@ openpty2(int *amaster, int *aslave, char *name, struct sgttyb *sg, struct winsiz
#define _write(fd, msg) write(fd, msg, sizeof(msg) - 1); #define _write(fd, msg) write(fd, msg, sizeof(msg) - 1);
static SetGSPB term_var = {
3, "\x04\x00TERM", "\x05\x00vt100", 1
};
static char **child_argv = NULL;
static struct passwd *pwd = NULL;
static char *whoami = "";
#pragma databank 1 #pragma databank 1
static int _child(int master, int slave) { static int _child(int master, int slave) {
//static char buffer[256]; static unsigned zero = 0;
int ok; int ok;
close(master); close(master);
@ -115,45 +124,23 @@ static int _child(int master, int slave) {
close(slave); close(slave);
return 1; return 1;
} }
#if 0
dup2(slave, STDIN_FILENO); /* work around GNO bug where environment leaks into parent */
dup2(slave, STDOUT_FILENO); PushVariablesGS(&zero);
dup2(slave, STDERR_FILENO);
SetInputDevice(3,(long)STDIN_FILENO); SetGS(&term_var);
SetOutputDevice(3,(long)STDOUT_FILENO);
SetErrorDevice(3,(long)STDERR_FILENO);
if (child_argv) {
execvp(child_argv[0], child_argv);
if (slave > STDERR_FILENO) close(slave); } else {
_write(STDOUT_FILENO, "here i am\r\n"); static char buffer[64] = "login -f ";
strcpy(buffer + 9, whoami);
/* should sniff the correct TERM value from /etc/ttys */
ok = tcnewpgrp(STDIN_FILENO); _execve(":usr:bin:login", buffer);
if (ok < 0) _write(STDERR_FILENO, "tcnewpgrp failed.\r\n"); _execve(":usr:sbin:login", buffer);
ok = settpgrp(STDIN_FILENO); _execve(":bin:gsh", "gsh");
if (ok < 0) _write(STDERR_FILENO, "settpgrp failed.\r\n");
if (ioctl(STDIN_FILENO, TIOCSCTTY, (char *)NULL) < 0) {
_write(STDERR_FILENO, "ioctl TIOCSCTTY failed.\r\n");
}
#endif
#if 0
_execve("/bin/cat", "cat");
for(;;) {
ok = read(STDIN_FILENO, buffer, sizeof(buffer));
if (ok <= 0) break;
write(STDOUT_FILENO, buffer, ok);
} }
//_execve(":bin:gsh", "gsh -f");
//_execve(":bin:cat", "cat");
#endif
_execve(":bin:gsh", "gsh -f");
_write(STDERR_FILENO, "_execve failed.\r\n"); _write(STDERR_FILENO, "_execve failed.\r\n");
return 1; return 1;
} }
@ -207,13 +194,17 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
term_var.value = "\x05\x00vt100";
child_argv = NULL;
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
char *cp = argv[i]; char *cp = argv[i];
if (cp[0] != '-') break; if (cp[0] != '-') break;
if (strcmp(cp, "--vt52") == 0) { if (strcmp(cp, "--vt52") == 0) {
term_var.value = "\x04\x00vt52";
} else if (strcmp(cp, "--vt100") == 0) { } else if (strcmp(cp, "--vt100") == 0) {
term_var.value = "\x05\x00vt100";
} else if (strcmp(cp,"--") == 0) {
break;
} else { } else {
ErrWriteCString("Unknown option: "); ErrWriteCString("Unknown option: ");
ErrWriteCString(cp); ErrWriteCString(cp);
@ -225,7 +216,14 @@ int main(int argc, char **argv) {
argc -= i; argc -= i;
argv += i; argv += i;
if (argc) {
child_argv = malloc(argc * 4 + 4);
/* <= argc so trailing NULL copies */
for(i = 0; i <= argc; ++i) child_argv[i] = argv[i];
}
pwd = getpwuid(getuid());
whoami = pwd ? pwd->pw_name : "";
MyID = MMStartUp(); MyID = MMStartUp();