summaryrefslogtreecommitdiffstats
path: root/libmount/src/monitor.c
diff options
context:
space:
mode:
authorKarel Zak2014-12-15 14:23:54 +0100
committerKarel Zak2015-01-06 16:19:02 +0100
commitc6b1e56d262680724452ed13a46ff673b6ef5ff6 (patch)
tree3d3638b54ca025b9b4a917a9b1c9527270b28eb7 /libmount/src/monitor.c
parentlibmount: split monitor initialization (diff)
downloadkernel-qcow2-util-linux-c6b1e56d262680724452ed13a46ff673b6ef5ff6.tar.gz
kernel-qcow2-util-linux-c6b1e56d262680724452ed13a46ff673b6ef5ff6.tar.xz
kernel-qcow2-util-linux-c6b1e56d262680724452ed13a46ff673b6ef5ff6.zip
libmount: cleanup monitor test
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/monitor.c')
-rw-r--r--libmount/src/monitor.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c
index 4a0cbc53c..739bd1afc 100644
--- a/libmount/src/monitor.c
+++ b/libmount/src/monitor.c
@@ -402,28 +402,13 @@ int mnt_monitor_is_changed(struct libmnt_monitor *mn, int fd)
#ifdef TEST_PROGRAM
-int test_monitor(struct libmnt_test *ts, int argc, char *argv[])
+static int my_epoll(struct libmnt_monitor *mn, int fd)
{
- struct libmnt_monitor *mn;
- int fd, efd = -1, rc = -1;
+ int efd = -1, rc = -1;
struct epoll_event ev = { .events = 0 };
- mn = mnt_new_monitor();
- if (!mn) {
- warn("failed to allocate monitor");
- goto done;
- }
-
- if (mnt_monitor_enable_userspace(mn, TRUE, NULL)) {
- warn("failed to initialize userspace monitor");
- goto done;
- }
-
- fd = mnt_monitor_userspace_get_fd(mn);
- if (fd < 0) {
- warn("failed to initialize userspace monitor fd");
- goto done;
- }
+ assert(mn);
+ assert(fd >= 0);
efd = epoll_create1(EPOLL_CLOEXEC);
if (efd < 0) {
@@ -432,10 +417,6 @@ int test_monitor(struct libmnt_test *ts, int argc, char *argv[])
}
ev.events = EPOLLPRI | EPOLLIN;
-
- /* set data is necessary only if you want to use epoll for more file
- * descriptors, then epoll_wait() returns data associated with the file
- * descriptor. */
ev.data.fd = fd;
rc = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
@@ -465,17 +446,44 @@ int test_monitor(struct libmnt_test *ts, int argc, char *argv[])
rc = 0;
done:
- printf("done");
- mnt_unref_monitor(mn);
if (efd >= 0)
close(efd);
return rc;
}
+int test_low_user(struct libmnt_test *ts, int argc, char *argv[])
+{
+ struct libmnt_monitor *mn;
+ int fd, rc = -1;
+
+ mn = mnt_new_monitor();
+ if (!mn) {
+ warn("failed to allocate monitor");
+ goto done;
+ }
+
+ if (mnt_monitor_enable_userspace(mn, TRUE, NULL)) {
+ warn("failed to initialize userspace monitor");
+ goto done;
+ }
+
+ fd = mnt_monitor_userspace_get_fd(mn);
+ if (fd < 0) {
+ warn("failed to initialize userspace monitor fd");
+ goto done;
+ }
+
+ rc = my_epoll(mn, fd);
+done:
+ printf("done");
+ mnt_unref_monitor(mn);
+ return rc;
+}
+
int main(int argc, char *argv[])
{
struct libmnt_test tss[] = {
- { "--low-userspace", test_monitor, "tests low-level userspace monitor" },
+ { "--low-userspace", test_low_user, "tests low-level userspace monitor" },
{ NULL }
};