This is a discussion on Re: Shouldn't /sbin/nologin send the message to stderr? within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Otto Moerbeek wrote: > This angel has problem with KNF: Ow yes: int\nmain(... > space between function name and ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Otto Moerbeek wrote: > This angel has problem with KNF: Ow yes: int\nmain(... > space between function name and arg list. Also, return (expr); > is preferred to return expr; It strikes me as inconsistent. I'd expect either ``return 0;'' or ``return(0)'' but not ``return (0)''. Any pointer to the reason behind this? I can't find it in style(9). > Apart from that, formatting changes combined with functional > changes are frowned upon. Errr OK, I'll keep it in mind. > But the main point: you did not make clear why stderr would be > better. Because it's an errormessage. Errormessages should be sent to stderr. I tried login in to a disabled account to see if the errormessage was not echoed but that was also not the case. That why I was informing if there were any other objections to sending the message to stderr. It was not a rhetorical question, nor was my patch a suggestion nor a recommendation. It was merely meant to clarify what I had in mind. But now after taking your remarks in account, this is what the code should look like in the end. After applying one patch for the functional change and one for the format. (without the license for briefness): [snip: licensenote] #include <sys/types.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> /* Distinctly different from _PATH_NOLOGIN. */ #define _PATH_NOLOGIN_TXT "/etc/nologin.txt" #define DEFAULT_MESG "This account is currently not available.\n" /*ARGSUSED*/ int main(int argc, char *argv[]) { int nfd; ssize_t nrd; char nbuf[BUFSIZ]; nfd = open(_PATH_NOLOGIN_TXT, O_RDONLY); if (nfd == -1) { write(STDERR_FILENO, DEFAULT_MESG, strlen(DEFAULT_MESG)); return (1); } while ((nrd = read(nfd, nbuf, sizeof(nbuf))) != -1 && nrd != 0) write(STDERR_FILENO, nbuf, nrd); close(nfd); return (1); } What say you? # Han |