Exemplo n.º 1
0
static void
signal_handler(int sig_num)
{
#ifdef WITH_THREAD
#ifdef WITH_PTH
	if (PyThread_get_thread_ident() != main_thread) {
		pth_raise(*(pth_t *) main_thread, sig_num);
		return;
	}
#endif
	/* See NOTES section above */
	if (getpid() == main_pid) {
#endif
		is_tripped++;
		Handlers[sig_num].tripped = 1;
		Py_AddPendingCall(checksignals_witharg, NULL);
#ifdef WITH_THREAD
	}
#endif
#ifdef SIGCHLD
	if (sig_num == SIGCHLD) {
		/* To avoid infinite recursion, this signal remains
		   reset until explicit re-instated.
		   Don't clear the 'func' field as it is our pointer
		   to the Python handler... */
		return;
	}
#endif
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(sig_num, 1);
#endif
	PyOS_setsig(sig_num, signal_handler);
}
Exemplo n.º 2
0
int 
ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
{
	return pth_raise( thread, signo ) ? 0 : errno;
}
Exemplo n.º 3
0
void call_backtrace(int fd, zend_backtrace_globals* g, backtrace_callback_t callback)
{
#ifdef DEBUG
	fprintf(stderr, "[%d]: call_backtrace()\n", getpid());
	fflush(stderr);
#endif

	if (!callback) {
		return;
	}

	HashPosition pos;
	void** current;
	THREAD_T self = tsrm_thread_id();
	int processed_self = 0;

	tsrm_mutex_lock(mutex);

	for (
			zend_hash_internal_pointer_reset_ex(&thread_ids, &pos);
			SUCCESS == zend_hash_get_current_data_ex(&thread_ids, (void**)&current, &pos);
			zend_hash_move_forward_ex(&thread_ids, &pos)
	)
	{
		char* key;
		uint key_len;
		ulong idx;
		int type;

		type = zend_hash_get_current_key_ex(&thread_ids, &key, &key_len, &idx, 0, &pos);
		if (HASH_KEY_IS_STRING == type) {
			idx = atol(key);
		}

#ifdef DEBUG
		fprintf(stderr, "[%d]: Trying thread %lu\n", getpid(), idx);
		fflush(stderr);
#endif

		if (idx) {
#if defined(PTHREADS)
			int res = pthread_kill((pthread_t)idx, 0);
			if (res) {
				continue;
			}
#elif defined(GNUPTH)
			int res = pth_raise((pth_t)idx, 0);
			if (!res) {
				continue;
			}
#endif

#ifdef DEBUG
			fprintf(stderr, "[%d]: Processing thread %lu\n", getpid(), idx);
			fflush(stderr);
#endif

			THREAD_T thread_id = idx;

#if defined(PTHREADS)
			if (!processed_self && pthread_equal(thread_id, self)) {
				processed_self = 1;
			}
#else
			if (thread_id == self) {
				processed_self = 1;
			}
#endif

			void*** tsrm_ls = (void***)ts_resource_ex(0, &thread_id);
			callback(fd, g, tsrm_ls);
#ifdef DEBUG
			fprintf(stderr, "[%d]: Processed thread %lu\n", getpid(), idx);
			fflush(stderr);
#endif
		}
	}

	if (!processed_self) {
#ifdef DEBUG
		fprintf(stderr, "[%d]: Processing self\n", getpid());
		fflush(stderr);
#endif
		void*** tsrm_ls = (void***)ts_resource_ex(0, (THREAD_T*)0);
		callback(fd, g, tsrm_ls);
#ifdef DEBUG
		fprintf(stderr, "[%d]: Processed self\n", getpid());
		fflush(stderr);
#endif
	}

	tsrm_mutex_unlock(mutex);
}