|
Home > Archive > Unix Shell > October 2006 > problem in making syslog entry
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem in making syslog entry
|
|
| ranjayap@gmail.com 2006-10-23, 1:16 pm |
| Hi Everybody,
I've the following c program that makes a syslog entry into
/var/log/messages the default syslog file [pl ref /etc/syslog.conf for
this entry]. After running this program for couple of minutes i'm not
able to see any entries in /var/log/messages
The c program has been built using the default cc compiler that comes
with linux
However the same program works on other platforms
#include <unistd.h>
#include <sys/syslog.h>
#include <stdio.h>
int main(){
char mesg_buf[1000];
int countx=0;
while (1) {
sprintf(mesg_buf,"MESSAGE FROM SYSLOG [%s][%d]",__FILE__);
syslog(LOG_INFO,mesg_buf);
countx++;
sleep (5)
}
return 0;
}
Other details related to my linux box
===========================
cat /etc/issue
Red Hat Enterprise Linux ES release 4 (Nahant)
Kernel \r on an \m
uname -v -r -a
2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 i686 i386 GNU/Linux
That's all . Looking forward to help from the community experts . Any
help would be highly appreciated
Thanks
Ranjaya
| |
| Eric Moors 2006-10-23, 1:16 pm |
| ranjayap@gmail.com wrote:
> Hi Everybody,
>
> I've the following c program that makes a syslog entry into
> /var/log/messages the default syslog file [pl ref /etc/syslog.conf for
> this entry]. After running this program for couple of minutes i'm not
> able to see any entries in /var/log/messages
>
> The c program has been built using the default cc compiler that comes
> with linux
which would be... (gcc?)
> However the same program works on other platforms
>
> #include <unistd.h>
> #include <sys/syslog.h>
> #include <stdio.h>
> int main(){
> char mesg_buf[1000];
> int countx=0;
> while (1) {
> sprintf(mesg_buf,"MESSAGE FROM SYSLOG [%s][%d]",__FILE__);
missing something over here (I guess __LINE__)
> syslog(LOG_INFO,mesg_buf);
> countx++;
> sleep (5)
missing a semicolon according to gcc
> }
> return 0;
> }
>
> Other details related to my linux box
> ===========================
> cat /etc/issue
> Red Hat Enterprise Linux ES release 4 (Nahant)
> Kernel \r on an \m
> uname -v -r -a
> 2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 i686 i386 GNU/Linux
>
> That's all . Looking forward to help from the community experts . Any
> help would be highly appreciated
No problems here (FC4)
- Linux HOSTNAME 2.6.17-1.2142_FC4 #1 Tue Jul 11 22:41:14 EDT 2006 i686 i686
i386 GNU/Linux
- gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)
Are you perhaps being blocked by an SElinux configuration issue?
Eric
| |
| Kaz Kylheku 2006-10-24, 1:22 am |
| ranjayap@gmail.com wrote:
> this entry]. After running this program for couple of minutes i'm not
> able to see any entries in /var/log/messages
> However the same program works on other platforms
>
> #include <unistd.h>
> #include <sys/syslog.h>
This should be <syslog.h> not <sys/syslog.h>. Do you read man pages at
all?
> #include <stdio.h>
> int main(){
> char mesg_buf[1000];
> int countx=0;
> while (1) {
> sprintf(mesg_buf,"MESSAGE FROM SYSLOG [%s][%d]",__FILE__);
Too few arguments for conversion specifiers. GCC can warn about this;
why don't you use -Wall?
> syslog(LOG_INFO,mesg_buf);
The syslog function already works much like printf:
syslog(LOG_INFO, "%s %d", __FILE__, __LINE__);
> countx++;
> sleep (5)
Missing semicolon after statement. This requires a diagnostic, and
probably won't compile.
What is the real program that you actually compiled and ran?
Maybe you ignored the compiler error and ran some random a.out that was
already lying in the directory.
> }
> return 0;
> }
You didn't call openlog, which lets you specify a facility. So, by
default, you are logging to the LOG_USER facility.
How is your syslog daemon configured to handle LOG_USER facility
messages that have a LOG_INFO level?
> cat /etc/issue
Yeah, that's really important! Unlike, say, the irrelevant blurbs in
/etc/syslog.conf.
|
|
|
|
|