/src/ostree/libglnx/glnx-dirfd.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-  | 
2  |  |  *  | 
3  |  |  * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.  | 
4  |  |  * SPDX-License-Identifier: LGPL-2.0-or-later  | 
5  |  |  *  | 
6  |  |  * This library is free software; you can redistribute it and/or  | 
7  |  |  * modify it under the terms of the GNU Lesser General Public  | 
8  |  |  * License as published by the Free Software Foundation; either  | 
9  |  |  * version 2 of the License, or (at your option) any later version.  | 
10  |  |  *  | 
11  |  |  * This library is distributed in the hope that it will be useful,  | 
12  |  |  * but 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  | 
17  |  |  * License along with this library; if not, write to the  | 
18  |  |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,  | 
19  |  |  * Boston, MA 02111-1307, USA.  | 
20  |  |  */  | 
21  |  |  | 
22  |  | #pragma once  | 
23  |  |  | 
24  |  | #include <glnx-backport-autocleanups.h>  | 
25  |  | #include <glnx-macros.h>  | 
26  |  | #include <glnx-errors.h>  | 
27  |  | #include <limits.h>  | 
28  |  | #include <dirent.h>  | 
29  |  | #include <sys/stat.h>  | 
30  |  | #include <fcntl.h>  | 
31  |  |  | 
32  |  | G_BEGIN_DECLS  | 
33  |  |    | 
34  |  | /**  | 
35  |  |  * glnx_dirfd_canonicalize:  | 
36  |  |  * @fd: A directory file descriptor  | 
37  |  |  *  | 
38  |  |  * It's often convenient in programs to use `-1` for "unassigned fd",  | 
39  |  |  * and also because gobject-introspection doesn't support `AT_FDCWD`,  | 
40  |  |  * libglnx honors `-1` to mean `AT_FDCWD`.  This small inline function  | 
41  |  |  * canonicalizes `-1 -> AT_FDCWD`.  | 
42  |  |  */  | 
43  |  | static inline int  | 
44  |  | glnx_dirfd_canonicalize (int fd)  | 
45  | 18.5k  | { | 
46  | 18.5k  |   if (fd == -1)  | 
47  | 0  |     return AT_FDCWD;  | 
48  | 18.5k  |   return fd;  | 
49  | 18.5k  | } Unexecuted instantiation: fuzz-repo.c:glnx_dirfd_canonicalize glnx-dirfd.c:glnx_dirfd_canonicalize Line  | Count  | Source  |  45  | 12.6k  | { |  46  | 12.6k  |   if (fd == -1)  |  47  | 0  |     return AT_FDCWD;  |  48  | 12.6k  |   return fd;  |  49  | 12.6k  | }  |  
 glnx-shutil.c:glnx_dirfd_canonicalize Line  | Count  | Source  |  45  | 845  | { |  46  | 845  |   if (fd == -1)  |  47  | 0  |     return AT_FDCWD;  |  48  | 845  |   return fd;  |  49  | 845  | }  |  
 Unexecuted instantiation: ostree-repo.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-commit.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-composefs.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-pull.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-refs.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-verity.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-file.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sepolicy.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sysroot.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sysroot-cleanup.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sysroot-deploy.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootconfig-parser.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-deployment.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader-aboot.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader-grub2.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader-zipl.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader-syslinux.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-bootloader-uboot.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-static-delta-core.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-static-delta-processing.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-kernel-args.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-gpg-verifier.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-gpg-verify-result.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sign.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-sign-dummy.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-checksum-instream.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-checksum-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-fs-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-gio-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-gpg-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-keyfile-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-tool-util.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-unix-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: ot-variant-utils.c:glnx_dirfd_canonicalize Unexecuted instantiation: otcore-prepare-root.c:glnx_dirfd_canonicalize glnx-fdio.c:glnx_dirfd_canonicalize Line  | Count  | Source  |  45  | 5.07k  | { |  46  | 5.07k  |   if (fd == -1)  |  47  | 0  |     return AT_FDCWD;  |  48  | 5.07k  |   return fd;  |  49  | 5.07k  | }  |  
 Unexecuted instantiation: ostree-async-progress.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-core.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-content-writer.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-linuxfsutil.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-diff.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-mutable-tree.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-ref.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-remote.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-checkout.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-prune.c:glnx_dirfd_canonicalize Unexecuted instantiation: ostree-repo-traverse.c:glnx_dirfd_canonicalize Unexecuted instantiation: fuzz-bsdiff.c:glnx_dirfd_canonicalize  | 
50  |  |  | 
51  |  | struct GLnxDirFdIterator { | 
52  |  |   gboolean initialized;  | 
53  |  |   int fd;  | 
54  |  |   gpointer padding_data[4];  | 
55  |  | };  | 
56  |  |  | 
57  |  | typedef struct GLnxDirFdIterator GLnxDirFdIterator;  | 
58  |  | gboolean glnx_dirfd_iterator_init_at (int dfd, const char *path,  | 
59  |  |                                     gboolean follow,  | 
60  |  |                                     GLnxDirFdIterator *dfd_iter, GError **error);  | 
61  |  | gboolean glnx_dirfd_iterator_init_take_fd (int *dfd, GLnxDirFdIterator *dfd_iter, GError **error);  | 
62  |  | gboolean glnx_dirfd_iterator_next_dent (GLnxDirFdIterator  *dfd_iter,  | 
63  |  |                                         struct dirent     **out_dent,  | 
64  |  |                                         GCancellable       *cancellable,  | 
65  |  |                                         GError            **error);  | 
66  |  | gboolean glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator  *dfd_iter,  | 
67  |  |                                                      struct dirent     **out_dent,  | 
68  |  |                                                      GCancellable       *cancellable,  | 
69  |  |                                                      GError            **error);  | 
70  |  | void glnx_dirfd_iterator_rewind (GLnxDirFdIterator  *dfd_iter);  | 
71  |  | void glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter);  | 
72  |  |  | 
73  |  | G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxDirFdIterator, glnx_dirfd_iterator_clear)  | 
74  |  |  | 
75  |  | int glnx_opendirat_with_errno (int           dfd,  | 
76  |  |                                const char   *path,  | 
77  |  |                                gboolean      follow);  | 
78  |  |  | 
79  |  | gboolean glnx_opendirat (int             dfd,  | 
80  |  |                          const char     *path,  | 
81  |  |                          gboolean        follow,  | 
82  |  |                          int            *out_fd,  | 
83  |  |                          GError        **error);  | 
84  |  |  | 
85  |  | char *glnx_fdrel_abspath (int         dfd,  | 
86  |  |                           const char *path);  | 
87  |  |  | 
88  |  | void glnx_gen_temp_name (gchar *tmpl);  | 
89  |  |  | 
90  |  | /**  | 
91  |  |  * glnx_ensure_dir:  | 
92  |  |  * @dfd: directory fd  | 
93  |  |  * @path: Directory path  | 
94  |  |  * @mode: Mode  | 
95  |  |  * @error: Return location for a #GError, or %NULL  | 
96  |  |  *  | 
97  |  |  * Wrapper around mkdirat() which adds #GError support, ensures that  | 
98  |  |  * it retries on %EINTR, and also ignores `EEXIST`.  | 
99  |  |  *  | 
100  |  |  * See also `glnx_shutil_mkdir_p_at()` for recursive handling.  | 
101  |  |  *  | 
102  |  |  * Returns: %TRUE on success, %FALSE otherwise  | 
103  |  |  */  | 
104  |  | static inline gboolean  | 
105  |  | glnx_ensure_dir (int           dfd,  | 
106  |  |                  const char   *path,  | 
107  |  |                  mode_t        mode,  | 
108  |  |                  GError      **error)  | 
109  | 0  | { | 
110  | 0  |   if (TEMP_FAILURE_RETRY (mkdirat (dfd, path, mode)) != 0)  | 
111  | 0  |     { | 
112  | 0  |       if (G_UNLIKELY (errno != EEXIST))  | 
113  | 0  |         return glnx_throw_errno_prefix (error, "mkdirat(%s)", path);  | 
114  | 0  |     }  | 
115  | 0  |   return TRUE;  | 
116  | 0  | } Unexecuted instantiation: fuzz-repo.c:glnx_ensure_dir Unexecuted instantiation: glnx-dirfd.c:glnx_ensure_dir Unexecuted instantiation: glnx-shutil.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-commit.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-composefs.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-pull.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-refs.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-verity.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-file.c:glnx_ensure_dir Unexecuted instantiation: ostree-sepolicy.c:glnx_ensure_dir Unexecuted instantiation: ostree-sysroot.c:glnx_ensure_dir Unexecuted instantiation: ostree-sysroot-cleanup.c:glnx_ensure_dir Unexecuted instantiation: ostree-sysroot-deploy.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootconfig-parser.c:glnx_ensure_dir Unexecuted instantiation: ostree-deployment.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader-aboot.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader-grub2.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader-zipl.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader-syslinux.c:glnx_ensure_dir Unexecuted instantiation: ostree-bootloader-uboot.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-static-delta-core.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-static-delta-processing.c:glnx_ensure_dir Unexecuted instantiation: ostree-kernel-args.c:glnx_ensure_dir Unexecuted instantiation: ostree-gpg-verifier.c:glnx_ensure_dir Unexecuted instantiation: ostree-gpg-verify-result.c:glnx_ensure_dir Unexecuted instantiation: ostree-sign.c:glnx_ensure_dir Unexecuted instantiation: ostree-sign-dummy.c:glnx_ensure_dir Unexecuted instantiation: ot-checksum-instream.c:glnx_ensure_dir Unexecuted instantiation: ot-checksum-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-fs-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-gio-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-gpg-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-keyfile-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-tool-util.c:glnx_ensure_dir Unexecuted instantiation: ot-unix-utils.c:glnx_ensure_dir Unexecuted instantiation: ot-variant-utils.c:glnx_ensure_dir Unexecuted instantiation: otcore-prepare-root.c:glnx_ensure_dir Unexecuted instantiation: glnx-fdio.c:glnx_ensure_dir Unexecuted instantiation: ostree-async-progress.c:glnx_ensure_dir Unexecuted instantiation: ostree-core.c:glnx_ensure_dir Unexecuted instantiation: ostree-content-writer.c:glnx_ensure_dir Unexecuted instantiation: ostree-linuxfsutil.c:glnx_ensure_dir Unexecuted instantiation: ostree-diff.c:glnx_ensure_dir Unexecuted instantiation: ostree-mutable-tree.c:glnx_ensure_dir Unexecuted instantiation: ostree-ref.c:glnx_ensure_dir Unexecuted instantiation: ostree-remote.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-checkout.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-prune.c:glnx_ensure_dir Unexecuted instantiation: ostree-repo-traverse.c:glnx_ensure_dir Unexecuted instantiation: fuzz-bsdiff.c:glnx_ensure_dir  | 
117  |  |  | 
118  |  | typedef struct { | 
119  |  |   gboolean initialized;  | 
120  |  |   int src_dfd;  | 
121  |  |   int fd;  | 
122  |  |   char *path;  | 
123  |  | } GLnxTmpDir;  | 
124  |  | gboolean glnx_tmpdir_delete (GLnxTmpDir *tmpf, GCancellable *cancellable, GError **error);  | 
125  |  | void glnx_tmpdir_unset (GLnxTmpDir *tmpf);  | 
126  |  | static inline void  | 
127  |  | glnx_tmpdir_cleanup (GLnxTmpDir *tmpf)  | 
128  | 845  | { | 
129  | 845  |   (void)glnx_tmpdir_delete (tmpf, NULL, NULL);  | 
130  | 845  | } fuzz-repo.c:glnx_tmpdir_cleanup Line  | Count  | Source  |  128  | 845  | { |  129  | 845  |   (void)glnx_tmpdir_delete (tmpf, NULL, NULL);  |  130  | 845  | }  |  
 Unexecuted instantiation: glnx-dirfd.c:glnx_tmpdir_cleanup Unexecuted instantiation: glnx-shutil.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-commit.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-composefs.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-pull.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-refs.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-verity.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-file.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sepolicy.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sysroot.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sysroot-cleanup.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sysroot-deploy.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootconfig-parser.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-deployment.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader-aboot.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader-grub2.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader-zipl.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader-syslinux.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-bootloader-uboot.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-static-delta-core.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-static-delta-processing.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-kernel-args.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-gpg-verifier.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-gpg-verify-result.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sign.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-sign-dummy.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-checksum-instream.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-checksum-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-fs-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-gio-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-gpg-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-keyfile-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-tool-util.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-unix-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: ot-variant-utils.c:glnx_tmpdir_cleanup Unexecuted instantiation: otcore-prepare-root.c:glnx_tmpdir_cleanup Unexecuted instantiation: glnx-fdio.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-async-progress.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-core.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-content-writer.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-linuxfsutil.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-diff.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-mutable-tree.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-ref.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-remote.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-checkout.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-prune.c:glnx_tmpdir_cleanup Unexecuted instantiation: ostree-repo-traverse.c:glnx_tmpdir_cleanup Unexecuted instantiation: fuzz-bsdiff.c:glnx_tmpdir_cleanup  | 
131  |  | G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxTmpDir, glnx_tmpdir_cleanup)  | 
132  |  |  | 
133  |  | gboolean glnx_mkdtempat (int dfd, const char *tmpl, int mode,  | 
134  |  |                          GLnxTmpDir *out_tmpdir, GError **error);  | 
135  |  |  | 
136  |  | gboolean glnx_mkdtemp (const char *tmpl, int      mode,  | 
137  |  |                        GLnxTmpDir *out_tmpdir, GError **error);  | 
138  |  |  | 
139  |  | G_END_DECLS  |