C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2003, 01:03 AM
Geekoidxp Geekoidxp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 41 Geekoidxp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old June 9th, 2003, 10:12 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,867 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 2 h 46 m 38 sec
Reputation Power: 480
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);
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > syslog help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT