#include "umask-util.h"
#include "user-util.h"
-int unlink_noerrno(const char *path) {
- PROTECT_ERRNO;
- return RET_NERRNO(unlink(path));
-}
-
int rmdir_parents(const char *path, const char *stop) {
char *p;
int r;
* successfully created. We ignore both the rare case where the
* original suffix is used and unlink failures. */
if (!endswith(*p, ".XXXXXX"))
- (void) unlink_noerrno(*p);
+ (void) unlink(*p);
}
int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
#define PTR_TO_MODE(p) ((mode_t) ((uintptr_t) (p)-1))
#define MODE_TO_PTR(u) ((void *) ((uintptr_t) (u)+1))
-int unlink_noerrno(const char *path);
-
int rmdir_parents(const char *path, const char *stop);
int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
if (!p)
return NULL;
- (void) unlink_noerrno(p);
+ (void) unlink(p);
return mfree(p);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);
f->operation = LOCK_EX|LOCK_NB;
if ((f->operation & ~LOCK_NB) == LOCK_EX)
- unlink_noerrno(f->path);
+ (void) unlink(f->path);
f->path = mfree(f->path);
}
r = fsync_full(fd_to);
if (r < 0) {
- (void) unlink_noerrno(t);
+ (void) unlink(t);
return log_error_errno(r, "Failed to copy data from \"%s\" to \"%s\": %m", from, t);
}
- if (renameat(AT_FDCWD, t, AT_FDCWD, to) < 0) {
- (void) unlink_noerrno(t);
- return log_error_errno(errno, "Failed to rename \"%s\" to \"%s\": %m", t, to);
+ r = RET_NERRNO(renameat(AT_FDCWD, t, AT_FDCWD, to));
+ if (r < 0) {
+ (void) unlink(t);
+ return log_error_errno(r, "Failed to rename \"%s\" to \"%s\": %m", t, to);
}
log_info("Copied \"%s\" to \"%s\".", from, to);
return log_error_errno(errno, "Failed to move public key file into place: %m");
temp_public = mfree(temp_public);
- if (rename(temp_private, "/var/lib/systemd/home/local.private") < 0) {
- (void) unlink_noerrno("/var/lib/systemd/home/local.public"); /* try to remove the file we already created */
- return log_error_errno(errno, "Failed to move private key file into place: %m");
+ r = RET_NERRNO(rename(temp_private, "/var/lib/systemd/home/local.private"));
+ if (r < 0) {
+ (void) unlink("/var/lib/systemd/home/local.public"); /* try to remove the file we already created */
+ return log_error_errno(r, "Failed to move private key file into place: %m");
}
temp_private = mfree(temp_private);
fd = safe_close(fd);
}
-TEST(unlink_noerrno) {
- char *name;
- int fd;
-
- name = strjoina(arg_test_dir ?: "/tmp", "/test-close_nointr.XXXXXX");
- fd = mkostemp_safe(name);
- assert_se(fd >= 0);
- assert_se(close_nointr(fd) >= 0);
-
- {
- PROTECT_ERRNO;
- errno = 42;
- assert_se(unlink_noerrno(name) >= 0);
- assert_se(errno == 42);
- assert_se(unlink_noerrno(name) < 0);
- assert_se(errno == 42);
- }
-}
-
TEST(readlink_and_make_absolute) {
const char *tempdir, *name, *name2, *name_alias;
_cleanup_free_ char *r1 = NULL, *r2 = NULL, *pwd = NULL;