test-event.c revision 12179984a38fe74581333fbcdc11c822d81f505f
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-event.h"
#include "log.h"
#include "util.h"
return 1;
}
static unsigned got_d;
got_unref = true;
return 0;
}
got_a = true;
got_b = true;
got_d++;
if (got_d < 2)
else
} else
assert_not_reached("Yuck!");
return 1;
}
assert(s);
return 1;
}
sd_event_source *p;
assert(s);
if (pid == 0)
_exit(0);
assert_se(sd_event_add_child(sd_event_source_get_event(s), pid, WEXITED, child_handler, INT_TO_PTR('f'), &p) >= 0);
return 1;
}
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);
return 1;
}
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);
} else {
got_c = true;
}
} else
assert_not_reached("Huh?");
return 2;
}
static bool got_exit = false;
got_exit = true;
return 3;
}
static const char ch = 'x';
int a[2] = { -1, -1 }, b[2] = { -1, -1}, d[2] = { -1, -1}, k[2] = { -1, -1 };
assert_se(sd_event_default(&e) >= 0);
assert_se(sd_event_set_watchdog(e, true) >= 0);
/* Test whether we cleanly can destroy an io event source from its own handler */
got_unref = false;
/* Add a oneshot handler, trigger it, re-enable it, and trigger
* it again. */
do_quit = true;
assert_se(sd_event_loop(e) >= 0);
sd_event_unref(e);
close_pipe(a);
close_pipe(b);
close_pipe(d);
close_pipe(k);
return 0;
}