You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
934 B

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