-
Notifications
You must be signed in to change notification settings - Fork 0
/
voyeur-watch-open.c
50 lines (41 loc) · 1.16 KB
/
voyeur-watch-open.c
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
#include <stdio.h>
#include <voyeur.h>
extern char** environ;
void open_callback(const char* path,
int oflag,
mode_t mode,
const char* cwd,
int retval,
pid_t pid,
void* userdata)
{
fprintf(stderr, "[OPEN] %s (flags %d) (mode %o) (in %s) (rv %d) (pid %u)\n",
path, oflag, (unsigned) mode, cwd, retval, pid);
}
void close_callback(int fd, int retval, pid_t pid, void* userdata)
{
fprintf(stderr, "[CLOSE] %d (rv %d) (pid %u)\n", fd, retval, pid);
}
void go(int argc, char** argv)
{
voyeur_context_t ctx = voyeur_context_create();
voyeur_observe_open(ctx,
OBSERVE_OPEN_CWD,
open_callback,
NULL);
voyeur_observe_close(ctx,
OBSERVE_CLOSE_DEFAULT,
close_callback,
NULL);
voyeur_exec(ctx, argv[0], argv, environ);
voyeur_context_destroy(ctx);
}
int main(int argc, char** argv)
{
if (argc == 1) {
printf("Usage: %s [command]\n", argv[0]);
return -1;
}
go(argc - 1, argv + 1);
return 0;
}