e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier/***
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier This file is part of systemd
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier Copyright 2014 Ronny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier systemd is free software; you can redistribute it and/or modify it
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier under the terms of the GNU Lesser General Public License as published by
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier the Free Software Foundation; either version 2.1 of the License, or
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier (at your option) any later version.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier systemd is distributed in the hope that it will be useful, but
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier Lesser General Public License for more details.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier You should have received a copy of the GNU Lesser General Public License
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier***/
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier#include <unistd.h>
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier#include "async.h"
0d39fa9c69b97a2ceb156053deef69c0866c2b97Lennart Poettering#include "fileio.h"
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier#include "macro.h"
0d39fa9c69b97a2ceb156053deef69c0866c2b97Lennart Poettering#include "util.h"
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalierstatic bool test_async = false;
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalierstatic void *async_func(void *arg) {
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier test_async = true;
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier return NULL;
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier}
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalierint main(int argc, char *argv[]) {
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier int fd;
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier char name[] = "/tmp/test-asynchronous_close.XXXXXX";
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier assert_se(fd >= 0);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier asynchronous_close(fd);
c1d630d5fd3c0b3307811d51f9840652e066a0f2Zbigniew Jędrzejewski-Szmek
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier assert_se(asynchronous_job(async_func, NULL) >= 0);
c1d630d5fd3c0b3307811d51f9840652e066a0f2Zbigniew Jędrzejewski-Szmek
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier assert_se(asynchronous_sync() >= 0);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier sleep(1);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier assert_se(fcntl(fd, F_GETFD) == -1);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier assert_se(test_async);
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier
1f532d7ef35210f11e75cfcab0535e65a37901f3Ronny Chevalier unlink(name);
1f532d7ef35210f11e75cfcab0535e65a37901f3Ronny Chevalier
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier return 0;
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier}