Skip to content

Commit

Permalink
use login -f as default command.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksherlock committed May 12, 2018
1 parent bcc6935 commit b838f72
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions darlene.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gsos.h>
#include <Locator.h>
#include <Memory.h>
#include <shell.h>
#include <texttool.h>

#include <errno.h>
Expand All @@ -19,6 +20,7 @@
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pwd.h>

#include <gno/gno.h>
#include <gno/kerntool.h>
Expand Down Expand Up @@ -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);

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
static int _child(int master, int slave) {

//static char buffer[256];
static unsigned zero = 0;
int ok;
close(master);

Expand All @@ -115,45 +124,23 @@ static int _child(int master, int slave) {
close(slave);
return 1;
}
#if 0

dup2(slave, STDIN_FILENO);
dup2(slave, STDOUT_FILENO);
dup2(slave, STDERR_FILENO);

SetInputDevice(3,(long)STDIN_FILENO);
SetOutputDevice(3,(long)STDOUT_FILENO);
SetErrorDevice(3,(long)STDERR_FILENO);


/* work around GNO bug where environment leaks into parent */
PushVariablesGS(&zero);

if (slave > STDERR_FILENO) close(slave);
_write(STDOUT_FILENO, "here i am\r\n");
SetGS(&term_var);


ok = tcnewpgrp(STDIN_FILENO);
if (ok < 0) _write(STDERR_FILENO, "tcnewpgrp failed.\r\n");
ok = settpgrp(STDIN_FILENO);
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");
if (child_argv) {
execvp(child_argv[0], child_argv);
} else {
static char buffer[64] = "login -f ";
strcpy(buffer + 9, whoami);
/* should sniff the correct TERM value from /etc/ttys */
_execve(":usr:bin:login", buffer);
_execve(":usr:sbin:login", buffer);
_execve(":bin:gsh", "gsh");
}
#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");
return 1;
}
Expand Down Expand Up @@ -207,13 +194,17 @@ int main(int argc, char **argv) {
return 1;
}

term_var.value = "\x05\x00vt100";
child_argv = NULL;
for (i = 1; i < argc; ++i) {
char *cp = argv[i];
if (cp[0] != '-') break;
if (strcmp(cp, "--vt52") == 0) {

term_var.value = "\x04\x00vt52";
} else if (strcmp(cp, "--vt100") == 0) {

term_var.value = "\x05\x00vt100";
} else if (strcmp(cp,"--") == 0) {
break;
} else {
ErrWriteCString("Unknown option: ");
ErrWriteCString(cp);
Expand All @@ -225,7 +216,14 @@ int main(int argc, char **argv) {
argc -= 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();

Expand Down

0 comments on commit b838f72

Please sign in to comment.