This commit is contained in:
~d6 2023-02-05 00:43:36 -05:00
parent 625527799c
commit ae5b3fc390
1 changed files with 2 additions and 7 deletions

9
term.c
View File

@ -7,7 +7,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
// compile with gcc term.c -lutil // compile with gcc term.c -lutil
@ -31,10 +30,6 @@ int main(int argc, char **argv) {
shell = "/bin/sh"; shell = "/bin/sh";
} }
// find the shell's name
char *slash = strrchr(shell, '/');
char *name = slash == NULL ? shell : slash + 1;
// allocate a pty, fork, inititialize file descriptor // allocate a pty, fork, inititialize file descriptor
int fdm = -1; // allocate file descriptor int fdm = -1; // allocate file descriptor
pid_t pid = forkpty(&fdm, NULL, NULL, NULL); pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
@ -46,9 +41,9 @@ int main(int argc, char **argv) {
setenv("TERM", "ansi", 1); setenv("TERM", "ansi", 1);
// execute shell // execute shell
if (login) { if (login) {
execlp(name, shell, "-l", "-i", NULL); execlp(shell, shell, "-l", "-i", NULL);
} else { } else {
execlp(name, shell, NULL); execlp(shell, shell, NULL);
} }
perror("exec bash failed"); perror("exec bash failed");
} else { // parent } else { // parent