1 2 #ifndef PROCESSX_H 3 #define PROCESSX_H 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 #ifndef _GNU_SOURCE 10 #define _GNU_SOURCE 1 11 #endif 12 13 #ifdef __INTEL_COMPILER 14 #define _BSD_SOURCE 1 15 #define _POSIX_C_SOURCE 200809L 16 #endif 17 18 #include "processx-connection.h" 19 #include "errors.h" 20 21 #ifdef _WIN32 22 #include <windows.h> 23 #else 24 #include <unistd.h> 25 #include <stdlib.h> 26 #include <errno.h> 27 #include <fcntl.h> 28 #include <string.h> 29 #include <sys/socket.h> 30 #include <signal.h> 31 #include <sys/wait.h> 32 #include <poll.h> 33 #endif 34 35 #include <Rinternals.h> 36 37 #ifdef _WIN32 38 #include "win/processx-win.h" 39 #else 40 #include "unix/processx-unix.h" 41 #endif 42 43 /* API from R */ 44 45 SEXP processx_exec(SEXP command, SEXP args, SEXP pty, SEXP pty_options, 46 SEXP connections, SEXP env, SEXP windows_verbatim_args, 47 SEXP windows_hide_window, SEXP windows_detached_process, 48 SEXP private_, SEXP cleanup, SEXP wd, SEXP encoding, 49 SEXP tree_id); 50 SEXP processx_wait(SEXP status, SEXP timeout, SEXP name); 51 SEXP processx_is_alive(SEXP status, SEXP name); 52 SEXP processx_get_exit_status(SEXP status, SEXP name); 53 SEXP processx_signal(SEXP status, SEXP signal, SEXP name); 54 SEXP processx_interrupt(SEXP status, SEXP name); 55 SEXP processx_kill(SEXP status, SEXP grace, SEXP name); 56 SEXP processx_get_pid(SEXP status); 57 SEXP processx_create_time(SEXP r_pid); 58 59 SEXP processx_poll(SEXP statuses, SEXP conn, SEXP ms); 60 61 SEXP processx__process_exists(SEXP pid); 62 SEXP processx__proc_start_time(SEXP status); 63 SEXP processx__unload_cleanup(); 64 65 SEXP processx_is_named_pipe_open(SEXP pipe_ext); 66 SEXP processx_close_named_pipe(SEXP pipe_ext); 67 SEXP processx_create_named_pipe(SEXP name, SEXP mode); 68 SEXP processx_write_named_pipe(SEXP pipe_ext, SEXP text); 69 70 SEXP processx_disable_crash_dialog(); 71 72 SEXP processx_base64_encode(SEXP array); 73 SEXP processx_base64_decode(SEXP array); 74 75 /* Common declarations */ 76 77 /* Interruption interval in ms */ 78 #define PROCESSX_INTERRUPT_INTERVAL 200 79 80 /* Various OSes and OS versions return various poll codes when the 81 child's end of the pipe is closed, so we cannot provide a more 82 elaborate API. See e.g. http://www.greenend.org.uk/rjk/tech/poll.html 83 In particular, (recent) macOS return both POLLIN and POLLHUP, 84 Cygwin return POLLHUP, and most others return just POLLIN, so there 85 is not way to distinguish. Essentially, if a read would not block, 86 and the fd is still open, then we return with PXREADY. 87 88 So for us, we just have: 89 */ 90 91 #define PXNOPIPE 1 /* we never captured this output */ 92 #define PXREADY 2 /* one fd is ready, or got EOF */ 93 #define PXTIMEOUT 3 /* no fd is ready before the timeout */ 94 #define PXCLOSED 4 /* fd was already closed when started polling */ 95 #define PXSILENT 5 /* still open, but no data or EOF for now. No timeout, either */ 96 /* but there were events on other fds */ 97 #define PXEVENT 6 /* some event, this is used for curl fds */ 98 99 /* These statuses can be only returned by the pre-poll functions */ 100 101 #define PXHANDLE 7 /* need to poll the set handle */ 102 #define PXSELECT 8 /* need to poll/select the set fd */ 103 104 typedef struct { 105 int windows_verbatim_args; 106 int windows_hide; 107 const char *wd; 108 int pty_echo; 109 int pty_rows; 110 int pty_cols; 111 } processx_options_t; 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif 118