Группа :: Система/Серверы
Пакет: smtptrapd
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: smtptrapd-1.4-alt-pidfile.patch
Скачать
Скачать
Adding support for pid file
--- smtptrapd.c.orig 2008-01-05 21:39:36 +0300
+++ smtptrapd.c 2008-01-05 21:39:57 +0300
@@ -76,6 +76,7 @@
char *chroot_dir;
char *banner;
char *username;
+ char *pidfile;
struct in_addr local_ip;
short bind_local;
int port;
@@ -121,6 +122,7 @@
int drop_priv(void) {
struct passwd *p;
+ FILE *pidfile;
p = getpwnam((config.username == NULL) ?
UNPRIV_USER : config.username);
@@ -131,6 +133,23 @@
return -1;
}
+ if (config.pidfile) {
+ /* write to pid file */
+ if ((pidfile=fopen(config.pidfile, "w")) == NULL) {
+ syslog(LOG_CRIT, "error: could not open pid file %s: %s",
+ config.pidfile, strerror(errno));
+ return -1;
+ }
+ fprintf(pidfile, "%d\n", (unsigned int)getpid());
+
+ /* we're done, clean up */
+ if (fclose(pidfile) != 0) {
+ syslog(LOG_CRIT, "error: could not close pid file %s: %s",
+ config.pidfile, strerror(errno));
+ return -1;
+ }
+ }
+
if (config.chroot_dir != NULL) {
if (chdir(config.chroot_dir) != 0)
@@ -181,7 +200,7 @@
char buf[BUFSIZ];
struct sockaddr_in addr;
- int addrlen = sizeof(addr);
+ unsigned int addrlen = sizeof(addr);
pthread_mutex_unlock(&queue.mutex);
@@ -270,7 +289,7 @@
int state = SMTP_STATE_NONE;
char buf[BUFSIZ], from[LOG_SIZ], rcpt[LOG_SIZ];
struct sockaddr_in addr;
- int addrlen = sizeof(addr);
+ unsigned int addrlen = sizeof(addr);
int i = 0, etime = 0, itime = time(NULL);
/* some nice initialisation of strings */
@@ -452,11 +471,12 @@
config.chroot_dir = NULL;
config.username = NULL;
config.banner = NULL;
+ config.pidfile = NULL;
config.port = LISTEN_PORT;
config.threads = NUM_CONSUMER;
config.max_queue_len = MAX_QUEUE_LEN;
- while ((c = getopt(argc, argv, "hc:l:p:b:u:m:t:")) != -1) {
+ while ((c = getopt(argc, argv, "hc:l:p:b:u:m:t:f:")) != -1) {
switch (c) {
case 'h':
@@ -467,7 +487,8 @@
"-u [username] "
"-t [number of threads] "
"-p [listen port] "
- "-m [max accept queue length]");
+ "-m [max accept queue length] "
+ "-f [pid file path]" );
exit(EX_USAGE);
@@ -486,6 +507,10 @@
config.chroot_dir = strdup(optarg);
break;
+ case 'f':
+ config.pidfile = strdup(optarg);
+ break;
+
case 'b':
config.banner = strdup(optarg);
break;