File: notifier_syslog_module.c

package info (click to toggle)
openmpi 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 99,912 kB
  • ctags: 55,589
  • sloc: ansic: 525,999; f90: 18,307; makefile: 12,062; sh: 6,583; java: 6,278; asm: 3,515; cpp: 2,227; perl: 2,136; python: 1,350; lex: 734; fortran: 52; tcl: 12
file content (133 lines) | stat: -rw-r--r-- 4,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2007      Sun Microsystems, Inc.  All rights reserved.
 * Copyright (c) 2014-2015 Intel, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "orte_config.h"
#include "orte/constants.h"

#include <string.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif  /* HAVE_SYS_TIME_H */
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#include <stdarg.h>

#include "opal/util/show_help.h"

#include "orte/util/error_strings.h"
#include "orte/util/name_fns.h"

#include "orte/mca/notifier/base/base.h"
#include "notifier_syslog.h"


/* Static API's */
static int init(void);
static void finalize(void);
static void mylog(orte_notifier_request_t *req);
static void myevent(orte_notifier_request_t *req);
static void myreport(orte_notifier_request_t *req);

/* Module def */
orte_notifier_base_module_t orte_notifier_syslog_module = {
    init,
    finalize,
    mylog,
    myevent,
    myreport
};


static int init(void)
{
    int opts;

    opts = LOG_CONS | LOG_PID;
    openlog("OpenRTE Error Report:", opts, LOG_USER);

    return ORTE_SUCCESS;
}

static void finalize(void)
{
    closelog();
}

static void mylog(orte_notifier_request_t *req)
{
    char tod[48];

    opal_output_verbose(5, orte_notifier_base_framework.framework_output,
                           "notifier:syslog:mylog function called with severity %d errcode %d and messg %s",
                           (int)req->severity, req->errcode, req->msg);
    /* If there was a message, output it */
    (void)ctime_r(&req->t, tod);
    /* trim the newline */
    tod[strlen(tod)] = '\0';

    syslog(req->severity, "[%s]%s %s: JOBID %s REPORTS ERROR %s: %s", tod,
           ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
           orte_notifier_base_sev2str(req->severity),
           ORTE_JOBID_PRINT((NULL == req->jdata) ?
                            ORTE_JOBID_INVALID : req->jdata->jobid),
           orte_job_state_to_str(req->state),
           (NULL == req->msg) ? "<N/A>" : req->msg);
}

static void myevent(orte_notifier_request_t *req)
{
    char tod[48];

    opal_output_verbose(5, orte_notifier_base_framework.framework_output,
                           "notifier:syslog:myevent function called with severity %d and messg %s",
                           (int)req->severity, req->msg);
    /* If there was a message, output it */
    (void)ctime_r(&req->t, tod);
    /* trim the newline */
    tod[strlen(tod)] = '\0';

    syslog(req->severity, "[%s]%s %s SYSTEM EVENT : %s", tod,
           ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
           orte_notifier_base_sev2str(req->severity),
           (NULL == req->msg) ? "<N/A>" : req->msg);
}

static void myreport(orte_notifier_request_t *req)
{
    char tod[48];

    opal_output_verbose(5, orte_notifier_base_framework.framework_output,
                           "notifier:syslog:myreport function called with severity %d state %s and messg %s",
                           (int)req->severity, orte_job_state_to_str(req->state),
                           req->msg);
    /* If there was a message, output it */
    (void)ctime_r(&req->t, tod);
    /* trim the newline */
    tod[strlen(tod)] = '\0';

    syslog(req->severity, "[%s]%s JOBID %s REPORTS STATE %s: %s", tod,
           ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
           ORTE_JOBID_PRINT((NULL == req->jdata) ?
                            ORTE_JOBID_INVALID : req->jdata->jobid),
           orte_job_state_to_str(req->state),
           (NULL == req->msg) ? "<N/A>" : req->msg);
}