Exemplo n.º 1
0
NS_INTERNAL void ns_call(struct ns_connection *nc, int ev, void *ev_data) {
  unsigned long flags_before;
  ns_event_handler_t ev_handler;

  DBG(("%p flags=%lu ev=%d ev_data=%p rmbl=%d", nc, nc->flags, ev, ev_data,
       (int) nc->recv_mbuf.len));

#ifndef NS_DISABLE_FILESYSTEM
  /* LCOV_EXCL_START */
  if (nc->mgr->hexdump_file != NULL && ev != NS_POLL &&
      ev != NS_SEND /* handled separately */) {
    int len = (ev == NS_RECV ? *(int *) ev_data : 0);
    ns_hexdump_connection(nc, nc->mgr->hexdump_file, len, ev);
  }
/* LCOV_EXCL_STOP */
#endif

  /*
   * If protocol handler is specified, call it. Otherwise, call user-specified
   * event handler.
   */
  ev_handler = nc->proto_handler ? nc->proto_handler : nc->handler;
  if (ev_handler != NULL) {
    flags_before = nc->flags;
    ev_handler(nc, ev, ev_data);
    if (nc->flags != flags_before) {
      nc->flags = (flags_before & ~_NS_CALLBACK_MODIFIABLE_FLAGS_MASK) |
                  (nc->flags & _NS_CALLBACK_MODIFIABLE_FLAGS_MASK);
    }
  }
}
Exemplo n.º 2
0
static void check_events(void)
{
	void *p, *p2;

	printf("%s\n", __func__);
	dut_alloc_set_event_cb(ev_handler);
	dut_alloc_init(heap, sizeof heap);

	ev_handler(-1, 0, ~0);
	p = dut_malloc(1024);
	ASSERT_EV(ALLOC_EV_ALLOC_LEVEL, p);
	assert(latest_a >= 1024);

	p2 = dut_malloc(1024);
	ASSERT_EV(ALLOC_EV_ALLOC_LEVEL, p2);
	assert(latest_a >= 2 * 1024);

	ev_handler(-1, NULL, ~0);
	dut_free(p2);
	/* No event.  */
	ASSERT_EV(-1, NULL);
	dut_free(p);
	ASSERT_EV(-1, NULL);

	/* Alloc an amount that can't be statisfied.  */
	p = dut_malloc(sizeof heap + 1);
	assert(p == NULL);
	ASSERT_EV(ALLOC_EV_ALLOC, NULL);
	assert(latest_a >= sizeof heap + 1);

	/* Free of NULL is ok.  */
	ev_handler(-1, NULL, ~0);
	dut_free(NULL);
	ASSERT_EV(-1, NULL);

	ev_handler(-1, NULL, ~0);
	p = dut_malloc(0);
	assert(p); /* minic's malloc returns valid ptrs.  */
	ASSERT_EV(ALLOC_EV_ALLOC, p);
	assert(latest_a == 0);

	dut_alloc_exit();
	/* Unregister.  */
	dut_alloc_set_event_cb(NULL);
	printf("%s OK\n", __func__);
}
Exemplo n.º 3
0
int main(
	int argc,	/* Argument count */
	char **argv)	/* Argument vector */
{
	sam_event_t event;
	event_handler_t ev_handler;

	if (dbupd_init(argc, argv) < 0) {
		return (EXIT_FAILURE);
	}

connect:
	/* Keep trying to connect to database until shutdown or retry limit */
	while (num_retry < RETRY_MAX && !is_shutdown &&
	    dbupd_connect() < 0) {
		num_retry++;
		sleep(RETRY_SLEEP);
	}

	/* Keep trying to process events until retry limit or shutdown */
	while (num_retry < RETRY_MAX && !is_shutdown) {
		int status = sam_fsa_read_event(&fsa_inv, &event);
		if (status < 0) {
			/* Error reading event for fs_name */
			SendCustMsg(HERE, 26003, fs_name);
			num_retry++;
			sleep(RETRY_SLEEP);
			goto connect;
		} else if (status == FSA_EOF) {
			/* Reached the end of events, goto sleep for a while */
			sleep(EOF_SLEEP);
		} else if (IS_DB_INODE(event.ev_id.ino) &&
		    IS_DB_INODE(event.ev_pid.ino)) {
			/* Got next event, get event handler and process */
			ev_handler = get_event_handler(event.ev_num);
			if (ev_handler == NULL) {
				/* Unrecognized event for fsname */
				SendCustMsg(HERE, 26006, event.ev_num, fs_name);
				continue;
			}

			/* Handle event */
			if (ev_handler(db_ctx, &event) < 0) {
				mysql_rollback(db_ctx->mysql);
				/* Event processing failed, running check */
				SendCustMsg(HERE, 26007,
				    get_event_name(event.ev_num),
				    event.ev_id.ino, event.ev_id.gen, fs_name);
				if (check_consistency(db_ctx,
				    &event, TRUE) < 0) {
					mysql_rollback(db_ctx->mysql);
					sam_fsa_rollback(&fsa_inv);
					/* Consistency check failed, retrying */
					SendCustMsg(HERE, 26008);
					num_retry++;
					goto connect;
				} else {
					mysql_commit(db_ctx->mysql);
				}
			} else {
				mysql_commit(db_ctx->mysql);
			}
			num_retry = 0;
		} else {
			/*
			 * Event's inode doesn't belong in database,
			 * run consistency to be sure.
			 */
			(void) check_consistency(db_ctx, &event, TRUE);
		}
	}

	/* Close event log */
	sam_fsa_close_inv(&fsa_inv);

	/* Close database */
	sam_db_disconnect(db_ctx);
	sam_db_context_free(db_ctx);

	if (num_retry >= RETRY_MAX) {
		/* Retry max reached, exiting */
		SendCustMsg(HERE, 26005, RETRY_MAX);
	}

	return (is_shutdown && num_retry < RETRY_MAX ?
	    EXIT_SUCCESS : EXIT_FAILURE);
}