]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-tmpfiles.c
tree-wide: remove Emacs lines from all files
[thirdparty/systemd.git] / src / test / test-tmpfiles.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24
25 #include "alloc-util.h"
26 #include "fd-util.h"
27 #include "fileio.h"
28 #include "formats-util.h"
29 #include "fs-util.h"
30 #include "log.h"
31 #include "string-util.h"
32 #include "util.h"
33
34 int main(int argc, char** argv) {
35 const char *p = argv[1] ?: "/tmp";
36 char *pattern = strjoina(p, "/systemd-test-XXXXXX");
37 _cleanup_close_ int fd, fd2;
38 _cleanup_free_ char *cmd, *cmd2, *ans, *ans2;
39
40 log_set_max_level(LOG_DEBUG);
41 log_parse_environment();
42
43 fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
44 assert_se(fd >= 0);
45
46 assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
47 (void) system(cmd);
48 assert_se(readlink_malloc(cmd + 6, &ans) >= 0);
49 log_debug("link1: %s", ans);
50 assert_se(endswith(ans, " (deleted)"));
51
52 fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
53 assert_se(fd >= 0);
54 assert_se(unlink(pattern) == 0);
55
56 assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);
57 (void) system(cmd2);
58 assert_se(readlink_malloc(cmd2 + 6, &ans2) >= 0);
59 log_debug("link2: %s", ans2);
60 assert_se(endswith(ans2, " (deleted)"));
61
62 return 0;
63 }