mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
useradd: Don't crash on -m
if directory already exists
This commit is contained in:
parent
111e4162d0
commit
7eec2d6c21
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/ddorando 🔰 Commit: https://github.com/SerenityOS/serenity/commit/7eec2d6c21 Pull-request: https://github.com/SerenityOS/serenity/pull/23052 Reviewed-by: https://github.com/BenWiederhake ✅
1 changed files with 6 additions and 2 deletions
|
@ -143,11 +143,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
home = home_path;
|
||||
|
||||
if (create_home_dir) {
|
||||
bool existed = false;
|
||||
auto mkdir_error = Core::System::mkdir(home, 0700);
|
||||
if (mkdir_error.is_error()) {
|
||||
int code = mkdir_error.release_error().code();
|
||||
warnln("Failed to create directory {}: {}", home, strerror(code));
|
||||
return 12;
|
||||
|
||||
if (code != EEXIST)
|
||||
return 12;
|
||||
existed = true;
|
||||
}
|
||||
|
||||
auto chown_error = Core::System::chown(home, static_cast<uid_t>(uid), static_cast<gid_t>(gid));
|
||||
|
@ -155,7 +159,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
int code = chown_error.release_error().code();
|
||||
warnln("Failed to change owner of {} to {}:{}: {}", home, uid, gid, strerror(code));
|
||||
|
||||
if (rmdir(home.characters()) < 0) {
|
||||
if (!existed && rmdir(home.characters()) < 0) {
|
||||
warnln("Failed to remove directory {}: {}", home, strerror(errno));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue