Lines Matching refs:sitter
97 DBusBabysitter *sitter; in _dbus_babysitter_new() local
99 sitter = dbus_new0 (DBusBabysitter, 1); in _dbus_babysitter_new()
100 if (sitter == NULL) in _dbus_babysitter_new()
103 sitter->refcount = 1; in _dbus_babysitter_new()
105 sitter->start_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL); in _dbus_babysitter_new()
106 if (sitter->start_sync_event == NULL) in _dbus_babysitter_new()
108 _dbus_babysitter_unref (sitter); in _dbus_babysitter_new()
113 sitter->end_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL); in _dbus_babysitter_new()
114 if (sitter->end_sync_event == NULL) in _dbus_babysitter_new()
116 _dbus_babysitter_unref (sitter); in _dbus_babysitter_new()
121 sitter->child_handle = NULL; in _dbus_babysitter_new()
123 sitter->socket_to_babysitter = sitter->socket_to_main = -1; in _dbus_babysitter_new()
125 sitter->argc = 0; in _dbus_babysitter_new()
126 sitter->argv = NULL; in _dbus_babysitter_new()
127 sitter->envp = NULL; in _dbus_babysitter_new()
129 sitter->watches = _dbus_watch_list_new (); in _dbus_babysitter_new()
130 if (sitter->watches == NULL) in _dbus_babysitter_new()
132 _dbus_babysitter_unref (sitter); in _dbus_babysitter_new()
136 sitter->have_spawn_errno = FALSE; in _dbus_babysitter_new()
137 sitter->have_child_status = FALSE; in _dbus_babysitter_new()
139 return sitter; in _dbus_babysitter_new()
149 _dbus_babysitter_ref (DBusBabysitter *sitter) in _dbus_babysitter_ref() argument
152 _dbus_assert (sitter != NULL); in _dbus_babysitter_ref()
153 _dbus_assert (sitter->refcount > 0); in _dbus_babysitter_ref()
155 sitter->refcount += 1; in _dbus_babysitter_ref()
157 return sitter; in _dbus_babysitter_ref()
161 close_socket_to_babysitter (DBusBabysitter *sitter) in close_socket_to_babysitter() argument
165 if (sitter->sitter_watch != NULL) in close_socket_to_babysitter()
167 _dbus_assert (sitter->watches != NULL); in close_socket_to_babysitter()
168 _dbus_watch_list_remove_watch (sitter->watches, sitter->sitter_watch); in close_socket_to_babysitter()
169 _dbus_watch_invalidate (sitter->sitter_watch); in close_socket_to_babysitter()
170 _dbus_watch_unref (sitter->sitter_watch); in close_socket_to_babysitter()
171 sitter->sitter_watch = NULL; in close_socket_to_babysitter()
174 if (sitter->socket_to_babysitter != -1) in close_socket_to_babysitter()
176 _dbus_close_socket (sitter->socket_to_babysitter, NULL); in close_socket_to_babysitter()
177 sitter->socket_to_babysitter = -1; in close_socket_to_babysitter()
187 _dbus_babysitter_unref (DBusBabysitter *sitter) in _dbus_babysitter_unref() argument
192 _dbus_assert (sitter != NULL); in _dbus_babysitter_unref()
193 _dbus_assert (sitter->refcount > 0); in _dbus_babysitter_unref()
195 sitter->refcount -= 1; in _dbus_babysitter_unref()
197 if (sitter->refcount == 0) in _dbus_babysitter_unref()
199 close_socket_to_babysitter (sitter); in _dbus_babysitter_unref()
201 if (sitter->socket_to_main != -1) in _dbus_babysitter_unref()
203 _dbus_close_socket (sitter->socket_to_main, NULL); in _dbus_babysitter_unref()
204 sitter->socket_to_main = -1; in _dbus_babysitter_unref()
208 if (sitter->argv != NULL) in _dbus_babysitter_unref()
210 for (i = 0; i < sitter->argc; i++) in _dbus_babysitter_unref()
211 if (sitter->argv[i] != NULL) in _dbus_babysitter_unref()
213 dbus_free (sitter->argv[i]); in _dbus_babysitter_unref()
214 sitter->argv[i] = NULL; in _dbus_babysitter_unref()
216 dbus_free (sitter->argv); in _dbus_babysitter_unref()
217 sitter->argv = NULL; in _dbus_babysitter_unref()
220 if (sitter->envp != NULL) in _dbus_babysitter_unref()
222 char **e = sitter->envp; in _dbus_babysitter_unref()
226 dbus_free (sitter->envp); in _dbus_babysitter_unref()
227 sitter->envp = NULL; in _dbus_babysitter_unref()
230 if (sitter->child_handle != NULL) in _dbus_babysitter_unref()
232 CloseHandle (sitter->child_handle); in _dbus_babysitter_unref()
233 sitter->child_handle = NULL; in _dbus_babysitter_unref()
236 if (sitter->sitter_watch) in _dbus_babysitter_unref()
238 _dbus_watch_invalidate (sitter->sitter_watch); in _dbus_babysitter_unref()
239 _dbus_watch_unref (sitter->sitter_watch); in _dbus_babysitter_unref()
240 sitter->sitter_watch = NULL; in _dbus_babysitter_unref()
243 if (sitter->watches) in _dbus_babysitter_unref()
244 _dbus_watch_list_free (sitter->watches); in _dbus_babysitter_unref()
246 if (sitter->start_sync_event != NULL) in _dbus_babysitter_unref()
249 CloseHandle (sitter->start_sync_event); in _dbus_babysitter_unref()
250 sitter->start_sync_event = NULL; in _dbus_babysitter_unref()
254 if (sitter->end_sync_event != NULL) in _dbus_babysitter_unref()
256 CloseHandle (sitter->end_sync_event); in _dbus_babysitter_unref()
257 sitter->end_sync_event = NULL; in _dbus_babysitter_unref()
261 dbus_free (sitter->executable); in _dbus_babysitter_unref()
263 dbus_free (sitter); in _dbus_babysitter_unref()
268 _dbus_babysitter_kill_child (DBusBabysitter *sitter) in _dbus_babysitter_kill_child() argument
271 if (sitter->child_handle == NULL) in _dbus_babysitter_kill_child()
275 TerminateProcess (sitter->child_handle, 12345); in _dbus_babysitter_kill_child()
284 _dbus_babysitter_get_child_exited (DBusBabysitter *sitter) in _dbus_babysitter_get_child_exited() argument
287 return (sitter->child_handle == NULL); in _dbus_babysitter_get_child_exited()
303 _dbus_babysitter_get_child_exit_status (DBusBabysitter *sitter, in _dbus_babysitter_get_child_exit_status() argument
306 if (!_dbus_babysitter_get_child_exited (sitter)) in _dbus_babysitter_get_child_exit_status()
309 if (!sitter->have_child_status || in _dbus_babysitter_get_child_exit_status()
310 sitter->child_status == STILL_ACTIVE) in _dbus_babysitter_get_child_exit_status()
313 *status = sitter->child_status; in _dbus_babysitter_get_child_exit_status()
327 _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter, in _dbus_babysitter_set_child_exit_error() argument
331 if (!_dbus_babysitter_get_child_exited (sitter)) in _dbus_babysitter_set_child_exit_error()
335 if (sitter->have_spawn_errno) in _dbus_babysitter_set_child_exit_error()
337 char *emsg = _dbus_win_error_string (sitter->spawn_errno); in _dbus_babysitter_set_child_exit_error()
340 sitter->executable, emsg); in _dbus_babysitter_set_child_exit_error()
343 else if (sitter->have_child_status) in _dbus_babysitter_set_child_exit_error()
348 sitter->executable, sitter->child_status); in _dbus_babysitter_set_child_exit_error()
355 sitter->executable); in _dbus_babysitter_set_child_exit_error()
361 _dbus_babysitter_set_watch_functions (DBusBabysitter *sitter, in _dbus_babysitter_set_watch_functions() argument
369 return _dbus_watch_list_set_functions (sitter->watches, in _dbus_babysitter_set_watch_functions()
382 DBusBabysitter *sitter = data; in handle_watch() local
395 close_socket_to_babysitter (sitter); in handle_watch()
398 if (_dbus_babysitter_get_child_exited (sitter) && in handle_watch()
399 sitter->finished_cb != NULL) in handle_watch()
401 sitter->finished_cb (sitter, sitter->finished_data); in handle_watch()
402 sitter->finished_cb = NULL; in handle_watch()
585 DBusBabysitter *sitter = (DBusBabysitter *) parameter; in babysitter() local
588 _dbus_babysitter_ref (sitter); in babysitter()
590 if (sitter->child_setup) in babysitter()
593 (*sitter->child_setup) (sitter->user_data); in babysitter()
596 _dbus_verbose ("babysitter: spawning %s\n", sitter->executable); in babysitter()
599 sitter->child_handle = spawn_program (sitter->executable, in babysitter()
600 sitter->argv, sitter->envp); in babysitter()
603 if (sitter->child_handle == (HANDLE) -1) in babysitter()
605 sitter->child_handle = NULL; in babysitter()
606 sitter->have_spawn_errno = TRUE; in babysitter()
607 sitter->spawn_errno = GetLastError(); in babysitter()
611 SetEvent (sitter->start_sync_event); in babysitter()
613 if (sitter->child_handle != NULL) in babysitter()
619 WaitForSingleObject (sitter->child_handle, INFINITE); in babysitter()
622 ret = GetExitCodeProcess (sitter->child_handle, &status); in babysitter()
624 sitter->child_status = status; in babysitter()
625 sitter->have_child_status = TRUE; in babysitter()
627 CloseHandle (sitter->child_handle); in babysitter()
628 sitter->child_handle = NULL; in babysitter()
632 SetEvent (sitter->end_sync_event); in babysitter()
636 send (sitter->socket_to_main, " ", 1, 0); in babysitter()
638 _dbus_babysitter_unref (sitter); in babysitter()
651 DBusBabysitter *sitter; in _dbus_spawn_async_with_babysitter() local
660 sitter = _dbus_babysitter_new (); in _dbus_spawn_async_with_babysitter()
661 if (sitter == NULL) in _dbus_spawn_async_with_babysitter()
667 sitter->child_setup = child_setup; in _dbus_spawn_async_with_babysitter()
668 sitter->user_data = user_data; in _dbus_spawn_async_with_babysitter()
670 sitter->executable = _dbus_strdup (argv[0]); in _dbus_spawn_async_with_babysitter()
671 if (sitter->executable == NULL) in _dbus_spawn_async_with_babysitter()
678 if (!_dbus_full_duplex_pipe (&sitter->socket_to_babysitter, in _dbus_spawn_async_with_babysitter()
679 &sitter->socket_to_main, in _dbus_spawn_async_with_babysitter()
683 sitter->sitter_watch = _dbus_watch_new (sitter->socket_to_babysitter, in _dbus_spawn_async_with_babysitter()
685 TRUE, handle_watch, sitter, NULL); in _dbus_spawn_async_with_babysitter()
687 if (sitter->sitter_watch == NULL) in _dbus_spawn_async_with_babysitter()
694 if (!_dbus_watch_list_add_watch (sitter->watches, sitter->sitter_watch)) in _dbus_spawn_async_with_babysitter()
698 _dbus_watch_invalidate (sitter->sitter_watch); in _dbus_spawn_async_with_babysitter()
699 _dbus_watch_unref (sitter->sitter_watch); in _dbus_spawn_async_with_babysitter()
700 sitter->sitter_watch = NULL; in _dbus_spawn_async_with_babysitter()
706 sitter->argc = protect_argv (argv, &sitter->argv); in _dbus_spawn_async_with_babysitter()
707 if (sitter->argc == -1) in _dbus_spawn_async_with_babysitter()
712 sitter->envp = envp; in _dbus_spawn_async_with_babysitter()
716 sitter, 0, &sitter_thread_id); in _dbus_spawn_async_with_babysitter()
728 WaitForSingleObject (sitter->start_sync_event, INFINITE); in _dbus_spawn_async_with_babysitter()
732 *sitter_p = sitter; in _dbus_spawn_async_with_babysitter()
734 _dbus_babysitter_unref (sitter); in _dbus_spawn_async_with_babysitter()
742 _dbus_babysitter_unref (sitter); in _dbus_spawn_async_with_babysitter()
748 _dbus_babysitter_set_result_function (DBusBabysitter *sitter, in _dbus_babysitter_set_result_function() argument
752 sitter->finished_cb = finished; in _dbus_babysitter_set_result_function()
753 sitter->finished_data = user_data; in _dbus_babysitter_set_result_function()
782 #define LIVE_CHILDREN(sitter) ((sitter)->child_handle != NULL) argument
785 _dbus_babysitter_block_for_child_exit (DBusBabysitter *sitter) in _dbus_babysitter_block_for_child_exit() argument
787 if (sitter->child_handle == NULL) in _dbus_babysitter_block_for_child_exit()
790 WaitForSingleObject (sitter->end_sync_event, INFINITE); in _dbus_babysitter_block_for_child_exit()
797 DBusBabysitter *sitter; in check_spawn_nonexistent() local
800 sitter = NULL; in check_spawn_nonexistent()
807 if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, in check_spawn_nonexistent()
811 _dbus_babysitter_block_for_child_exit (sitter); in check_spawn_nonexistent()
812 _dbus_babysitter_set_child_exit_error (sitter, &error); in check_spawn_nonexistent()
815 if (sitter) in check_spawn_nonexistent()
816 _dbus_babysitter_unref (sitter); in check_spawn_nonexistent()
842 DBusBabysitter *sitter; in check_spawn_segfault() local
846 sitter = NULL; in check_spawn_segfault()
860 if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, in check_spawn_segfault()
864 _dbus_babysitter_block_for_child_exit (sitter); in check_spawn_segfault()
865 _dbus_babysitter_set_child_exit_error (sitter, &error); in check_spawn_segfault()
870 if (sitter) in check_spawn_segfault()
871 _dbus_babysitter_unref (sitter); in check_spawn_segfault()
897 DBusBabysitter *sitter; in check_spawn_exit() local
901 sitter = NULL; in check_spawn_exit()
915 if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, in check_spawn_exit()
919 _dbus_babysitter_block_for_child_exit (sitter); in check_spawn_exit()
920 _dbus_babysitter_set_child_exit_error (sitter, &error); in check_spawn_exit()
925 if (sitter) in check_spawn_exit()
926 _dbus_babysitter_unref (sitter); in check_spawn_exit()
952 DBusBabysitter *sitter; in check_spawn_and_kill() local
956 sitter = NULL; in check_spawn_and_kill()
970 if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, in check_spawn_and_kill()
974 _dbus_babysitter_kill_child (sitter); in check_spawn_and_kill()
976 _dbus_babysitter_block_for_child_exit (sitter); in check_spawn_and_kill()
978 _dbus_babysitter_set_child_exit_error (sitter, &error); in check_spawn_and_kill()
983 if (sitter) in check_spawn_and_kill()
984 _dbus_babysitter_unref (sitter); in check_spawn_and_kill()