test-event.c revision 6203e07a83214a55bb1f88508fcda2005c601dea
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani This file is part of systemd.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Copyright 2013 Lennart Poettering
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is free software; you can redistribute it and/or modify it
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani under the terms of the GNU Lesser General Public License as published by
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani the Free Software Foundation; either version 2.1 of the License, or
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani (at your option) any later version.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is distributed in the hope that it will be useful, but
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani WITHOUT ANY WARRANTY; without even the implied warranty of
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Lesser General Public License for more details.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani You should have received a copy of the GNU Lesser General Public License
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani along with systemd; If not, see <http://www.gnu.org/licenses/>.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic int prepare_handler(sd_event_source *s, void *userdata) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani log_info("preparing %c", PTR_TO_INT(userdata));
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic unsigned got_d;
6b3fd9a14d378a35d95ec4be65065708d092bee2Torstein Husebøstatic int io_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani log_info("got IO on %c", PTR_TO_INT(userdata));
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani assert_se(sd_event_source_set_enabled(s, SD_EVENT_ONESHOT) >= 0);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic int child_handler(sd_event_source *s, const siginfo_t *si, void *userdata) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani log_info("got child on %c", PTR_TO_INT(userdata));
9c8e3101ceef00342263d57dce3fa61956824985Lennart Poettering assert_se(sd_event_exit(sd_event_source_get_event(s), 0) >= 0);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic int signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani log_info("got signal on %c", PTR_TO_INT(userdata));
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani assert_se(sigprocmask(SIG_BLOCK, &ss, NULL) >= 0);
assert_se(sd_event_add_child(sd_event_source_get_event(s), pid, WEXITED, child_handler, INT_TO_PTR('f'), &p) >= 0);
sd_event_source *p;
assert(s);
assert_se(sd_event_add_signal(sd_event_source_get_event(s), SIGUSR1, signal_handler, INT_TO_PTR('e'), &p) >= 0);
static bool do_quit = false;
if (do_quit) {
sd_event_source *p;
assert_se(sd_event_add_defer(sd_event_source_get_event(s), defer_handler, INT_TO_PTR('d'), &p) >= 0);
got_c = true;
static bool got_exit = false;
got_exit = true;
do_quit = true;
sd_event_unref(e);
close_pipe(a);
close_pipe(b);