]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-tmpfiles.c
Merge pull request #2373 from keszybz/man-api-build-3
[thirdparty/systemd.git] / src / test / test-tmpfiles.c
CommitLineData
65b3903f
ZJS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Zbigniew Jędrzejewski-Szmek
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
65b3903f 22#include <fcntl.h>
65b3903f 23#include <stdio.h>
07630cea
LP
24#include <stdlib.h>
25#include <unistd.h>
65b3903f 26
b5efdb8a 27#include "alloc-util.h"
3ffd4af2 28#include "fd-util.h"
0d39fa9c 29#include "fileio.h"
6482f626 30#include "formats-util.h"
07630cea
LP
31#include "string-util.h"
32#include "util.h"
65b3903f
ZJS
33
34int main(int argc, char** argv) {
35 const char *p = argv[1] ?: "/tmp";
63c372cb 36 char *pattern = strjoina(p, "/systemd-test-XXXXXX");
65b3903f
ZJS
37 _cleanup_close_ int fd, fd2;
38 _cleanup_free_ char *cmd, *cmd2;
39
2d5bdf5b 40 fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
bdf7026e 41 assert_se(fd >= 0);
65b3903f
ZJS
42
43 assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
44 system(cmd);
45
2d5bdf5b 46 fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
bdf7026e 47 assert_se(fd >= 0);
65b3903f
ZJS
48 assert_se(unlink(pattern) == 0);
49
50 assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);
51 system(cmd2);
52
53 return 0;
54}