/src/wrappers/glib/library/utilities/glib_spawning_processes.e

http://github.com/tybor/Liberty · Specman e · 468 lines · 2 code · 77 blank · 389 comment · 0 complexity · ff28df323f17a93a52f3208b2b8a294b MD5 · raw file

  1. class GLIB_SPAWNING_PROCESSES
  2. -- Spawning Processes
  3. -- Spawning Processes -- process launching with fork()/exec().
  4. -- Synopsis
  5. -- #include <glib.h>
  6. -- enum GSpawnError;
  7. -- #define G_SPAWN_ERROR
  8. -- enum GSpawnFlags;
  9. -- void (*GSpawnChildSetupFunc) (gpointer user_data);
  10. -- gboolean g_spawn_async_with_pipes (const gchar *working_directory,
  11. -- gchar **argv,
  12. -- gchar **envp,
  13. -- GSpawnFlags flags,
  14. -- GSpawnChildSetupFunc child_setup,
  15. -- gpointer user_data,
  16. -- GPid *child_pid,
  17. -- gint *standard_input,
  18. -- gint *standard_output,
  19. -- gint *standard_error,
  20. -- GError **error);
  21. -- gboolean g_spawn_async (const gchar *working_directory,
  22. -- gchar **argv,
  23. -- gchar **envp,
  24. -- GSpawnFlags flags,
  25. -- GSpawnChildSetupFunc child_setup,
  26. -- gpointer user_data,
  27. -- GPid *child_pid,
  28. -- GError **error);
  29. -- gboolean g_spawn_sync (const gchar *working_directory,
  30. -- gchar **argv,
  31. -- gchar **envp,
  32. -- GSpawnFlags flags,
  33. -- GSpawnChildSetupFunc child_setup,
  34. -- gpointer user_data,
  35. -- gchar **standard_output,
  36. -- gchar **standard_error,
  37. -- gint *exit_status,
  38. -- GError **error);
  39. -- gboolean g_spawn_command_line_async (const gchar *command_line,
  40. -- GError **error);
  41. -- gboolean g_spawn_command_line_sync (const gchar *command_line,
  42. -- gchar **standard_output,
  43. -- gchar **standard_error,
  44. -- gint *exit_status,
  45. -- GError **error);
  46. -- void g_spawn_close_pid (GPid pid);
  47. -- Description
  48. -- Details
  49. -- enum GSpawnError
  50. -- typedef enum
  51. -- {
  52. -- G_SPAWN_ERROR_FORK, /* fork failed due to lack of memory */
  53. -- G_SPAWN_ERROR_READ, /* read or select on pipes failed */
  54. -- G_SPAWN_ERROR_CHDIR, /* changing to working dir failed */
  55. -- G_SPAWN_ERROR_ACCES, /* execv() returned EACCES */
  56. -- G_SPAWN_ERROR_PERM, /* execv() returned EPERM */
  57. -- G_SPAWN_ERROR_2BIG, /* execv() returned E2BIG */
  58. -- G_SPAWN_ERROR_NOEXEC, /* execv() returned ENOEXEC */
  59. -- G_SPAWN_ERROR_NAMETOOLONG, /* "" "" ENAMETOOLONG */
  60. -- G_SPAWN_ERROR_NOENT, /* "" "" ENOENT */
  61. -- G_SPAWN_ERROR_NOMEM, /* "" "" ENOMEM */
  62. -- G_SPAWN_ERROR_NOTDIR, /* "" "" ENOTDIR */
  63. -- G_SPAWN_ERROR_LOOP, /* "" "" ELOOP */
  64. -- G_SPAWN_ERROR_TXTBUSY, /* "" "" ETXTBUSY */
  65. -- G_SPAWN_ERROR_IO, /* "" "" EIO */
  66. -- G_SPAWN_ERROR_NFILE, /* "" "" ENFILE */
  67. -- G_SPAWN_ERROR_MFILE, /* "" "" EMFLE */
  68. -- G_SPAWN_ERROR_INVAL, /* "" "" EINVAL */
  69. -- G_SPAWN_ERROR_ISDIR, /* "" "" EISDIR */
  70. -- G_SPAWN_ERROR_LIBBAD, /* "" "" ELIBBAD */
  71. -- G_SPAWN_ERROR_FAILED /* other fatal failure, error->message
  72. -- * should explain
  73. -- */
  74. -- } GSpawnError;
  75. -- Error codes returned by spawning processes.
  76. -- G_SPAWN_ERROR_FORK Fork failed due to lack of memory.
  77. -- G_SPAWN_ERROR_READ Read or select on pipes failed.
  78. -- G_SPAWN_ERROR_CHDIR Changing to working directory failed.
  79. -- G_SPAWN_ERROR_ACCES execv() returned EACCES.
  80. -- G_SPAWN_ERROR_PERM execv() returned EPERM.
  81. -- G_SPAWN_ERROR_2BIG execv() returned E2BIG.
  82. -- G_SPAWN_ERROR_NOEXEC execv() returned ENOEXEC.
  83. -- G_SPAWN_ERROR_NAMETOOLONG execv() returned ENAMETOOLONG.
  84. -- G_SPAWN_ERROR_NOENT execv() returned ENOENT.
  85. -- G_SPAWN_ERROR_NOMEM execv() returned ENOMEM.
  86. -- G_SPAWN_ERROR_NOTDIR execv() returned ENOTDIR.
  87. -- G_SPAWN_ERROR_LOOP execv() returned ELOOP.
  88. -- G_SPAWN_ERROR_TXTBUSY execv() returned ETXTBUSY.
  89. -- G_SPAWN_ERROR_IO execv() returned EIO.
  90. -- G_SPAWN_ERROR_NFILE execv() returned ENFILE.
  91. -- G_SPAWN_ERROR_MFILE execv() returned EMFILE.
  92. -- G_SPAWN_ERROR_INVAL execv() returned EINVAL.
  93. -- G_SPAWN_ERROR_ISDIR execv() returned EISDIR.
  94. -- G_SPAWN_ERROR_LIBBAD execv() returned ELIBBAD.
  95. -- G_SPAWN_ERROR_FAILED Some other fatal failure, error->message should
  96. -- explain.
  97. -- ---------------------------------------------------------------------------------
  98. -- G_SPAWN_ERROR
  99. -- #define G_SPAWN_ERROR g_spawn_error_quark ()
  100. -- Error domain for spawning processes. Errors in this domain will be from the
  101. -- GSpawnError enumeration. See GError for information on error domains.
  102. -- ---------------------------------------------------------------------------------
  103. -- enum GSpawnFlags
  104. -- typedef enum
  105. -- {
  106. -- G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0,
  107. -- G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
  108. -- /* look for argv[0] in the path i.e. use execvp() */
  109. -- G_SPAWN_SEARCH_PATH = 1 << 2,
  110. -- /* Dump output to /dev/null */
  111. -- G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
  112. -- G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
  113. -- G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
  114. -- G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
  115. -- } GSpawnFlags;
  116. -- Flags passed to g_spawn_sync(), g_spawn_async() and g_spawn_async_with_pipes().
  117. -- G_SPAWN_LEAVE_DESCRIPTORS_OPEN the parent's open file descriptors will be
  118. -- inherited by the child; otherwise all descriptors
  119. -- except stdin/stdout/stderr will be closed before
  120. -- calling exec() in the child.
  121. -- G_SPAWN_DO_NOT_REAP_CHILD the child will not be automatically reaped; you
  122. -- must call waitpid() or handle SIGCHLD yourself, or
  123. -- the child will become a zombie.
  124. -- G_SPAWN_SEARCH_PATH argv[0] need not be an absolute path, it will be
  125. -- looked for in the user's PATH.
  126. -- G_SPAWN_STDOUT_TO_DEV_NULL the child's standad output will be discarded,
  127. -- instead of going to the same location as the
  128. -- parent's standard output.
  129. -- G_SPAWN_STDERR_TO_DEV_NULL the child's standard error will be discarded.
  130. -- G_SPAWN_CHILD_INHERITS_STDIN the child will inherit the parent's standard input
  131. -- (by default, the child's standard input is
  132. -- attached to /dev/null).
  133. -- G_SPAWN_FILE_AND_ARGV_ZERO the first element of argv is the file to execute,
  134. -- while the remaining elements are the actual
  135. -- argument vector to pass to the file. Normally
  136. -- g_spawn_async_with_pipes() uses argv[0] as the
  137. -- file to execute, and passes all of argv to the
  138. -- child.
  139. -- ---------------------------------------------------------------------------------
  140. -- GSpawnChildSetupFunc ()
  141. -- void (*GSpawnChildSetupFunc) (gpointer user_data);
  142. -- Specifies the type of the setup function passed to g_spawn_async(),
  143. -- g_spawn_sync() and g_spawn_async_with_pipes(). On POSIX platforms it is called in
  144. -- the child after GLib has performed all the setup it plans to perform but before
  145. -- calling exec(). On POSIX actions taken in this function will thus only affect the
  146. -- child, not the parent.
  147. -- On Windows the function is called in the parent. Its usefulness on Windows is
  148. -- thus questionable. In many cases executing the child setup function in the parent
  149. -- can have ill effects, and you should be very careful when porting software to
  150. -- Windows that uses child setup functions.
  151. -- user_data : user data to pass to the function.
  152. -- ---------------------------------------------------------------------------------
  153. -- g_spawn_async_with_pipes ()
  154. -- gboolean g_spawn_async_with_pipes (const gchar *working_directory,
  155. -- gchar **argv,
  156. -- gchar **envp,
  157. -- GSpawnFlags flags,
  158. -- GSpawnChildSetupFunc child_setup,
  159. -- gpointer user_data,
  160. -- GPid *child_pid,
  161. -- gint *standard_input,
  162. -- gint *standard_output,
  163. -- gint *standard_error,
  164. -- GError **error);
  165. -- Executes a child program asynchronously (your program will not block waiting for
  166. -- the child to exit). The child program is specified by the only argument that must
  167. -- be provided, argv. argv should be a NULL-terminated array of strings, to be
  168. -- passed as the argument vector for the child. The first string in argv is of
  169. -- course the name of the program to execute. By default, the name of the program
  170. -- must be a full path; the PATH shell variable will only be searched if you pass
  171. -- the G_SPAWN_SEARCH_PATH flag.
  172. -- On Windows, note that all the string or string vector arguments to this function
  173. -- and the other g_spawn*() functions are in UTF-8, the GLib file name encoding.
  174. -- Unicode characters that are not part of the system codepage passed in argument
  175. -- vectors will be correctly available in the spawned program only if it uses wide
  176. -- character API to retrieve its command line. For C programs built with Microsoft's
  177. -- tools it is enough to make the program have a wmain() instead of main(). wmain()
  178. -- has a wide character argument vector as parameter.
  179. -- At least currently, mingw doesn't support wmain(), so if you use mingw to develop
  180. -- the spawned program, it will have to call the undocumented function
  181. -- __wgetmainargs() to get the wide character argument vector and environment. See
  182. -- gspawn-win32-helper.c in the GLib sources or init.c in the mingw runtime sources
  183. -- for a prototype for that function. Alternatively, you can retrieve the Win32
  184. -- system level wide character command line passed to the spawned program using the
  185. -- GetCommandLineW() function.
  186. -- On Windows the low-level child process creation API CreateProcess() doesn't use
  187. -- argument vectors, but a command line. The C runtime library's spawn*() family of
  188. -- functions (which g_spawn_async_with_pipes() eventually calls) paste the argument
  189. -- vector elements together into a command line, and the C runtime startup code does
  190. -- a corresponding reconstruction of an argument vector from the command line, to be
  191. -- passed to main(). Complications arise when you have argument vector elements that
  192. -- contain spaces of double quotes. The spawn*() functions don't do any quoting or
  193. -- escaping, but on the other hand the startup code does do unquoting and unescaping
  194. -- in order to enable receiving arguments with embedded spaces or double quotes. To
  195. -- work around this asymmetry, g_spawn_async_with_pipes() will do quoting and
  196. -- escaping on argument vector elements that need it before calling the C runtime
  197. -- spawn() function.
  198. -- envp is a NULL-terminated array of strings, where each string has the form
  199. -- KEY=VALUE. This will become the child's environment. If envp is NULL, the child
  200. -- inherits its parent's environment.
  201. -- flags should be the bitwise OR of any flags you want to affect the function's
  202. -- behaviour. The G_SPAWN_DO_NOT_REAP_CHILD means that the child will not
  203. -- automatically be reaped; you must use a GChildWatch source to be notified about
  204. -- the death of the child process. Eventually you must call g_spawn_close_pid() on
  205. -- the child_pid, in order to free resources which may be associated with the child
  206. -- process. (On Unix, using a GChildWatch source is equivalent to calling waitpid()
  207. -- or handling the SIGCHLD signal manually. On Windows, calling g_spawn_close_pid()
  208. -- is equivalent to calling CloseHandle() on the process handle returned in
  209. -- child_pid).
  210. -- G_SPAWN_LEAVE_DESCRIPTORS_OPEN means that the parent's open file descriptors will
  211. -- be inherited by the child; otherwise all descriptors except stdin/stdout/stderr
  212. -- will be closed before calling exec() in the child. G_SPAWN_SEARCH_PATH means that
  213. -- argv[0] need not be an absolute path, it will be looked for in the user's PATH.
  214. -- G_SPAWN_STDOUT_TO_DEV_NULL means that the child's standard output will be
  215. -- discarded, instead of going to the same location as the parent's standard output.
  216. -- If you use this flag, standard_output must be NULL. G_SPAWN_STDERR_TO_DEV_NULL
  217. -- means that the child's standard error will be discarded, instead of going to the
  218. -- same location as the parent's standard error. If you use this flag,
  219. -- standard_error must be NULL. G_SPAWN_CHILD_INHERITS_STDIN means that the child
  220. -- will inherit the parent's standard input (by default, the child's standard input
  221. -- is attached to /dev/null). If you use this flag, standard_input must be NULL.
  222. -- G_SPAWN_FILE_AND_ARGV_ZERO means that the first element of argv is the file to
  223. -- execute, while the remaining elements are the actual argument vector to pass to
  224. -- the file. Normally g_spawn_async_with_pipes() uses argv[0] as the file to
  225. -- execute, and passes all of argv to the child.
  226. -- child_setup and user_data are a function and user data. On POSIX platforms, the
  227. -- function is called in the child after GLib has performed all the setup it plans
  228. -- to perform (including creating pipes, closing file descriptors, etc.) but before
  229. -- calling exec(). That is, child_setup is called just before calling exec() in the
  230. -- child. Obviously actions taken in this function will only affect the child, not
  231. -- the parent. On Windows, there is no separate fork() and exec() functionality.
  232. -- Child processes are created and run with a single API call, CreateProcess().
  233. -- child_setup is called in the parent process just before creating the child
  234. -- process. You should carefully consider what you do in child_setup if you intend
  235. -- your software to be portable to Windows.
  236. -- If non-NULL, child_pid will on Unix be filled with the child's process ID. You
  237. -- can use the process ID to send signals to the child, or to waitpid() if you
  238. -- specified the G_SPAWN_DO_NOT_REAP_CHILD flag. On Windows, child_pid will be
  239. -- filled with a handle to the child process only if you specified the
  240. -- G_SPAWN_DO_NOT_REAP_CHILD flag. You can then access the child process using the
  241. -- Win32 API, for example wait for its termination with the WaitFor*() functions, or
  242. -- examine its exit code with GetExitCodeProcess(). You should close the handle with
  243. -- CloseHandle() or g_spawn_close_pid() when you no longer need it.
  244. -- If non-NULL, the standard_input, standard_output, standard_error locations will
  245. -- be filled with file descriptors for writing to the child's standard input or
  246. -- reading from its standard output or standard error. The caller of
  247. -- g_spawn_async_with_pipes() must close these file descriptors when they are no
  248. -- longer in use. If these parameters are NULL, the corresponding pipe won't be
  249. -- created.
  250. -- If standard_input is NULL, the child's standard input is attached to /dev/null
  251. -- unless G_SPAWN_CHILD_INHERITS_STDIN is set.
  252. -- If standard_error is NULL, the child's standard error goes to the same location
  253. -- as the parent's standard error unless G_SPAWN_STDERR_TO_DEV_NULL is set.
  254. -- If standard_output is NULL, the child's standard output goes to the same location
  255. -- as the parent's standard output unless G_SPAWN_STDOUT_TO_DEV_NULL is set.
  256. -- error can be NULL to ignore errors, or non-NULL to report errors. If an error is
  257. -- set, the function returns FALSE. Errors are reported even if they occur in the
  258. -- child (for example if the executable in argv[0] is not found). Typically the
  259. -- message field of returned errors should be displayed to users. Possible errors
  260. -- are those from the G_SPAWN_ERROR domain.
  261. -- If an error occurs, child_pid, standard_input, standard_output, and
  262. -- standard_error will not be filled with valid values.
  263. -- If child_pid is not NULL and an error does not occur then the returned pid must
  264. -- be closed using g_spawn_close_pid().
  265. -- working_directory : child's current working directory, or NULL to inherit
  266. -- parent's, in the GLib file name encoding
  267. -- argv : child's argument vector, in the GLib file name encoding
  268. -- envp : child's environment, or NULL to inherit parent's, in the GLib
  269. -- file name encoding
  270. -- flags : flags from GSpawnFlags
  271. -- child_setup : function to run in the child just before exec()
  272. -- user_data : user data for child_setup
  273. -- child_pid : return location for child process ID, or NULL
  274. -- standard_input : return location for file descriptor to write to child's
  275. -- stdin, or NULL
  276. -- standard_output : return location for file descriptor to read child's stdout,
  277. -- or NULL
  278. -- standard_error : return location for file descriptor to read child's stderr,
  279. -- or NULL
  280. -- error : return location for error
  281. -- Returns : TRUE on success, FALSE if an error was set
  282. -- ---------------------------------------------------------------------------------
  283. -- g_spawn_async ()
  284. -- gboolean g_spawn_async (const gchar *working_directory,
  285. -- gchar **argv,
  286. -- gchar **envp,
  287. -- GSpawnFlags flags,
  288. -- GSpawnChildSetupFunc child_setup,
  289. -- gpointer user_data,
  290. -- GPid *child_pid,
  291. -- GError **error);
  292. -- See g_spawn_async_with_pipes() for a full description; this function simply calls
  293. -- the g_spawn_async_with_pipes() without any pipes.
  294. -- working_directory : child's current working directory, or NULL to inherit
  295. -- parent's
  296. -- argv : child's argument vector
  297. -- envp : child's environment, or NULL to inherit parent's
  298. -- flags : flags from GSpawnFlags
  299. -- child_setup : function to run in the child just before exec()
  300. -- user_data : user data for child_setup
  301. -- child_pid : return location for child process ID, or NULL
  302. -- error : return location for error
  303. -- Returns : TRUE on success, FALSE if error is set
  304. -- ---------------------------------------------------------------------------------
  305. -- g_spawn_sync ()
  306. -- gboolean g_spawn_sync (const gchar *working_directory,
  307. -- gchar **argv,
  308. -- gchar **envp,
  309. -- GSpawnFlags flags,
  310. -- GSpawnChildSetupFunc child_setup,
  311. -- gpointer user_data,
  312. -- gchar **standard_output,
  313. -- gchar **standard_error,
  314. -- gint *exit_status,
  315. -- GError **error);
  316. -- Executes a child synchronously (waits for the child to exit before returning).
  317. -- All output from the child is stored in standard_output and standard_error, if
  318. -- those parameters are non-NULL. If exit_status is non-NULL, the exit status of the
  319. -- child is stored there as it would be returned by waitpid(); standard UNIX macros
  320. -- such as WIFEXITED() and WEXITSTATUS() must be used to evaluate the exit status.
  321. -- If an error occurs, no data is returned in standard_output, standard_error, or
  322. -- exit_status.
  323. -- This function calls g_spawn_async_with_pipes() internally; see that function for
  324. -- full details on the other parameters and details on how these functions work on
  325. -- Windows.
  326. -- working_directory : child's current working directory, or NULL to inherit
  327. -- parent's
  328. -- argv : child's argument vector
  329. -- envp : child's environment, or NULL to inherit parent's
  330. -- flags : flags from GSpawnFlags
  331. -- child_setup : function to run in the child just before exec()
  332. -- user_data : user data for child_setup
  333. -- standard_output : return location for child output
  334. -- standard_error : return location for child error messages
  335. -- exit_status : return location for child exit status, as returned by
  336. -- waitpid()
  337. -- error : return location for error
  338. -- Returns : TRUE on success, FALSE if an error was set.
  339. -- ---------------------------------------------------------------------------------
  340. -- g_spawn_command_line_async ()
  341. -- gboolean g_spawn_command_line_async (const gchar *command_line,
  342. -- GError **error);
  343. -- A simple version of g_spawn_async() that parses a command line with
  344. -- g_shell_parse_argv() and passes it to g_spawn_async(). Runs a command line in the
  345. -- background. Unlike g_spawn_async(), the G_SPAWN_SEARCH_PATH flag is enabled,
  346. -- other flags are not. Note that G_SPAWN_SEARCH_PATH can have security
  347. -- implications, so consider using g_spawn_async() directly if appropriate. Possible
  348. -- errors are those from g_shell_parse_argv() and g_spawn_async().
  349. -- The same concerns on Windows apply as for g_spawn_command_line_sync().
  350. -- command_line : a command line
  351. -- error : return location for errors
  352. -- Returns : TRUE on success, FALSE if error is set.
  353. -- ---------------------------------------------------------------------------------
  354. -- g_spawn_command_line_sync ()
  355. -- gboolean g_spawn_command_line_sync (const gchar *command_line,
  356. -- gchar **standard_output,
  357. -- gchar **standard_error,
  358. -- gint *exit_status,
  359. -- GError **error);
  360. -- A simple version of g_spawn_sync() with little-used parameters removed, taking a
  361. -- command line instead of an argument vector. See g_spawn_sync() for full details.
  362. -- command_line will be parsed by g_shell_parse_argv(). Unlike g_spawn_sync(), the
  363. -- G_SPAWN_SEARCH_PATH flag is enabled. Note that G_SPAWN_SEARCH_PATH can have
  364. -- security implications, so consider using g_spawn_sync() directly if appropriate.
  365. -- Possible errors are those from g_spawn_sync() and those from
  366. -- g_shell_parse_argv().
  367. -- If exit_status is non-NULL, the exit status of the child is stored there as it
  368. -- would be returned by waitpid(); standard UNIX macros such as WIFEXITED() and
  369. -- WEXITSTATUS() must be used to evaluate the exit status.
  370. -- On Windows, please note the implications of g_shell_parse_argv() parsing
  371. -- command_line. Parsing is done according to Unix shell rules, not Windows command
  372. -- interpreter rules. Space is a separator, and backslashes are special. Thus you
  373. -- cannot simply pass a command_line containing canonical Windows paths, like
  374. -- "c:\\program files\\app\\app.exe", as the backslashes will be eaten, and the
  375. -- space will act as a separator. You need to enclose such paths with single quotes,
  376. -- like "'c:\\program files\\app\\app.exe' 'e:\\folder\\argument.txt'".
  377. -- command_line : a command line
  378. -- standard_output : return location for child output
  379. -- standard_error : return location for child errors
  380. -- exit_status : return location for child exit status, as returned by waitpid()
  381. -- error : return location for errors
  382. -- Returns : TRUE on success, FALSE if an error was set
  383. -- ---------------------------------------------------------------------------------
  384. -- g_spawn_close_pid ()
  385. -- void g_spawn_close_pid (GPid pid);
  386. -- On some platforms, notably WIN32, the GPid type represents a resource which must
  387. -- be closed to prevent resource leaking. g_spawn_close_pid() is provided for this
  388. -- purpose. It should be used on all platforms, even though it doesn't do anything
  389. -- under UNIX.
  390. -- pid : The process identifier to close
  391. end -- class GLIB_SPAWNING_PROCESSES