Hot answers tagged

16

It's a good idea for worker.c to include "worker.h", preferably as the very first line. That ensures that the declarations are consistent and that the header has no missing includes of its own. (So, in task.c move the task.h include to the top spot, and similarly with utils.h in utils.c.) I recommend adding include-guards on all your header files. I know ...


13

Make sure Doxygen picks up comments after struct members It's good to add a comment after each member in a struct declaration to describe what that member does. To make Doxygen pick up the member documentation as well, use //!< or ///< instead of // to start the comments with. Use "filename" or "path", not "file" describe filenames You will be ...


7

In addition to the excellent answer by that other guy: It's a good idea to start the script with a shebang specifying which interpreter to run. In this case, we're not using any Bash features not present in standard POSIX shell, so we can write #!/bin/sh Consider setting the flags -u (using unset variables is an error) and -e (exit when commands fail and ...


7

Overall it's fine. My suggestions would be: Fix the indenting. If you find the comments helpful, great. Otherwise, consider saying "why" and not "what", e.g. # set the var SUDO to "" (blank) -> # This will be used as a prefix to run a command as root You can alternatively consider checking if the command exists by running it: if htop --version > /dev/...


7

I only want to add some nitpicks, but otherwise a really clean code base! Don't create types with_t suffix These types are reserved by POSIX and C is currently even moving to claiming some of these, too. Use function prototypes Currently you don't use function prototypes for functions with no arguments, eg. void f(); This declaration defines the ...


3

You should consider to check the return value of malloc, on main.c you have char *process_name = (char *) malloc(name_len + 1 + sizeof(REQUEUE_PROCESS)); memcpy(process_name, worker->name, name_len); Consider that malloc could fail and you will have a problem. char *process_name = (char *) malloc(name_len + 1 + sizeof(REQUEUE_PROCESS)); if (...


3

Self-review comments Comments are very important to future readers, they speed up the comprehension of the whole code. I think I messed up at least one comment, (others pending review): original: # let's take a closer look at the first argument, the editor suggested: # store the first argument, the editor name combine what can be combined By ...


3

The thing with bash is more often then not... there is a tool that you can leverage to do what you want. When writing bash scripts, I try write as little bash as possible, and to leverage these tools where best possible to avoid bash (seems counter intuitive, but is the nature of bash to write as little bash as possible). For example have you heard of the ...


3

Just a couple of additional points... I've not used c++17, but when performing tests against constants, consider putting the constants on the left, rather than the right. This prevents typos from having unexpected consequences. if (res = -1) changes the value of res, whereas if(-1 = res) doesn't compile. You're keeping variables in your class that seem ...


3

__MYLIB_COM_HPP is a reserved identifier, you're not allowed to use these in your code. Instead of including both <string> and <string.h>, you could also use std::strcpy(). Also, you don't need that in the header, move it to the implementation file. sizeof (char) is by definition one, because sizeof gives you the size in multiples of that of a ...


2

This long line: printf '%b\n' "sudoedit_enhanced_run(): Low number of arguments.\\nExpected: \$1 = editor name; \$2 = wait option; \$3, (\$4), ... = file(s).\\nPassed $#: $*" >&2 can easily be made more tractable by separating the lines (since we have \n in the format string) and by using single quotes where we don't want expansion (avoiding the ...


1

Philosophy You seemed to worry about the usefulness of this a bit when you said "it might still be useful..." It doesn't have to be useful! Was it fun? Did you learn something? I love personal data collection projects like this. It is amazing what it can lead to. I also find it interesting to see the idea of "write as little bash as possible" in a ...


Only top voted, non community-wiki answers of a minimum length are eligible