2011-11-06 23:51:02 +01:00
|
|
|
#include <sys/wait.h>
|
2011-11-22 17:26:47 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2011-11-24 10:26:36 +01:00
|
|
|
#include <fcntl.h>
|
2011-09-21 20:52:29 +02:00
|
|
|
#include <libmaxsi/platform.h>
|
2011-08-27 23:03:39 +02:00
|
|
|
#include <libmaxsi/process.h>
|
2011-11-07 14:36:35 +01:00
|
|
|
#include <libmaxsi/thread.h>
|
2011-08-27 23:03:39 +02:00
|
|
|
|
2011-09-21 20:52:29 +02:00
|
|
|
using namespace Maxsi;
|
|
|
|
|
|
|
|
int parent(pid_t childid)
|
2011-08-27 23:03:39 +02:00
|
|
|
{
|
2011-11-06 23:51:02 +01:00
|
|
|
int status;
|
|
|
|
waitpid(childid, &status, 0);
|
|
|
|
return status;
|
2011-09-21 20:52:29 +02:00
|
|
|
}
|
2011-08-27 23:03:39 +02:00
|
|
|
|
2011-09-21 20:52:29 +02:00
|
|
|
int child()
|
|
|
|
{
|
2011-08-27 23:03:39 +02:00
|
|
|
const char* programname = "sh";
|
|
|
|
const char* newargv[] = { programname };
|
|
|
|
|
2011-09-21 20:52:29 +02:00
|
|
|
Process::Execute(programname, 1, newargv);
|
2011-08-27 23:03:39 +02:00
|
|
|
|
2011-11-06 23:51:02 +01:00
|
|
|
return 2;
|
2011-08-27 23:03:39 +02:00
|
|
|
}
|
2011-09-21 20:52:29 +02:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2011-11-24 10:26:36 +01:00
|
|
|
if ( open("/dev/tty", O_RDONLY) != 0 ) { return 2; }
|
|
|
|
if ( open("/dev/tty", O_WRONLY | O_APPEND) != 1 ) { return 2; }
|
|
|
|
if ( open("/dev/tty", O_WRONLY | O_APPEND) != 2 ) { return 2; }
|
|
|
|
|
2011-09-21 20:52:29 +02:00
|
|
|
// Reset the terminal's color and the rest of it.
|
|
|
|
printf("\r\e[m\e[J");
|
|
|
|
|
|
|
|
pid_t childpid = Process::Fork();
|
|
|
|
|
|
|
|
if ( childpid < 0 )
|
|
|
|
{
|
2011-11-22 17:26:47 +01:00
|
|
|
printf("init: fork: %s\n", strerror(errno));
|
2011-11-06 23:51:02 +01:00
|
|
|
return 2;
|
2011-09-21 20:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ( childpid == 0 ) ? child() : parent(childpid);
|
|
|
|
}
|