Merge pull request #4795 from poettering/dissect
Generalize image dissection logic of nspawn, and make it useful for other tools.
This commit is contained in:
@@ -1409,3 +1409,22 @@ int read_nul_string(FILE *f, char **ret) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mkdtemp_malloc(const char *template, char **ret) {
|
||||
char *p;
|
||||
|
||||
assert(template);
|
||||
assert(ret);
|
||||
|
||||
p = strdup(template);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!mkdtemp(p)) {
|
||||
free(p);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
*ret = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -88,3 +88,5 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path);
|
||||
int link_tmpfile(int fd, const char *path, const char *target);
|
||||
|
||||
int read_nul_string(FILE *f, char **ret);
|
||||
|
||||
int mkdtemp_malloc(const char *template, char **ret);
|
||||
|
||||
@@ -84,3 +84,10 @@ enum {
|
||||
};
|
||||
|
||||
int chase_symlinks(const char *path_with_prefix, const char *root, unsigned flags, char **ret);
|
||||
|
||||
/* Useful for usage with _cleanup_(), removes a directory and frees the pointer */
|
||||
static inline void rmdir_and_free(char *p) {
|
||||
(void) rmdir(p);
|
||||
free(p);
|
||||
}
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rmdir_and_free);
|
||||
|
||||
@@ -33,8 +33,6 @@ int rm_rf(const char *path, RemoveFlags flags);
|
||||
|
||||
/* Useful for usage with _cleanup_(), destroys a directory and frees the pointer */
|
||||
static inline void rm_rf_physical_and_free(char *p) {
|
||||
if (!p)
|
||||
return;
|
||||
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
free(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user