]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-tmpfiles.c
2 This file is part of systemd.
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
25 #include "alloc-util.h"
28 #include "formats-util.h"
31 #include "string-util.h"
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
;
40 log_set_max_level(LOG_DEBUG
);
41 log_parse_environment();
43 fd
= open_tmpfile(p
, O_RDWR
|O_CLOEXEC
);
46 assert_se(asprintf(&cmd
, "ls -l /proc/"PID_FMT
"/fd/%d", getpid(), fd
) > 0);
48 assert_se(readlink_malloc(cmd
+ 6, &ans
) >= 0);
49 log_debug("link1: %s", ans
);
50 assert_se(endswith(ans
, " (deleted)"));
52 fd2
= mkostemp_safe(pattern
, O_RDWR
|O_CLOEXEC
);
54 assert_se(unlink(pattern
) == 0);
56 assert_se(asprintf(&cmd2
, "ls -l /proc/"PID_FMT
"/fd/%d", getpid(), fd2
) > 0);
58 assert_se(readlink_malloc(cmd2
+ 6, &ans2
) >= 0);
59 log_debug("link2: %s", ans2
);
60 assert_se(endswith(ans2
, " (deleted)"));