ppc64-diag
Macros | Functions | Variables
files.c File Reference

File Manipulation routines for files used by rtas_errd. More...

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include "rtas_errd.h"

Macros

#define RTAS_ERRD_LOGSZ   25000
 Maximum size of the rtas_errd_log. More...
 

Functions

int init_files (void)
 Initialize files used by rtas_errd. More...
 
void close_files (void)
 Close all the files used by rtas_errd. More...
 
int read_proc_error_log (char *buf, int buflen)
 Read data from proc_error_log. More...
 
int reformat_msg (char *msg)
 Re-format a log message to wrap at 80 characters. More...
 
static void _log_msg (struct event *event, const char *fmt, va_list ap)
 The real routine to write messages to rtas_errd_log. More...
 
void cfg_log (char *fmt,...)
 dummy interface for calls to diag_cfg More...
 
void log_msg (struct event *event, char *fmt,...)
 Log messages to rtas_errd_log. More...
 
void _dbg (const char *fmt,...)
 Write debug messages to stdout. More...
 
int print_rtas_event (struct event *event)
 Print an RTAS event to the platform log. More...
 
int platform_log_write (char *fmt,...)
 Write messages to the platform log. More...
 
void update_epow_status_file (int status)
 Update the epow status file. More...
 

Variables

char * platform_log = "/var/log/platform"
 
int platform_log_fd = -1
 
char * proc_error_log1 = "/proc/ppc64/rtas/error_log"
 File to read RTAS events from. More...
 
char * proc_error_log2 = "/proc/ppc64/error_log"
 Alternate file to read RTAS events from. More...
 
static int proc_error_log_fd = -1
 File descriptor for proc_error_log. More...
 
char * rtas_errd_log = "/var/log/rtas_errd.log"
 Message log for the rtas_errd daemon. More...
 
char * rtas_errd_log0 = "/var/log/rtas_errd.log0"
 Saved ("rolled over") messages log for rtas_errd daemon. More...
 
static int rtas_errd_log_fd = -1
 File descriptor for rtas_errd_log. More...
 
static int epow_status_fd = -1
 
char * epow_status_file = "/var/log/epow_status"
 
char * scanlog = NULL
 buffer to hold scanlog dump path More...
 

Detailed Description

Copyright (C) 2004 IBM Corporation

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Macro Definition Documentation

◆ RTAS_ERRD_LOGSZ

#define RTAS_ERRD_LOGSZ   25000

Referenced by _log_msg().

Function Documentation

◆ _dbg()

void _dbg ( const char *  fmt,
  ... 
)

dbg Provide utility to print debug statements if the debug flag is specified.

Parameters
fmtformat string a la printf()
...args a la printf()

References debug, reformat_msg(), and RTAS_ERROR_LOG_MAX.

Referenced by _log_msg().

◆ _log_msg()

static void _log_msg ( struct event event,
const char *  fmt,
va_list  ap 
)
static

_log_msg This is a common routine for formatting messages that go to the /var/log/rtas_errd.log file. Users should pass in a reference to the rtas_event structure if this message is directly related a rtas event and a formatted message a la printf() style. Please make sure that the message passed in does not have any ending punctuation or ends with a newline. It should also not have any internal newlines.

This routine will do several things to the message before printing it out;

  • Add a timestamp
  • If a rtas_event reference is passed in, a sequenbce number is added
  • If errno is set, the results of perror are added.
  • The entire message is then formatted to fit in 80 cols.
Parameters
eventreference to event
fmtformatted string a la printf()
...additional args a la printf()

References _dbg(), dbg, log_msg(), reformat_msg(), rtas_errd_log, rtas_errd_log0, rtas_errd_log_fd, RTAS_ERRD_LOGSZ, RTAS_ERROR_LOG_MAX, and event::seq_num.

Referenced by cfg_log(), and log_msg().

◆ cfg_log()

void cfg_log ( char *  fmt,
  ... 
)

cfg_log

Parameters
fmtformatted string a la printf()
...additional args a la printf()

References _log_msg().

Referenced by main(), read_rtas_events(), and sighup_handler().

◆ close_files()

void close_files ( void  )

close_files Perform any file cleanup (i.e. close()) and possibly free()'ing buffers needed by rtas_errd before exiting.

References epow_status_fd, platform_log_fd, proc_error_log_fd, and rtas_errd_log_fd.

Referenced by main().

◆ init_files()

int init_files ( void  )

init_files Open the following files needed by the rtas_errd daemon: rtas_errd_log proc_error_log platform_log epow_status

Note: This should only be called once before any rtas_events are read.

Returns
0 on success, !0 on failure

References debug, log_msg(), platform_log, platform_log_fd, proc_error_log1, proc_error_log2, proc_error_log_fd, rtas_errd_log, rtas_errd_log_fd, and update_epow_status_file().

Referenced by main().

◆ log_msg()

void log_msg ( struct event event,
char *  fmt,
  ... 
)

◆ platform_log_write()

int platform_log_write ( char *  fmt,
  ... 
)

platform_log_write Provide a printf() style interface to write messages to platform_log. All messages are prepended with "ppc64-diag" to match the expected format of the platform log.

Parameters
fmtformat string a la printf()
...additional args a la printf()
Returns
return code from write() call

References platform_log_fd.

Referenced by check_eeh(), check_platform_dump(), guard_cpu(), guard_memlmb(), guard_spcpu(), and handle_rtas_event().

◆ print_rtas_event()

int print_rtas_event ( struct event event)

print_rtas_event Prints the binary hexdump of an RTAS event to the PLATFORM_LOG file.

Parameters
eventpointer to the struct event to print
Returns
0 on success, !0 on failure

References dbg, event::event_buf, event::flags, log_msg(), platform_log, platform_log_fd, RE_SCANLOG_AVAIL, scanlog, and event::seq_num.

Referenced by handle_rtas_event().

◆ read_proc_error_log()

int read_proc_error_log ( char *  buf,
int  buflen 
)

read_proc_error_log Read the data in from the /proc error log file. This routine also handles the debug case of reading in a test file that contains an ascii representation of a RTAS event.

Parameters
bufbuffer to read RTAS event in to.
buflenlength of buffer parameter
Returns
number of bytes read.

References log_msg(), proc_error_log1, proc_error_log2, and proc_error_log_fd.

Referenced by read_rtas_events().

◆ reformat_msg()

int reformat_msg ( char *  msg)

reformat_msg In order to ease the formatting of messages in the rtas_errd daemon this will automatically format the messages to wrap at 80 characters.

Parameters
msgbuffer containing the message to re-format
Returns
new buffer length

References RTAS_ERROR_LOG_MAX.

Referenced by _dbg(), and _log_msg().

◆ update_epow_status_file()

void update_epow_status_file ( int  status)

update_epow_status_file Used to write the current EPOW status (as defined in the parse_epow() function (epow.c) comment) to the epow_status file.

Parameters
statusvalue to update epow_status file to.

References epow_status_fd, epow_status_file, and log_msg().

Referenced by check_epow(), epow_timer_handler(), and init_files().

Variable Documentation

◆ epow_status_fd

int epow_status_fd = -1
static

◆ epow_status_file

char* epow_status_file = "/var/log/epow_status"

◆ platform_log

char* platform_log = "/var/log/platform"

◆ platform_log_fd

int platform_log_fd = -1

◆ proc_error_log1

proc_error_log1 = "/proc/ppc64/rtas/error_log"

◆ proc_error_log2

proc_error_log2 = "/proc/ppc64/error_log"

◆ proc_error_log_fd

proc_error_log_fd = -1
static

◆ rtas_errd_log

rtas_errd_log = "/var/log/rtas_errd.log"

◆ rtas_errd_log0

rtas_errd_log0 = "/var/log/rtas_errd.log0"

Referenced by _log_msg().

◆ rtas_errd_log_fd

rtas_errd_log_fd = -1
static

Referenced by _log_msg(), close_files(), and init_files().

◆ scanlog

scanlog = NULL

This is a buffer that is allocated and filled when rtas_errd is initially exec()'ed via check_scanlog_dump(). The buffer will contain the path to a scanlog dump and is reported with the first RTAS event we receive from the kernel.

Referenced by check_scanlog_dump(), print_rtas_event(), and read_rtas_events().