/***
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 "fd-util.h"
#include "log.h"
#include "macro.h"
#include "signal-util.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_se(s);
return 1;
}
sd_event_source *p = NULL;
assert_se(s);
if (pid == 0)
_exit(0);
assert_se(sd_event_add_child(sd_event_source_get_event(s), &p, pid, WEXITED, child_handler, INT_TO_PTR('f')) >= 0);
return 1;
}
sd_event_source *p = NULL;
assert_se(s);
assert_se(sd_event_add_signal(sd_event_source_get_event(s), &p, SIGUSR1, signal_handler, INT_TO_PTR('e')) >= 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), &p, defer_handler, INT_TO_PTR('d')) >= 0);
} else {
got_c = true;
}
} else
assert_not_reached("Huh?");
return 2;
}
static bool got_exit = false;
got_exit = true;
return 3;
}
static bool got_post = false;
log_info("got post handler");
got_post = true;
return 2;
}
static void test_basic(void) {
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. */
/* Test for floating event sources */
do_quit = true;
assert_se(sd_event_loop(e) >= 0);
sd_event_unref(e);
safe_close_pair(a);
safe_close_pair(b);
safe_close_pair(d);
safe_close_pair(k);
}
static void test_sd_event_now(void) {
assert_se(sd_event_new(&e) >= 0);
assert_se(sd_event_run(e, 0) == 0);
}
static int last_rtqueue_sigval = 0;
static int n_rtqueue = 0;
n_rtqueue ++;
return 0;
}
static void test_rtqueue(void) {
assert_se(sd_event_default(&e) >= 0);
assert_se(last_rtqueue_sigval == 0);
assert_se(sd_event_run(e, 0) == 0); /* the other SIGUSR2 is dropped, because the first one was still queued */
sd_event_unref(e);
}
test_basic();
test_rtqueue();
return 0;
}