Exemple #1
0
/*
 * 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);
}
Exemple #2
0
static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
{
	CitContext *Ctx;
	long IOID = -1;
	long count = 0;;
	ev_tstamp Now;
	HashList *q;
	void *v;
	HashPos *It;
	long len;
	const char *Key;

	/* get the control command... */
	pthread_mutex_lock(&DBEventQueueMutex);

	if (DBInboundEventQueues[0] == DBInboundEventQueue) {
		DBInboundEventQueue = DBInboundEventQueues[1];
		q = DBInboundEventQueues[0];
	}
	else {
		DBInboundEventQueue = DBInboundEventQueues[0];
		q = DBInboundEventQueues[1];
	}
	pthread_mutex_unlock(&DBEventQueueMutex);

	Now = ev_now (event_db);
	It = GetNewHashPos(q, 0);
	while (GetNextHashPos(q, It, &len, &Key, &v))
	{
		IOAddHandler *h = v;
		eNextState rc;
		count ++;
		if (h->IO->ID == 0)
			h->IO->ID = EvIDSource++;
		IOID = h->IO->ID;
		if (h->IO->StartDB == 0.0)
			h->IO->StartDB = Now;
		h->IO->CitContext->lastcmd = h->IO->Now = Now;

		SetEVState(h->IO, eDBAttach);
		Ctx = h->IO->CitContext;
		become_session(Ctx);
		ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
		rc = h->EvAttch(h->IO);
		switch (rc)
		{
		case eAbort:
			ShutDownDBCLient(h->IO);
		default:
			break;
		}
	}
	DeleteHashPos(&It);
	DeleteHashContent(&q);
	EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
}
Exemple #3
0
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);
}
Exemple #4
0
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;
}
Exemple #5
0
eNextState ReAttachIO(AsyncIO *IO,
		      void *pData,
		      int ReadFirst)
{
	SetEVState(IO, eIOAttach);
	IO->Data = pData;
	become_session(IO->CitContext);
	ev_cleanup_start(event_base, &IO->abort_by_shutdown);
	if (ReadFirst) {
		IO->NextState = eReadMessage;
	}
	else {
		IO->NextState = eSendReply;
	}
	set_start_callback(event_base, IO, 0);

	return IO->NextState;
}