#include #include #include #include #include const char *file_name="nohum.out"; /* * This is the black hole all errors will go to */ const char *trash_bin="/dev/null"; int main(int argc, char *argv[]) { int new_stdout; if(argc < 2) { fprintf(stderr, "Usage: %s command [arguments]\n", *argv); exit(1); } if(isatty(1)) { fprintf(stderr, "Sending output to %s\n", file_name); close(1); if ((new_stdout = open(file_name, O_WRONLY | O_CREAT |O_APPEND, 0644)) == -1) { perror(file_name); exit(2); } } /* * Dump the stuff into the black hole :-) * Same way it was done by the author for stdout */ if(isatty(2)) { fprintf(stderr, "Sending error output to %s\n", trash_bin); close(2); if ((new_stdout = open(trash_bin, O_WRONLY | O_CREAT |O_APPEND, 0644)) == -1) { perror(trash_bin); exit(4); } } if (signal(SIGHUP, SIG_IGN) == SIG_ERR) { perror("SIGHUP"); exit(3); } ++argv; execvp(*argv, argv); perror(*argv); exit(4); } /* Well first if we ignore all the output to stderr then if signal faults then no error message will be generated and we won't be able to see anything on the screen .. if, as the author suggested, logout without performing ps then we have done nothing... another possibility for same scenario is that execvp could fail too then we won't see any errors either. Third possibility with the same scenario is that the program executed by execve could fail too .. and nothing will be displayed as an error either... But directing the stderr messages to "the black hole" could save us all these permission denied notifications from find when it encounters restrictions on x with directory files which is good I suppose. As a matter of fact I personally think that if the original version is tested then there's nothing bad to add these few lines to get rid of the nasty messages :-) */