]> git.proxmox.com Git - systemd.git/blame - src/test/test-tmpfiles.c
Imported Upstream version 220
[systemd.git] / src / test / test-tmpfiles.c
CommitLineData
60f067b4
JS
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
60f067b4
JS
22#include <fcntl.h>
23#include <unistd.h>
24#include <stdlib.h>
25#include <stdio.h>
26
27#include "util.h"
e3bff60a 28#include "formats-util.h"
60f067b4
JS
29
30int main(int argc, char** argv) {
31 const char *p = argv[1] ?: "/tmp";
e735f4d4 32 char *pattern = strjoina(p, "/systemd-test-XXXXXX");
60f067b4
JS
33 _cleanup_close_ int fd, fd2;
34 _cleanup_free_ char *cmd, *cmd2;
35
36 fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
5eef597e 37 assert_se(fd >= 0);
60f067b4
JS
38
39 assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
40 system(cmd);
41
42 fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
5eef597e 43 assert_se(fd >= 0);
60f067b4
JS
44 assert_se(unlink(pattern) == 0);
45
46 assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);
47 system(cmd2);
48
49 return 0;
50}