ref: db729cbb50a43ed357ac8153b8a9717684aa6f4b
parent: d4cc35f3872350716d0ae1cb5777a7a826cf2a27
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Apr 17 23:13:15 EDT 2017
vt: send interrupt on exit, open logfile OCEXEC, run host after environment got exported, send rest of arguments to host
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -131,24 +131,18 @@
int
start_host(void)
{
- int fd;
-
switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
case 0:
- fd = open("/dev/cons", OREAD);
- dup(fd,0);
- if(fd != 0)
- close(fd);
- fd = open("/dev/cons", OWRITE);
- dup(fd,1);
- dup(fd,2);
- if(fd != 1 && fd !=2)
- close(fd);
+ close(0);
+ open("/dev/cons", OREAD);
+ close(1);
+ open("/dev/cons", OWRITE);
+ dup(1, 2);
execl("/bin/rc","rcX",nil);
- fprint(2,"failed to start up rc\n");
+ fprint(2, "failed to start up rc: %r\n");
_exits("rc");
case -1:
- fprint(2,"rc startup: fork error\n");
+ fprint(2,"rc startup: fork: %r\n");
_exits("rc_fork");
}
return open("/mnt/cons/data", ORDWR);
@@ -192,6 +186,7 @@
static void
shutdown(void)
{
+ send_interrupt();
postnote(PNGROUP, getpid(), "exit");
threadexitsall(nil);
}
@@ -208,7 +203,7 @@
void
usage(void)
{
- fprint(2, "usage: %s [-2abcrx] [-f font] [-l logfile]\n", argv0);
+ fprint(2, "usage: %s [-2abcrx] [-f font] [-l logfile] [cmd...]\n", argv0);
exits("usage");
}
@@ -244,7 +239,7 @@
break;
case 'l':
p = EARGF(usage());
- logfd = create(p, OWRITE, 0666);
+ logfd = create(p, OWRITE|OCEXEC, 0666);
if(logfd < 0)
sysfatal("could not create log file: %s: %r", p);
break;
@@ -269,9 +264,6 @@
if((cs = consctl()) == nil)
sysfatal("consctl failed: %r");
cs->raw = rflag;
- hc = chancreate(sizeof(Rune*), 1);
- if((hostfd = start_host()) >= 0)
- proccreate(hostreader, nil, BSIZE+1024);
histp = hist;
menu2.item = menutext2;
@@ -301,9 +293,18 @@
resize();
- if(argc > 0) {
- sendnchars(strlen(argv[0]),argv[0]);
- sendnchars(1,"\n");
+ hc = chancreate(sizeof(Rune*), 1);
+ if((hostfd = start_host()) >= 0)
+ proccreate(hostreader, nil, BSIZE+1024);
+
+ while(*argv != nil){
+ sendnchars(strlen(*argv), *argv);
+ if(argv[1] == nil){
+ sendnchars(1, "\n");
+ break;
+ }
+ sendnchars(1, " ");
+ argv++;
}
}