blob: 7c4b957593c890835f459d74dc27201aefb671bb (
plain)
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
|
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <iostream>
#include <string>
static void callsystem(std::string const &call)
{
auto ret = system(call.c_str());
if (WIFEXITED(ret) == false || WEXITSTATUS(ret) != 0)
_error->Error("Calling %s failed!", call.c_str());
}
int main(int, char ** argv)
{
auto const pid = getpid();
std::string ls;
strprintf(ls, "ls -l /proc/%d/fd", pid);
callsystem(ls);
FileFd t;
t.Open(argv[1], FileFd::ReadOnly, FileFd::Extension);
callsystem(ls);
char buf[1024];
unsigned long long act;
while (t.Read(buf, sizeof(buf), &act))
if (act == 0)
break;
callsystem(ls);
t.Seek(5);
callsystem(ls);
t.Close();
callsystem(ls);
auto const ret = _error->PendingError();
_error->DumpErrors();
return ret;
}
|