Beispiel #1
0
void communicate(struct sigaction* signal_action, struct Arguments* args) {
	// Tell the sever we can go
	notify_server();

	for (; args->count > 0; --args->size) {
		wait_for_signal(signal_action);
		notify_server();
	}
}
Beispiel #2
0
int
message_demuxer (mach_msg_header_t *inp,
		 mach_msg_header_t *outp)
{
  extern int process_server (mach_msg_header_t *, mach_msg_header_t *);
  extern int notify_server (mach_msg_header_t *, mach_msg_header_t *);
  extern int proc_exc_server (mach_msg_header_t *, mach_msg_header_t *);
  int status;

  mutex_lock (&global_lock);
  status = (process_server (inp, outp)
	    || notify_server (inp, outp)
	    || ports_interrupt_server (inp, outp)
	    || proc_exc_server (inp, outp));
  mutex_unlock (&global_lock);
  return status;
}
Beispiel #3
0
__private_extern__
boolean_t
config_demux(mach_msg_header_t *request, mach_msg_header_t *reply)
{
	Boolean				processed = FALSE;

	/*
	 * (attempt to) process SCDynamicStore requests.
	 */
	processed = config_server(request, reply);
	if (processed) {
		return TRUE;
	}

	/*
	 * (attempt to) process (NO MORE SENDERS) notification messages.
	 */
	processed = notify_server(request, reply);
	if (processed) {
		return TRUE;
	}

	/*
	 * unknown message ID, log and return an error.
	 */
	SCLog(TRUE, LOG_ERR, CFSTR("config_demux(): unknown message ID (%d) received"), request->msgh_id);
	reply->msgh_bits        = MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(request->msgh_bits), 0);
	reply->msgh_remote_port = request->msgh_remote_port;
	reply->msgh_size        = sizeof(mig_reply_error_t);	/* Minimal size */
	reply->msgh_local_port  = MACH_PORT_NULL;
	reply->msgh_id          = request->msgh_id + 100;
	((mig_reply_error_t *)reply)->NDR = NDR_record;
	((mig_reply_error_t *)reply)->RetCode = MIG_BAD_ID;

	return FALSE;
}
Beispiel #4
0
int main(int argc, char const *argv[]) {

	shmem *mem;
	const char *geometry;
	int lemon_in, lemon_out;
	int tries=0;
	struct pollfd fds[1];

	fds[0].events = POLLIN;

	geometry = (argc < 2) ? DEFAULT_GEOM : argv[1];
	if (validate_geometry(geometry) < 0){
		fprintf(stderr, "please provide a valid window geometry. E.g. 1920x22+0+0  (widthxheight+X+Y)\n");
		return -1;
	}

	if ((mem = setup_memory(0)) == MEM_FAILED){
		printf("Spawning data daemon\n");

		if (spawn_daemon() < 0){
			fprintf(stderr, "failed to start daemon\n");
			exit(-1);
		}

		while ((mem = setup_memory(0)) == MEM_FAILED){
			if (tries++ > 10){
				fprintf(stderr, "failed to connect to daemon\n");
				exit(-1);
			}
			sleep(1);
		}

		printf("connected to new data source\n");
	} else {
		printf("Connected to running data source.\n");
	}

	spawn_bar(&lemon_in, &lemon_out, geometry);
	fds[0].fd = lemon_out;
	
	notify_server(mem->server);
	catch_signals();

	//@todo allow an escape for when server dies
	while (1) {
		DEBUG_(printf("waiting for wakeup signal\n"));

		//block. wait here for lemonbar click output, or update signal from server
		//we could block with read() or something, but let's plan for multiple
		//sources for the future.
		if (poll(fds, 1, -1) < 0){
			if (errno != EINTR){
				perror("poll");
				break;
			}
		}

		if (fds[0].revents & POLLIN) {
			fds[0].revents = 0; //clear for next round
			//something was clicked
			process_click(fds[0].fd);
		} else {
			//must have gotten pinged by server
			//@todo verify SIGUSR1 vs other signals (which generally just exit anyway)
			update_bar(mem,lemon_in);
		}
	}

	return -1;
}