]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/utils.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXCFS_UTILS_H
4 #define __LXCFS_UTILS_H
10 #include <sys/socket.h>
11 #include <sys/types.h>
13 #include <sys/syscall.h>
16 #include "lxcfs_fuse.h"
19 #include "syscall_numbers.h"
21 /* Reserve buffer size to account for file size changes. */
22 #define BUF_RESERVE_SIZE 512
24 #define SEND_CREDS_OK 0
25 #define SEND_CREDS_NOTSK 1
26 #define SEND_CREDS_FAIL 2
30 __attribute__((__format__(__printf__
, 4, 5))) extern char *must_strcat(char **src
, size_t *sz
, size_t *asz
, const char *format
, ...);
31 extern bool is_shared_pidns(pid_t pid
);
32 extern int preserve_ns(const int pid
, const char *ns
);
33 extern void do_release_file_info(struct fuse_file_info
*fi
);
34 extern bool recv_creds(int sock
, struct ucred
*cred
, char *v
);
35 extern int send_creds(int sock
, struct ucred
*cred
, char v
, bool pingfirst
);
36 extern bool wait_for_sock(int sock
, int timeout
);
37 extern int read_file_fuse(const char *path
, char *buf
, size_t size
,
39 extern int read_file_fuse_with_offset(const char *path
, char *buf
, size_t size
,
40 off_t offset
, struct file_info
*d
);
41 extern void prune_init_slice(char *cg
);
42 extern int wait_for_pid(pid_t pid
);
45 static inline int pidfd_open(pid_t pid
, unsigned int flags
)
47 return syscall(__NR_pidfd_open
, pid
, flags
);
51 #if !HAVE_PIDFD_SEND_SIGNAL
52 static inline int pidfd_send_signal(int pidfd
, int sig
, siginfo_t
*info
,
55 return syscall(__NR_pidfd_send_signal
, pidfd
, sig
, info
, flags
);
59 extern FILE *fopen_cached(const char *path
, const char *mode
,
60 void **caller_freed_buffer
);
61 extern FILE *fdopen_cached(int fd
, const char *mode
, void **caller_freed_buffer
);
62 extern DIR *opendir_flags(const char *path
, int oflags
);
63 extern ssize_t
write_nointr(int fd
, const void *buf
, size_t count
);
64 extern int safe_uint64(const char *numstr
, uint64_t *converted
, int base
);
65 extern int safe_uint32(const char *numstr
, uint32_t *converted
, int base
);
66 extern char *trim_whitespace_in_place(char *buffer
);
68 static inline bool file_exists(const char *f
)
72 return stat(f
, &statbuf
) == 0;
75 #define PROTECT_OPEN_WITH_TRAILING_SYMLINKS (O_CLOEXEC | O_NOCTTY | O_RDONLY)
76 #define PROTECT_OPEN (PROTECT_OPEN_WITH_TRAILING_SYMLINKS | O_NOFOLLOW)
77 extern char *read_file_at(int dfd
, const char *fnam
, unsigned int o_flags
);
79 #endif /* __LXCFS_UTILS_H */