]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhades <hades>
Mon, 2 Jul 2001 12:09:45 +0000 (12:09 +0000)
committerhades <hades>
Mon, 2 Jul 2001 12:09:45 +0000 (12:09 +0000)
hadaq/worker.c

index 26831bf23dd7d48890999c46ffa358c11ecbfd92..bc5d0a0c4f920b149a378f395f584e3813e9cd28 100644 (file)
@@ -1,4 +1,4 @@
-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
@@ -18,10 +18,9 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #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;
@@ -59,12 +58,12 @@ static int createStatShm(Worker *my)
        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;
@@ -99,7 +98,7 @@ static int openStatShm(Worker *my)
 
        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;
@@ -130,14 +129,14 @@ static int installSigHandlers(Worker *my, int s0, int s1, void (*sigHandler) (in
        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;
        }
        
@@ -156,18 +155,21 @@ Worker *Worker_initBegin(const char *name, void (*sigHandler) (int), int priorit
        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 {
@@ -177,7 +179,7 @@ Worker *Worker_initBegin(const char *name, void (*sigHandler) (int), int priorit
                *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;
@@ -190,8 +192,8 @@ void Worker_initEnd(Worker *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));
                }
        }
 }
@@ -201,7 +203,7 @@ void Worker_fini(Worker *my)
        removeStatShm(my);
        removeSigHandlers(my);
 
-       freeMem(my);
+       free(my);
 }
 
 int Worker_start(const char *path, char *const argv[])
@@ -215,15 +217,15 @@ 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 {
@@ -236,8 +238,8 @@ int Worker_start(const char *path, char *const argv[])
                        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;
@@ -261,7 +263,7 @@ char *Worker_status(const char *name)
        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, "{}");
@@ -305,8 +307,8 @@ unsigned long *Worker_addStatistic(Worker *my, const char *name)
        }
        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);
@@ -326,7 +328,7 @@ void Worker_dump(Worker *my, time_t interval)
 
                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;
                }
        }