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