forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordshell.cc
70 lines (58 loc) · 2.18 KB
/
recordshell.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <net/route.h>
#include "nat.hh"
#include "util.hh"
#include "interfaces.hh"
#include "address.hh"
#include "dns_proxy.hh"
#include "http_proxy.hh"
#include "netdevice.hh"
#include "event_loop.hh"
#include "socketpair.hh"
#include "config.h"
#include "backing_store.hh"
#include "process_recorder.hh"
#include "process_recorder.cc"
using namespace std;
int main( int argc, char *argv[] )
{
try {
/* clear environment */
char **user_environment = environ;
environ = nullptr;
check_requirements( argc, argv );
if ( argc < 2 ) {
throw Exception( "Usage", string( argv[ 0 ] ) + " directory [command...]" );
}
/* Make sure directory ends with '/' so we can prepend directory to file name for storage */
string directory( argv[ 1 ] );
if ( directory.empty() ) {
throw Exception( argv[ 0 ], "directory name must be non-empty" );
}
if ( directory.back() != '/' ) {
directory.append( "/" );
}
/* what command will we run inside the container? */
vector < string > command;
if ( argc == 2 ) {
command.push_back( shell_path() );
} else {
for ( int i = 2; i < argc; i++ ) {
command.push_back( argv[ i ] );
}
}
ProcessRecorder<HTTPDiskStore> process_recorder( directory );
return process_recorder.record_process( [&] ( FileDescriptor & parent_channel __attribute__ ((unused)) ) {
/* restore environment and tweak prompt */
environ = user_environment;
prepend_shell_prefix( "[record] " );
return ezexec( command, true );
}, Socket( SocketType::UDP ) /* Dummy socket, unused by HTTPDiskStore */ );
} catch ( const Exception & e ) {
e.perror();
return EXIT_FAILURE;
}
}