Porting from linux and dealing with "pipe", "vfork", and "execvp"

4 posts / 0 new
Last post
tekmage
tekmage's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2011-10-09 03:19
Porting from linux and dealing with "pipe", "vfork", and "execvp"
HI All, Looking at porting code from linux and I ran in to the following code block that causes the OS4 system some heart ache:
  1. int
  2. ijs_exec_server(const char *server_cmd, int *pfd_to, int *pfd_from,
  3. int *pchild_pid)
  4. {
  5. int fds_to[2], fds_from[2];
  6. int child_pid;
  7.  
  8. if (pipe (fds_to) < 0)
  9. return -1;
  10. if (pipe (fds_from) < 0)
  11. {
  12. close (fds_to[0]);
  13. close (fds_to[1]);
  14. return -1;
  15. }
  16.  
  17. child_pid = vfork ();
  18. if (child_pid < 0)
  19. {
  20. close (fds_to[0]);
  21. close (fds_to[1]);
  22. close (fds_from[0]);
  23. close (fds_from[1]);
  24. return -1;
  25. }
  26. if (child_pid == 0)
  27. {
  28. int status;
  29. char *argv[8];
  30. int i = 0;
  31.  
  32. close (fds_to[1]);
  33. close (fds_from[0]);
  34.  
  35. dup2 (fds_to[0], STDIN_FILENO);
  36. dup2 (fds_from[1], STDOUT_FILENO);
  37. #define noGDB
  38. #ifdef GDB
  39. argv[i++] = "gdb";
  40. #endif
  41.  
  42. argv[i++] = "sh";
  43. argv[i++] = "-c";
  44.  
  45. argv[i++] = (char *)server_cmd;
  46. argv[i++] = NULL;
  47. status = execvp (argv[0], argv);
  48. if (status < 0)
  49. exit (1);
  50. }
Anyone have a good example for dealing with pipe,vfork, and execvp? Thanks!
hypex
hypex's picture
Offline
Last seen: 1 month 5 hours ago
Joined: 2011-09-09 16:20
I don't quite know the point
I don't quite know the point it but it create some pipes, then a thread, to execute a program and pass arguments to it. You could make your own pipe() if we don't have it with PIPE: I suppose but then you'd need it in the format of the CLib file structure. We used to have vfork() on 68K which creates a thread wuthout MMU tricks to clone variables, so simpler and more like an Amiga child process but one that can change parent memory. And execvp() executes a program while passing arguments direct to it. Whatever it does it might be best to just convert it so it uses Amiga or generic single threaded functions. Or PThreads even.
alfkil
alfkil's picture
Offline
Last seen: 1 year 1 week ago
Joined: 2011-05-10 22:02
@tekmage Compare this with
@tekmage Compare this with this. It might give you some general idea. If you need anything else, just ask :);
tekmage
tekmage's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2011-10-09 03:19
thanks alfkil! I'll review
thanks alfkil! I'll review those files and see how far I can get :) Cheers, Bill
Log in or register to post comments