]>
Commit | Line | Data |
---|---|---|
1 | #include <apt-pkg/fileutl.h> | |
2 | #include <apt-pkg/strutl.h> | |
3 | #include <apt-pkg/error.h> | |
4 | ||
5 | #include <sys/types.h> | |
6 | #include <sys/stat.h> | |
7 | #include <sys/wait.h> | |
8 | #include <unistd.h> | |
9 | #include <stdlib.h> | |
10 | #include <fcntl.h> | |
11 | ||
12 | #include <iostream> | |
13 | #include <string> | |
14 | ||
15 | static void callsystem(std::string const &call) | |
16 | { | |
17 | auto ret = system(call.c_str()); | |
18 | if (WIFEXITED(ret) == false || WEXITSTATUS(ret) != 0) | |
19 | _error->Error("Calling %s failed!", call.c_str()); | |
20 | } | |
21 | ||
22 | int main(int, char ** argv) | |
23 | { | |
24 | auto const pid = getpid(); | |
25 | std::string ls; | |
26 | strprintf(ls, "ls -l /proc/%d/fd", pid); | |
27 | callsystem(ls); | |
28 | FileFd t; | |
29 | t.Open(argv[1], FileFd::ReadOnly, FileFd::Extension); | |
30 | callsystem(ls); | |
31 | char buf[1024]; | |
32 | unsigned long long act; | |
33 | while (t.Read(buf, sizeof(buf), &act)) | |
34 | if (act == 0) | |
35 | break; | |
36 | callsystem(ls); | |
37 | t.Seek(5); | |
38 | callsystem(ls); | |
39 | t.Close(); | |
40 | callsystem(ls); | |
41 | auto const ret = _error->PendingError(); | |
42 | _error->DumpErrors(); | |
43 | return ret; | |
44 | } |