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