switch (cf->type) {
case TYPE_CONTROLLER:
setproctitle ("controller process");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting controller process %P", getpid ());
start_controller (cur);
break;
case TYPE_LMTP:
setproctitle ("lmtp process");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting lmtp process %P", getpid ());
start_lmtp_worker (cur);
break;
case TYPE_SMTP:
setproctitle ("smtp process");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting smtp process %P", getpid ());
start_smtp_worker (cur);
break;
case TYPE_FUZZY:
setproctitle ("fuzzy storage");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting fuzzy storage process %P", getpid ());
start_fuzzy_storage (cur);
break;
case TYPE_GREYLIST:
setproctitle ("greylist storage");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting greylist storage process %P", getpid ());
start_greylist_storage (cur);
break;
case TYPE_WORKER:
default:
setproctitle ("worker process");
- pidfile_close (rspamd->pfh);
+ rspamd_pidfile_close (rspamd->pfh);
msg_info ("starting worker process %P", getpid ());
start_worker (cur);
break;
break;
case -1:
msg_err ("cannot fork main process. %s", strerror (errno));
- pidfile_remove (rspamd->pfh);
+ rspamd_pidfile_remove (rspamd->pfh);
exit (-errno);
break;
default:
if (main->cfg->pid_file == NULL) {
return -1;
}
- main->pfh = pidfile_open (main->cfg->pid_file, 0644, &pid);
+ main->pfh = rspamd_pidfile_open (main->cfg->pid_file, 0644, &pid);
if (main->pfh == NULL) {
return -1;
}
- pidfile_write (main->pfh);
+ rspamd_pidfile_write (main->pfh);
return 0;
}
#ifndef HAVE_PIDFILE
extern gchar *__progname;
-static gint _pidfile_remove (struct pidfh *pfh, gint freeit);
+static gint _rspamd_pidfile_remove (rspamd_pidfh_t *pfh, gint freeit);
static gint
-pidfile_verify (struct pidfh *pfh)
+rspamd_pidfile_verify (rspamd_pidfh_t *pfh)
{
struct stat sb;
}
static gint
-pidfile_read (const gchar *path, pid_t * pidptr)
+rspamd_pidfile_read (const gchar *path, pid_t * pidptr)
{
gchar buf[16], *endptr;
gint error, fd, i;
return 0;
}
-struct pidfh *
-pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
+rspamd_pidfh_t *
+rspamd_pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
{
- struct pidfh *pfh;
+ rspamd_pidfh_t *pfh;
struct stat sb;
gint error, fd, len, count;
struct timespec rqtp;
rqtp.tv_nsec = 5000000;
if (errno == EWOULDBLOCK && pidptr != NULL) {
again:
- errno = pidfile_read (pfh->pf_path, pidptr);
+ errno = rspamd_pidfile_read (pfh->pf_path, pidptr);
if (errno == 0)
errno = EEXIST;
else if (errno == EAGAIN) {
}
gint
-pidfile_write (struct pidfh *pfh)
+rspamd_pidfile_write (rspamd_pidfh_t *pfh)
{
gchar pidstr[16];
gint error, fd;
* Check remembered descriptor, so we don't overwrite some other
* file if pidfile was closed and descriptor reused.
*/
- errno = pidfile_verify (pfh);
+ errno = rspamd_pidfile_verify (pfh);
if (errno != 0) {
/*
* Don't close descriptor, because we are not sure if it's ours.
*/
if (ftruncate (fd, 0) == -1) {
error = errno;
- _pidfile_remove (pfh, 0);
+ _rspamd_pidfile_remove (pfh, 0);
errno = error;
return -1;
}
rspamd_snprintf (pidstr, sizeof (pidstr), "%P", getpid ());
if (pwrite (fd, pidstr, strlen (pidstr), 0) != (ssize_t) strlen (pidstr)) {
error = errno;
- _pidfile_remove (pfh, 0);
+ _rspamd_pidfile_remove (pfh, 0);
errno = error;
return -1;
}
}
gint
-pidfile_close (struct pidfh *pfh)
+rspamd_pidfile_close (rspamd_pidfh_t *pfh)
{
gint error;
- error = pidfile_verify (pfh);
+ error = rspamd_pidfile_verify (pfh);
if (error != 0) {
errno = error;
return -1;
}
static gint
-_pidfile_remove (struct pidfh *pfh, gint freeit)
+_rspamd_pidfile_remove (rspamd_pidfh_t *pfh, gint freeit)
{
gint error;
- error = pidfile_verify (pfh);
+ error = rspamd_pidfile_verify (pfh);
if (error != 0) {
errno = error;
return -1;
if (unlink (pfh->pf_path) == -1)
error = errno;
- if (! unlock_file (pfh->pf_fd, FALSE)) {
+ if (!unlock_file (pfh->pf_fd, FALSE)) {
if (error == 0)
error = errno;
}
}
gint
-pidfile_remove (struct pidfh *pfh)
+rspamd_pidfile_remove (rspamd_pidfh_t *pfh)
{
- return (_pidfile_remove (pfh, 1));
+ return (_rspamd_pidfile_remove (pfh, 1));
}
#endif
/*
* Pidfile functions from FreeBSD libutil code
*/
-struct pidfh {
+typedef struct rspamd_pidfh_s {
gint pf_fd;
#ifdef HAVE_PATH_MAX
gchar pf_path[PATH_MAX + 1];
#endif
dev_t pf_dev;
ino_t pf_ino;
-};
-struct pidfh *pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr);
-gint pidfile_write(struct pidfh *pfh);
-gint pidfile_close(struct pidfh *pfh);
-gint pidfile_remove(struct pidfh *pfh);
+} rspamd_pidfh_t;
+rspamd_pidfh_t *rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr);
+gint rspamd_pidfile_write(rspamd_pidfh_t *pfh);
+gint rspamd_pidfile_close(rspamd_pidfh_t *pfh);
+gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
+#else
+typedef struct pidfh rspamd_pidfh_t;
+#define rspamd_pidfile_open pidfile_open
+#define rspamd_pidfile_write pidfile_write
+#define rspamd_pidfile_close pidfile_close
+#define rspamd_pidfile_remove pidfile_remove
#endif
/*