-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.7 2001-07-02 11:58:44 hades Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.8 2001-07-02 12:09:45 hades Exp $";
#define _POSIX_C_SOURCE 199309L
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
+#include <syslog.h>
#include <time.h>
-#include <hadesstd.h>
-
#include "worker.h"
static sigReceived = 0;
strcat(ipcName, ".shm");
if (-1 == PsxShm_unlink(ipcName) && errno != ENOENT) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
my->shm = PsxShm_open(ipcName, O_CREAT | O_RDWR, S_IRWXU, 32 * sizeof(Statistic));
if (NULL == my->shm) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
my->statistics = my->shm->addr;
my->shm = PsxShm_open(ipcName, O_RDWR, 0, 32 * sizeof(Statistic));
if (NULL == my->shm) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
my->statistics = my->shm->addr;
my->oldSigAction0 = &my->oldSigAction0S;
my->signal0 = s0;
if (0 > sigaction(my->signal0, act, my->oldSigAction0)) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
my->oldSigAction0 = NULL;
}
my->signal1 = s1;
my->oldSigAction1 = &my->oldSigAction1S;
if (0 > sigaction(my->signal1, act, my->oldSigAction1)) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
my->oldSigAction1 = NULL;
}
Worker *retVal;
Worker *my;
- my = allocMem(sizeof(Worker));
+ if (NULL == (my = malloc(sizeof(Worker)))) {
+ syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
+ return NULL;
+ }
strcpy(my->name, name);
my->pid = getpid();
my->isStandalone = isStandalone;
if (-1 == installSigHandlers(my, SIGINT, SIGTERM, sigHandler)) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
Worker_fini(my);
retVal = NULL;
} else if (-1 == createStatShm(my)) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
Worker_fini(my);
retVal = NULL;
} else {
*pidP = my->pid;
if (0 > changePriority(priority)) {
- msglog(LOG_WARNING, "changeing priority: %s\n", strerror(errno));
+ syslog(LOG_WARNING, "changeing priority: %s", strerror(errno));
}
retVal = my;
{
if (!my->isStandalone) {
if (0 > kill(getppid(), SIGUSR1)) {
- msglog(LOG_DEBUG,
- "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG,
+ "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
}
}
}
removeStatShm(my);
removeSigHandlers(my);
- freeMem(my);
+ free(my);
}
int Worker_start(const char *path, char *const argv[])
my->pid = fork();
if (0 > my->pid) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
if (my->pid == 0) { /* This is the child, we can not get out of */
/* this block */
if (0 > execvp(path, argv)) {
- msglog(LOG_DEBUG,
- "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
- msglog(LOG_EMERG, "Starting %s: %s\n", path, strerror(errno));
+ syslog(LOG_DEBUG,
+ "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_EMERG, "Starting %s: %s", path, strerror(errno));
abort();
}
} else {
if (sigReceived == SIGCHLD) {
sleep(1);
wait(NULL);
- msglog(LOG_DEBUG,
- "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG,
+ "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
retVal = 0;
strcpy(my->name, name);
if (-1 == openStatShm(my)) {
- msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = NULL;
} else {
strcpy(buf, "{}");
}
if (i == 32) {
errno = ENOSPC;
- msglog(LOG_DEBUG,
- "%s:%d: %s\n", __FILE__, __LINE__, "Too many statistics");
+ syslog(LOG_DEBUG,
+ "%s:%d: %s", __FILE__, __LINE__, "Too many statistics");
retVal = NULL;
} else {
strcpy(my->statistics[i].name, name);
curTime = time(NULL);
if (curTime >= lastTime + interval) {
- msglog(LOG_INFO, "%s\n", Worker_status(my->name));
+ syslog(LOG_INFO, "%s", Worker_status(my->name));
lastTime = curTime;
}
}