From b0de699679e8f1e39af847ed172d1ba605b4370c Mon Sep 17 00:00:00 2001 From: Klaatu Date: Sun, 17 May 2015 15:33:21 +1200 Subject: bulk upload of source --- update.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 update.c (limited to 'update.c') diff --git a/update.c b/update.c new file mode 100644 index 0000000..a7dcc24 --- /dev/null +++ b/update.c @@ -0,0 +1,96 @@ +#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