This is Unofficial EPICS BASE Doxygen Site
logMsgToErrlog.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /*
12  * route vxWorks logMsg messages into the EPICS logging system
13  *
14  * Author: Jeff Hill
15  *
16  */
17 
18 #include <string.h>
19 #include <stdlib.h>
20 
21 #include <errnoLib.h>
22 #include <iosLib.h>
23 #include <logLib.h>
24 
25 #include "errlog.h"
26 
27 // vxCommonLibrary calls logMsgToErrlog so that logMsgToErrlog gets loaded
28 extern "C" {
29  int logMsgToErrlog();
30 }
31 
32 int logMsgToErrlog() { return 0;}
33 
34 static class errlogDevTimeInit
35 {
36 public:
37  errlogDevTimeInit ();
38 } errlogDevInstance;
39 
40 static int errlogOpen ( DEV_HDR *, const char *, int )
41 {
42  return OK;
43 }
44 
45 static int errlogWrite ( DEV_HDR *, const char * pInBuf, int nbytes )
46 {
47  errlogPrintfNoConsole ( "%.*s", nbytes, pInBuf );
48  return nbytes;
49 }
50 
51 errlogDevTimeInit::errlogDevTimeInit ()
52 {
53  int errlogNo = iosDrvInstall (
54  0, // create not supported
55  0, // remove not supported
56  reinterpret_cast < FUNCPTR > ( errlogOpen ),
57  0, // close is a noop
58  0, // read not supported
59  reinterpret_cast < FUNCPTR > ( errlogWrite ),
60  0 // ioctl not supported
61  );
62  if ( errlogNo == ERROR ) {
63  errlogPrintf (
64  "Unable to install driver routing the vxWorks "
65  "logging system to the EPICS logging system because \"%s\"\n",
66  strerror ( errno ) );
67  return;
68  }
69  DEV_HDR * pDev = static_cast < DEV_HDR * > ( calloc ( 1, sizeof ( *pDev ) ) );
70  if ( ! pDev ) {
71  errlogPrintf (
72  "Unable to create driver data structure for routing the vxWorks "
73  "logging system to the EPICS logging system because \"%s\"\n",
74  strerror ( errno ) );
75  return;
76  }
77  int status = iosDevAdd ( pDev, "/errlog/", errlogNo );
78  if ( status < 0 ) {
79  errlogPrintf (
80  "Unable to install device routing the vxWorks "
81  "logging system to the EPICS logging system because \"%s\"\n",
82  strerror ( errno ) );
83  free ( pDev );
84  return;
85  }
86  int fd = open ( "/errlog/any", O_WRONLY, 0 );
87  if ( fd < 0 ) {
88  errlogPrintf (
89  "Unable to open fd routing the vxWorks "
90  "logging system to the EPICS logging system because \"%s\"\n",
91  strerror ( errno ) );
92  return;
93  }
94  status = logFdAdd ( fd );
95  if ( status != OK) {
96  errlogPrintf (
97  "Unable to install fd routing the vxWorks "
98  "logging system to the EPICS logging system because \"%s\"\n",
99  strerror ( errno ) );
100  close ( fd );
101  return;
102  }
103 }
104 
pvd::Status status
int errlogPrintfNoConsole(const char *pFormat,...)
Definition: errlog.c:186
int logMsgToErrlog()
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105