コード例 #1
0
ファイル: util.c プロジェクト: Fresne/i3-1
/*
 * Starts an i3-nagbar instance with the given parameters. Takes care of
 * handling SIGCHLD and killing i3-nagbar when i3 exits.
 *
 * The resulting PID will be stored in *nagbar_pid and can be used with
 * kill_nagbar() to kill the bar later on.
 *
 */
void start_nagbar(pid_t *nagbar_pid, char *argv[]) {
    if (*nagbar_pid != -1) {
        DLOG("i3-nagbar already running (PID %d), not starting again.\n", *nagbar_pid);
        return;
    }

    *nagbar_pid = fork();
    if (*nagbar_pid == -1) {
        warn("Could not fork()");
        return;
    }

    /* child */
    if (*nagbar_pid == 0)
        exec_i3_utility("i3-nagbar", argv);

    DLOG("Starting i3-nagbar with PID %d\n", *nagbar_pid);

    /* parent */
    /* install a child watcher */
    ev_child *child = smalloc(sizeof(ev_child));
    ev_child_init(child, &nagbar_exited, *nagbar_pid, 0);
    child->data = nagbar_pid;
    ev_child_start(main_loop, child);

    /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
     * still running) */
    ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
    ev_cleanup_init(cleanup, nagbar_cleanup);
    cleanup->data = nagbar_pid;
    ev_cleanup_start(main_loop, cleanup);
}
コード例 #2
0
ファイル: server.c プロジェクト: crudbug/bjoern
static void
ev_signal_on_sigint(struct ev_loop* mainloop, ev_signal* watcher, const int events)
{
  /* Clean up and shut down this thread.
   * (Shuts down the Python interpreter if this is the main thread) */
  ev_cleanup* cleanup_watcher = malloc(sizeof(ev_cleanup));
  ev_cleanup_init(cleanup_watcher, pyerr_set_interrupt);
  ev_cleanup_start(mainloop, cleanup_watcher);

  ev_io_stop(mainloop, &((ThreadInfo*)ev_userdata(mainloop))->accept_watcher);
  ev_signal_stop(mainloop, watcher);
}
コード例 #3
0
ファイル: serv_eventclient.c プロジェクト: mingodad/citadel
eNextState
evcurl_handle_start(AsyncIO *IO)
{
	CURLMcode msta;
	CURLcode sta;
	CURL *chnd;

	SetEVState(IO, eCurlStart);
	chnd = IO->HttpReq.chnd;
	EVCURL_syslog(LOG_DEBUG,
		  "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
	OPT(URL, IO->ConnectMe->PlainUrl);
	if (StrLength(IO->ConnectMe->CurlCreds))
	{
		OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
		OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
	}
	if (StrLength(IO->HttpReq.PostData) > 0)
	{
		OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
		OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));

	}
	else if ((IO->HttpReq.PlainPostDataLen != 0) &&
		 (IO->HttpReq.PlainPostData != NULL))
	{
		OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
		OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
	}
	OPT(HTTPHEADER, IO->HttpReq.headers);

	IO->NextState = eConnect;
	EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
	msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
	if (msta)
	{
		EVCURL_syslog(LOG_ERR,
			  "EVCURL: error attaching to curl multi handle: %s\n",
			  curl_multi_strerror(msta));
	}

	IO->HttpReq.attached = 1;
	ev_async_send (event_base, &WakeupCurl);

	ev_cleanup_init(&IO->abort_by_shutdown,
			IOcurl_abort_shutdown_callback);

	ev_cleanup_start(event_base, &IO->abort_by_shutdown);

	return eReadMessage;
}
コード例 #4
0
ファイル: event_client.c プロジェクト: mingodad/citadel
eNextState QueueAnDBOperation(AsyncIO *IO)
{
	IOAddHandler *h;
	int i;

	SetEVState(IO, eDBQ);
	h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
	h->IO = IO;

	assert(IO->ReAttachCB != NULL);

	h->EvAttch = IO->ReAttachCB;
	ev_cleanup_init(&IO->db_abort_by_shutdown,
			IO_abort_shutdown_callback);
	IO->db_abort_by_shutdown.data = IO;

	pthread_mutex_lock(&DBEventQueueMutex);
	if (DBInboundEventQueue == NULL)
	{
		/* shutting down... */
		free(h);
		EVM_syslog(LOG_DEBUG, "DBEVENT Q exiting.\n");
		pthread_mutex_unlock(&DBEventQueueMutex);
		return eAbort;
	}
	EVM_syslog(LOG_DEBUG, "DBEVENT Q\n");
	i = ++evdb_count ;
	Put(DBInboundEventQueue, IKEY(i), h, NULL);
	pthread_mutex_unlock(&DBEventQueueMutex);

	pthread_mutex_lock(&DBEventExitQueueMutex);
	if (event_db == NULL)
	{
		pthread_mutex_unlock(&DBEventExitQueueMutex);
		return eAbort;
	}
	ev_async_send (event_db, &DBAddJob);
	pthread_mutex_unlock(&DBEventExitQueueMutex);

	EVQM_syslog(LOG_DEBUG, "DBEVENT Q Done.\n");
	return eDBQuery;
}
コード例 #5
0
ファイル: event_client.c プロジェクト: mingodad/citadel
eNextState QueueAnEventContext(AsyncIO *IO)
{
	IOAddHandler *h;
	int i;

	SetEVState(IO, eIOQ);
	h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
	h->IO = IO;

	assert(IO->ReAttachCB != NULL);

	h->EvAttch = IO->ReAttachCB;

	ev_cleanup_init(&IO->abort_by_shutdown,
			IO_abort_shutdown_callback);
	IO->abort_by_shutdown.data = IO;

	pthread_mutex_lock(&EventQueueMutex);
	if (InboundEventQueue == NULL)
	{
		free(h);
		/* shutting down... */
		EVM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
		pthread_mutex_unlock(&EventQueueMutex);
		return eAbort;
	}
	EVM_syslog(LOG_DEBUG, "EVENT Q\n");
	i = ++evbase_count;
	Put(InboundEventQueue, IKEY(i), h, NULL);
	pthread_mutex_unlock(&EventQueueMutex);

	pthread_mutex_lock(&EventExitQueueMutex);
	if (event_base == NULL) {
		pthread_mutex_unlock(&EventExitQueueMutex);
		return eAbort;
	}
	ev_async_send (event_base, &AddJob);
	pthread_mutex_unlock(&EventExitQueueMutex);
	EVM_syslog(LOG_DEBUG, "EVENT Q Done.\n");
	return eSendReply;
}