2016-11-25 17:18:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Jehanne.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Giacomo Tesio <giacomo@tesio.it>
|
|
|
|
*
|
|
|
|
* Jehanne is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3 of the License.
|
|
|
|
*
|
|
|
|
* Jehanne is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <u.h>
|
2017-04-19 23:33:14 +02:00
|
|
|
#include <lib9.h>
|
2016-11-25 17:18:40 +01:00
|
|
|
|
|
|
|
#include "console.h"
|
|
|
|
|
|
|
|
int linecontrol;
|
|
|
|
int blind;
|
|
|
|
int crnl;
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprint(2, "usage: %s [-d dbgfile] [-s srvname] comfile [program [args]]\n", argv0);
|
|
|
|
exits("usage");
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
opencom(char *file)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2019-11-26 02:25:23 +01:00
|
|
|
if((fd = sys_open(file, ORDWR)) <= 0)
|
2016-11-25 17:18:40 +01:00
|
|
|
sysfatal("open: %r");
|
|
|
|
dup(fd, 0);
|
|
|
|
dup(fd, 1);
|
2019-11-26 02:25:23 +01:00
|
|
|
sys_close(fd);
|
2016-11-25 17:18:40 +01:00
|
|
|
}
|
|
|
|
void
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, devmnt;
|
|
|
|
char *srv = nil;
|
|
|
|
|
|
|
|
blind = 0;
|
|
|
|
linecontrol = 1;
|
|
|
|
crnl = 1;
|
|
|
|
ARGBEGIN{
|
|
|
|
case 'd':
|
|
|
|
enabledebug(EARGF(usage()));
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
srv = EARGF(usage());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}ARGEND;
|
|
|
|
|
|
|
|
if(srv && argc != 1)
|
|
|
|
usage();
|
|
|
|
if(argc < 2 && srv == nil)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
opencom(argv[0]);
|
|
|
|
|
|
|
|
fd = servecons(passthrough, passthrough, &devmnt);
|
|
|
|
|
|
|
|
if(srv){
|
2016-12-01 00:09:42 +01:00
|
|
|
debug("%s (%d): posting %d\n", argv0, getpid(), fd);
|
2016-11-25 17:18:40 +01:00
|
|
|
post(srv, fd);
|
|
|
|
exits(0);
|
|
|
|
} else {
|
|
|
|
debug("%s %d: mounting cons for %s\n", argv0, getpid(), argv[0]);
|
2019-11-26 02:25:23 +01:00
|
|
|
if(sys_mount(fd, -1, "/dev", MBEFORE, "", devmnt) == -1)
|
2016-11-25 17:18:40 +01:00
|
|
|
sysfatal("mount (%s): %r", argv[0]);
|
|
|
|
|
2019-11-26 02:25:23 +01:00
|
|
|
debug("%s (%d): all services started, ready to sys_exec(%s)\n", argv0, getpid(), argv[0]);
|
2016-11-25 17:18:40 +01:00
|
|
|
|
|
|
|
/* become the requested program */
|
2019-11-26 02:25:23 +01:00
|
|
|
sys_rfork(RFNOTEG|RFREND|RFCFDG);
|
2016-11-25 17:18:40 +01:00
|
|
|
|
2019-11-26 02:25:23 +01:00
|
|
|
fd = sys_open("/dev/cons", OREAD);
|
|
|
|
fd = sys_open("/dev/cons", OWRITE);
|
2016-11-25 17:18:40 +01:00
|
|
|
if(dup(fd, 2) != 2)
|
|
|
|
sysfatal("bad FDs: %r");
|
2020-11-15 13:30:09 +01:00
|
|
|
sys_exec(argv[1], (const char**)(argv+1));
|
2016-11-25 17:18:40 +01:00
|
|
|
sysfatal("exec %s: %r", argv[1]);
|
|
|
|
}
|
|
|
|
}
|