The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
syslog help
Discuss syslog help in the C Programming forum on Dev Shed. syslog help C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 9th, 2003, 01:03 AM
|
|
Contributing User
|
|
Join Date: Apr 2003
Posts: 41
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
syslog help
Hi there,
I am just curious if anyone can tell me where I can find information about syslog. I need to know how I can manipulate the syslog, for instance, when people connect thru' my proxy, I want to be able to log their details, etc....
Geekoid
|

June 9th, 2003, 10:12 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Just to get you started, here are my (admittedly very terse) notes from "Linux Programming by Example":
Quote:
need to log errors, etc, to a system log:
<syslog.h>
void openlog(char *ident, int option, int facility);
void closelog(void);
void syslog(int priority, char *format, ...);
OR options for openlog:
LOG_CONS
LOG_NDELAY
LOG_PERROR
LOG_PID
facility is one of:
LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_KERN, LOG_LOCAL[0-7], LOG_LPR,
LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP
priority is one of:
LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG |
The example given was (downloaded from their site):
Code:
int main(void)
{
pid_t pid, sid;
time_t timebuf;
int fd, len;
/* Open the system log */
openlog("lpedated", LOG_PID, LOG_DAEMON);
pid = fork();
if(pid < 0) {
syslog(LOG_ERR, "%s\n", perror);
exit(EXIT_FAILURE);
}
if(pid > 0)
/* In the parent, let's bail */
exit(EXIT_SUCCESS);
/* In the child... */
/* First, start a new session */
if((sid = setsid()) < 0) {
syslog(LOG_ERR, "%s\n", "setsid");
exit(EXIT_FAILURE);
}
/* Next, make / the current directory */
if((chdir("/")) < 0) {
syslog(LOG_ERR, "%s\n", "chdir");
exit(EXIT_FAILURE);
}
/* Reset the file mode */
umask(0);
/* Close stdin, etc. */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Finally, do our work */
len = strlen(ctime(&timebuf));
while(1) {
char *buf = malloc(sizeof(char) * (len + 1));
if(buf == NULL) {
syslog(LOG_ERR, "malloc");
exit(EXIT_FAILURE);
}
if((fd = open("/var/log/lpedated.log",
O_CREAT | O_WRONLY | O_APPEND, 0600)) < 0) {
syslog(LOG_ERR, "open");
exit(EXIT_FAILURE);
}
time(&timebuf);
strncpy(buf, ctime(&timebuf), len + 1);
write(fd, buf, len + 1);
close(fd);
sleep(60);
}
closelog();
exit(EXIT_SUCCESS);
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|