]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-tmpfiles.c
util: split out escaping code into escape.[ch]
[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
ZJS
22#include <fcntl.h>
23#include <unistd.h>
24#include <stdlib.h>
25#include <stdio.h>
26
27#include "util.h"
6482f626 28#include "formats-util.h"
65b3903f
ZJS
29
30int main(int argc, char** argv) {
31 const char *p = argv[1] ?: "/tmp";
63c372cb 32 char *pattern = strjoina(p, "/systemd-test-XXXXXX");
65b3903f
ZJS
33 _cleanup_close_ int fd, fd2;
34 _cleanup_free_ char *cmd, *cmd2;
35
2d5bdf5b 36 fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
bdf7026e 37 assert_se(fd >= 0);
65b3903f
ZJS
38
39 assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
40 system(cmd);
41
2d5bdf5b 42 fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
bdf7026e 43 assert_se(fd >= 0);
65b3903f
ZJS
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}