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