Ejemplo n.º 1
0
void
services_die(const char *msg, int rboot)
{
  ilog(L_NOTICE, "Dying: %s", msg);

  cleanup_channel_modes();
  cleanup_conf();
#ifdef HAVE_RUBY
  cleanup_ruby();
#endif
  cleanup_db();
  cleanup_modules();

  EVP_cleanup();

  send_queued_all();
  exit_client(&me, &me, "Services shutting down");
  send_queued_all();

  if(me.uplink != NULL)
    MyFree(me.uplink->server);
 
  cleanup_client();
  cleanup_channel();
  cleanup_interface();
  cleanup_mqueue();
  cleanup_tor();
  unregister_callback(iorecv_cb);
  unregister_callback(connected_cb);
  unregister_callback(iosend_cb);
  libio_cleanup();
  exit(rboot);
}
Ejemplo n.º 2
0
/*
 * child_fn() - Inside container
 */
int child_fn(void *arg)
{
	pid_t pid, ppid;
	mqd_t mqd;
	char buf[5];

	/* Set process id and parent pid */
	pid = getpid();
	ppid = getppid();

	if (pid != CHILD_PID || ppid != PARENT_PID) {
		tst_resm(TBROK, "cinit: pidns is not created");
		cleanup_mqueue(TBROK, NO_STEP, 0);
	}

	/* Close the appropriate end of pipe */
	close(father_to_child[1]);

	/* Is parent ready to receive a message? */
	read(father_to_child[0], buf, 5);
	if (strcmp(buf, "f:ok")) {
		tst_resm(TBROK, "cinit: parent did not send the message!");
		cleanup_mqueue(TBROK, NO_STEP, 0);
	}
	tst_resm(TINFO, "cinit: my father is ready to receive a message");

	mqd = ltp_syscall(__NR_mq_open, mqname, O_WRONLY, 0, NULL);
	if (mqd == (mqd_t) - 1) {
		tst_resm(TBROK, "cinit: mq_open() failed (%s)",
			 strerror(errno));
		cleanup_mqueue(TBROK, NO_STEP, 0);
	}
	tst_resm(TINFO, "cinit: mq_open succeeded");

	if (mq_send(mqd, MSG, strlen(MSG), MSG_PRIO) == (mqd_t) - 1) {
		tst_resm(TBROK, "cinit: mq_send() failed (%s)",
			 strerror(errno));
		cleanup_mqueue(TBROK, C_STEP_0, mqd);
	}
	tst_resm(TINFO, "cinit: mq_send() succeeded");

	/* Cleanup and exit */
	cleanup_resources(C_STEP_1, mqd);
	exit(0);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	pid_t cpid;
	mqd_t mqd;
	struct sigevent notif;
	struct sigaction sa;
	int status;
	struct notify_info info;

	setup();

	if (pipe(father_to_child) == -1) {
		tst_resm(TBROK, "parent: pipe() failed. aborting!");
		cleanup_mqueue(TBROK, NO_STEP, 0);
	}

	ltp_syscall(__NR_mq_unlink, mqname);
	mqd =
	    ltp_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
		    NULL);
	if (mqd == (mqd_t) - 1) {
		tst_resm(TBROK, "parent: mq_open() failed (%s)",
			 strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_0, 0);
	}
	tst_resm(TINFO, "parent: successfully created posix mqueue");

	/* container creation on PID namespace */
	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
	if (cpid < 0) {
		tst_resm(TBROK, "parent: clone() failed(%s)", strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_1, mqd);
	}
	tst_resm(TINFO, "parent: successfully created child (pid = %d)", cpid);

	/* Register for notification on message arrival */
	notif.sigev_notify = SIGEV_SIGNAL;
	notif.sigev_signo = SIGUSR1;
	info.mqd = mqd;
	info.pid = cpid;
	notif.sigev_value.sival_ptr = &info;
	if (ltp_syscall(__NR_mq_notify, mqd, &notif) == (mqd_t) -1) {
		tst_resm(TBROK, "parent: mq_notify() failed (%s)",
			 strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_1, mqd);
	}
	tst_resm(TINFO, "parent: successfully registered for notification");

	/* Define handler for SIGUSR1 */
	sa.sa_flags = SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sa.sa_sigaction = father_signal_handler;
	if (sigaction(SIGUSR1, &sa, NULL) == -1) {
		tst_resm(TBROK, "parent: sigaction() failed(%s)",
			 strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_2, mqd);
	}
	tst_resm(TINFO, "parent: successfully registered handler for SIGUSR1");

	/* Close the appropriate end of pipe */
	close(father_to_child[0]);

	/* Tell the child a message can be sent */
	if (write(father_to_child[1], "f:ok", 5) != 5) {
		tst_resm(TBROK, "parent: pipe is broken(%s)", strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_2, mqd);
	}

	sleep(3);

	/* Wait for child to finish */
	if (wait(&status) == -1) {
		tst_resm(TBROK, "parent: wait() failed(%s)", strerror(errno));
		cleanup_mqueue(TBROK, F_STEP_1, mqd);
	}

	cleanup_mqueue(result, F_STEP_3, mqd);

	tst_exit();
}