On Sun, Nov 24, 2019 at 05:13:15PM -0300, Guillermo wrote: > Those are just two if statements 'sharing' a body for brevity. That > deals with errors in the openat() and subsequent write() calls, for > the file that controls cgroup membership. By displaying a message > constructed in the same way in both cases, and then throwing an > exception. *Shrug* That particular piece of code > if (0 > cgroup_procs_fd.get()) { > procs_file_error: ... > } > if (0 > write(cgroup_procs_fd.get(), "0\n", 2)) goto procs_file_error; seems equivalent to > if (0 > cgroup_procs_fd.get() || > 0 > write(cgroup_procs_fd.get(), "0\n", 2)) { > ... > } If the error handling branches that need reuse become more complex, the following way can also be considered (cf. [1]): > ... > if (...) goto err; > ... > if (...) goto err; > ... > return; > err: > ... > return; Macros and/or helper functions (again cf. [1]; they can be factored into a mini-library in nosh) can also be used to reduce boilerplate like > const int error(errno); > std::fprintf(stderr, ..., std::strerror(error)); > throw EXIT_FAILURE; which can be easily observed after the attached patch is applied. BTW, it seems that the value of errno is passed to std::strerror() before anything can change the errno, which implies that `const int error(errno);' can be left out and `errno' can be directly used as the argument of std::strerror(). [1] . -- My current OpenPGP key: RSA4096/0x227E8CAAB7AA186C (expires: 2020.10.19) 7077 7781 B859 5166 AE07 0286 227E 8CAA B7AA 186C