2018-01-02 01:00:07 +01:00
|
|
|
/* Copyright (C) Charles Forsyth
|
|
|
|
* See /doc/license/NOTICE.Plan9-9k.txt for details about the licensing.
|
|
|
|
*/
|
|
|
|
/* Portions of this file are Copyright (C) 2015-2018 Giacomo Tesio <giacomo@tesio.it>
|
|
|
|
* See /doc/license/gpl-2.0.txt for details about the licensing.
|
2016-11-25 17:18:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include "../boot/boot.h"
|
|
|
|
|
|
|
|
static char *paqfile;
|
|
|
|
|
|
|
|
void
|
|
|
|
configembed(Method *m)
|
|
|
|
{
|
|
|
|
if(*sys == '/' || *sys == '#'){
|
|
|
|
/*
|
|
|
|
* if the user specifies the disk in the boot cmd or
|
|
|
|
* 'root is from' prompt, use it
|
|
|
|
*/
|
|
|
|
paqfile = sys;
|
|
|
|
} else if(m->arg){
|
|
|
|
/*
|
|
|
|
* a default is supplied when the kernel is made
|
|
|
|
*/
|
|
|
|
paqfile = m->arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
connectembed(void)
|
|
|
|
{
|
|
|
|
int i, p[2];
|
|
|
|
Dir *dir;
|
|
|
|
char **arg, **argp;
|
|
|
|
|
2017-04-19 23:33:14 +02:00
|
|
|
dir = jehanne_dirstat("/boot/paqfs");
|
2016-11-25 17:18:40 +01:00
|
|
|
if(dir == nil)
|
|
|
|
return -1;
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_free(dir);
|
2016-11-25 17:18:40 +01:00
|
|
|
|
2017-04-19 23:33:14 +02:00
|
|
|
dir = jehanne_dirstat(paqfile);
|
2016-11-25 17:18:40 +01:00
|
|
|
if(dir == nil || dir->mode & DMDIR)
|
|
|
|
return -1;
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_free(dir);
|
2016-11-25 17:18:40 +01:00
|
|
|
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_print("paqfs...");
|
2019-11-26 02:25:23 +01:00
|
|
|
if(sys_bind("#0", "/dev", MREPL) < 0)
|
2017-01-02 00:40:27 +01:00
|
|
|
fatal("bind #0");
|
2019-11-26 02:25:23 +01:00
|
|
|
if(sys_bind("#c", "/dev", MAFTER) < 0)
|
2016-11-25 17:18:40 +01:00
|
|
|
fatal("bind #c");
|
2019-11-26 02:25:23 +01:00
|
|
|
if(sys_bind("#p", "/proc", MREPL) < 0)
|
2016-11-25 17:18:40 +01:00
|
|
|
fatal("bind #p");
|
2017-04-19 23:33:14 +02:00
|
|
|
if(jehanne_pipe(p)<0)
|
2016-11-25 17:18:40 +01:00
|
|
|
fatal("pipe");
|
2017-04-19 23:33:14 +02:00
|
|
|
switch(jehanne_fork()){
|
2016-11-25 17:18:40 +01:00
|
|
|
case -1:
|
|
|
|
fatal("fork");
|
|
|
|
case 0:
|
2017-04-19 23:33:14 +02:00
|
|
|
arg = jehanne_malloc((bargc+5)*sizeof(char*));
|
2016-11-25 17:18:40 +01:00
|
|
|
argp = arg;
|
|
|
|
*argp++ = "/boot/paqfs";
|
|
|
|
*argp++ = "-iv";
|
|
|
|
*argp++ = paqfile;
|
|
|
|
for(i=1; i<bargc; i++)
|
|
|
|
*argp++ = bargv[i];
|
|
|
|
*argp = 0;
|
|
|
|
|
2017-04-19 23:33:14 +02:00
|
|
|
if(jehanne_dup(p[0], 0) != 0)
|
|
|
|
fatal("jehanne_dup(p[0], 0)");
|
|
|
|
if(jehanne_dup(p[1], 1) != 1)
|
|
|
|
fatal("jehanne_dup(p[1], 1)");
|
2019-11-26 02:25:23 +01:00
|
|
|
sys_close(p[0]);
|
|
|
|
sys_close(p[1]);
|
|
|
|
sys_exec("/boot/paqfs", (const char**)arg);
|
2016-11-25 17:18:40 +01:00
|
|
|
fatal("can't exec paqfs");
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_waitpid();
|
2016-11-25 17:18:40 +01:00
|
|
|
|
2019-11-26 02:25:23 +01:00
|
|
|
sys_close(p[1]);
|
2016-11-25 17:18:40 +01:00
|
|
|
return p[0];
|
|
|
|
}
|