~ubuntu-branches/ubuntu/wily/sblim-sfcb/wily

« back to all changes in this revision

Viewing changes to mlog.c

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-07-16 15:47:22 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716154722-7b5n4g1r1gybd321
Tags: 1.3.4-0ubuntu1
* New upstream release (LP: #394235)
* debian/control: Add a version to the debhelper build dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: mlog.c,v 1.6 2008/10/16 15:53:36 mchasal Exp $
 
2
 * $Id: mlog.c,v 1.9 2009/06/15 20:16:33 buccella Exp $
3
3
 *
4
4
 * (C) Copyright IBM Corp. 2003, 2004
5
5
 *
18
18
 *
19
19
 */
20
20
 
21
 
const char *_mlog_id = "$Id: mlog.c,v 1.6 2008/10/16 15:53:36 mchasal Exp $";
 
21
const char *_mlog_id = "$Id: mlog.c,v 1.9 2009/06/15 20:16:33 buccella Exp $";
 
22
 
22
23
 
23
24
#include "mlog.h"
 
25
#include "msgqueue.h"
24
26
#include <syslog.h>
25
27
#include <stdarg.h>
26
28
#include <stdio.h>
27
 
 
28
 
void startLogging(const char *name)
 
29
#include <errno.h>
 
30
 
 
31
//semaphore
 
32
static key_t logSemKey;
 
33
static int logSem = -1;
 
34
 
 
35
 
 
36
void startLogging(const char *name, int level)
29
37
{
 
38
   union semun sun;
 
39
 
 
40
   logSemKey=ftok(SFCB_BINARY,'L');
 
41
 
 
42
    // if sem exists, clear it out.
 
43
   if ((logSem=semget(logSemKey,1, 0600))!=-1)
 
44
      semctl(logSem,0,IPC_RMID,sun);
 
45
 
 
46
   if ((logSem=semget(logSemKey,1,IPC_CREAT | IPC_EXCL | 0600))==-1) {
 
47
      char *emsg=strerror(errno);
 
48
      fprintf(stderr,"\n--- Logging semaphore create key: 0x%x failed: %s\n",logSemKey,emsg);
 
49
      abort();
 
50
   }
 
51
 
 
52
   sun.val=1;
 
53
   semctl(logSem,0,SETVAL,sun);
 
54
 
30
55
  openlog(name,LOG_PID,LOG_DAEMON);
31
 
  setlogmask(LOG_UPTO(LOG_INFO));
 
56
  setlogmask(LOG_UPTO(level));
 
57
 
32
58
}
33
59
 
34
60
/** \brief mlogf - Create syslog entries
45
71
 */
46
72
void mlogf(int priority, int errout, const char *fmt, ...)
47
73
{
48
 
  va_list ap,apc;
 
74
  va_list ap;
49
75
  int priosysl;
50
76
 
51
77
  char buf[4096];
62
88
    priosysl=LOG_ERR;
63
89
    break;
64
90
  }
 
91
 
 
92
  if (semAcquire(logSem,0)) {
 
93
      char *emsg=strerror(errno);
 
94
      fprintf(stderr,"\n--- Unable to acquire logging lock: %s\n",emsg);
 
95
      // not aborting since that will kill sfcb, so try to continue
 
96
  }
 
97
  
65
98
  va_start(ap,fmt);
66
 
  
67
99
  vsnprintf(buf,4096,fmt,ap);
68
100
  syslog(priosysl,"%s",buf);
69
101
 
70
102
  if (errout) {
71
 
    va_start(apc,fmt);
72
 
    vfprintf(stderr,fmt,apc);
73
 
    va_end(apc);
 
103
    fprintf(stderr,"%s",buf);
74
104
  }
75
105
  va_end(ap);
 
106
  if (semRelease(logSem,0)) {
 
107
      char *emsg=strerror(errno);
 
108
      fprintf(stderr,"\n--- Unable to release logging lock: %s\n",emsg);
 
109
      // not aborting since that will kill sfcb, so try to continue
 
110
  }
76
111
}
77
112