]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-tmpfiles.c
util-lib: split our string related calls from util.[ch] into its own file string...
[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
6482f626 27#include "formats-util.h"
07630cea
LP
28#include "string-util.h"
29#include "util.h"
65b3903f
ZJS
30
31int main(int argc, char** argv) {
32 const char *p = argv[1] ?: "/tmp";
63c372cb 33 char *pattern = strjoina(p, "/systemd-test-XXXXXX");
65b3903f
ZJS
34 _cleanup_close_ int fd, fd2;
35 _cleanup_free_ char *cmd, *cmd2;
36
2d5bdf5b 37 fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
bdf7026e 38 assert_se(fd >= 0);
65b3903f
ZJS
39
40 assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
41 system(cmd);
42
2d5bdf5b 43 fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
bdf7026e 44 assert_se(fd >= 0);
65b3903f
ZJS
45 assert_se(unlink(pattern) == 0);
46
47 assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);
48 system(cmd2);
49
50 return 0;
51}