--- move-to-control-group.cpp 2018-09-14 21:48:55.000000000 +0800 +++ move-to-control-group.new.cpp 2019-11-25 10:50:20.518459398 +0800 @@ -50,9 +50,8 @@ next_prog = arg0_of(args); FileStar self_cgroup(open_my_control_group_info("/proc/self/cgroup")); - if (!self_cgroup) { + if (!self_cgroup && ENOENT != errno) { // `ENOENT == error' is what we'll see on a BSD. const int error(errno); - if (ENOENT == error) return; // This is what we'll see on a BSD. std::fprintf(stderr, "%s: FATAL: %s: %s\n", prog, "/proc/self/cgroup", std::strerror(error)); throw EXIT_FAILURE; } @@ -73,20 +72,16 @@ current = prefix + current; - if (0 > mkdirat(AT_FDCWD, current.c_str(), 0755)) { + if (0 > mkdirat(AT_FDCWD, current.c_str(), 0755) && EEXIST != error) { const int error(errno); - if (EEXIST != error) { - std::fprintf(stderr, "%s: FATAL: %s: %s\n", prog, current.c_str(), std::strerror(error)); - throw EXIT_FAILURE; - } + std::fprintf(stderr, "%s: FATAL: %s: %s\n", prog, current.c_str(), std::strerror(error)); + throw EXIT_FAILURE; } const FileDescriptorOwner cgroup_procs_fd(open_appendexisting_at(AT_FDCWD, (current + "/cgroup.procs").c_str())); - if (0 > cgroup_procs_fd.get()) { -procs_file_error: + if (0 > cgroup_procs_fd.get() || 0 > write(cgroup_procs_fd.get(), "0\n", 2)) { const int error(errno); std::fprintf(stderr, "%s: FATAL: %s%s: %s\n", prog, current.c_str(), "/cgroup.procs", std::strerror(error)); throw EXIT_FAILURE; } - if (0 > write(cgroup_procs_fd.get(), "0\n", 2)) goto procs_file_error; }