I am trying to run the example programs that accompany the book "Beginning Linux Programming". I don't undestand what is wrong with this one (it produces Aug 10 02:42:38 rakefet logmask[13691]: debug message, should not appear , although it is not execpected to):
bash-2.00$ cat logmask.c #include <syslog.h> #include <stdio.h> #include <unistd.h> int main() { int logmask; openlog("logmask", LOG_PID|LOG_CONS, LOG_USER); syslog(LOG_INFO,"informative message, pid = %d", getpid()); syslog(LOG_DEBUG,"debug message, should appear"); logmask = setlogmask(LOG_MASK(LOG_DEBUG)); syslog(LOG_DEBUG,"debug message, should not appear"); return(0); } bash-2.00$ cc -o logmask logmask.c bash-2.00$ ./logmask rakefet# tail -n2 /var/log/debug Aug 10 02:42:38 rakefet logmask[13691]: debug message, should appear Aug 10 02:42:38 rakefet logmask[13691]: debug message, should not appear How it (should ?) works: The program initializes the logging dacility with its name , "logmask" and requests that log messages contain the process identifier. The informative message is logged to "/var/log/messages" and the debug message to "/var/log/debug". The second debug message doesn't appear because we call "setlogmask" to ignore all messages with a priority below "LOG_NOTICE".