#include #include #include #include "ninitfeatures.h" static int infd=-1, outfd=-1; static uint32t env_free=0; #include "contrib/put_env.h" static void die_xx(char *s) { char *aa[3]; INIT_ARGS3(aa, "/sbin/ninit","",0); write(2,"\nupdate: ",9); write(2,s,str_len(s)); write(2,"\n",1); while (1) { execve(*aa,aa,environ); /* really panic !!! */ nano_sleep(0,800000000); } } static void safe_read(void *buf, int len) { if (read(infd,buf,len) != len) die_xx("error reading"); } static void safe_write() { if (write(outfd,"1",1) != 1) die_xx("error writing"); } int main(int Argc, char **Argv) { uint32t len,i,k; char **argv, **env, *s; s = Argv[0]; s[str_rchr(s, '/')] = 0; chdir(s); infd=open("../in",O_RDWR); outfd=open("../out",O_RDWR|O_NONBLOCK); fcntl(infd,F_SETFD,FD_CLOEXEC); fcntl(outfd,F_SETFD,FD_CLOEXEC); if (infd<0 || outfd<0) { write(outfd,"0",1); die_xx("pipes error"); } write(outfd,"7",1); safe_read(&len,sizeof(len)); argv = alloca((len+5) * sizeof(char *)); if (argv==0) die_xx("out of memory"); safe_write(); for (i=0; i