log.c 3.65 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
3
 * $Id: log.c,v 0.20 1999/05/24 09:34:28 ceder Exp $
 * Copyright (C) 1991-1995, 1998-1999  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM 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 1, or (at your option) 
 * any later version.
 * 
 * LysKOM 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 LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
26
27
28
29
30
/*
 * log.c
 *
 * File created by ceder 1990-05-25.
 */

David Byers's avatar
David Byers committed
31
32
33
34
35
36


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

37
static const char *
38
rcsid = "$Id: log.c,v 0.20 1999/05/24 09:34:28 ceder Exp $";
39
40
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
41

Per Cederqvist's avatar
Per Cederqvist committed
42
43
44
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
45
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
46
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
47
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
48
#include <unistd.h>
49
#include <errno.h>
Per Cederqvist's avatar
Per Cederqvist committed
50

Per Cederqvist's avatar
Per Cederqvist committed
51
#include "log.h"
52
#include "lyskomd.h"
Per Cederqvist's avatar
Per Cederqvist committed
53
54
55
56
57

/*
 * Add a string to the log file.
 */

Per Cederqvist's avatar
Per Cederqvist committed
58
#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
Per Cederqvist's avatar
Per Cederqvist committed
59
extern void
David Byers's avatar
David Byers committed
60
kom_log (const char * format, ...)
Per Cederqvist's avatar
Per Cederqvist committed
61
62
63
64
{
    va_list AP;

    va_start(AP, format);
David Byers's avatar
David Byers committed
65
    kom_logv(format, AP);
Per Cederqvist's avatar
Per Cederqvist committed
66
67
68
69
70
    va_end(AP);
}


extern void
David Byers's avatar
David Byers committed
71
kom_logv (const char *format, va_list AP)
Per Cederqvist's avatar
Per Cederqvist committed
72
{
73
    time_t clk;
74
    struct tm *t;
Per Cederqvist's avatar
Per Cederqvist committed
75

76
77
    time(&clk);
    t = localtime(&clk);
Per Cederqvist's avatar
Per Cederqvist committed
78

79
    fprintf(stderr, "%02d%02d%02d %02d:%02d:%02d %ld ",
80
	    t->tm_year, t->tm_mon + 1, t->tm_mday,
81
	    t->tm_hour, t->tm_min, t->tm_sec, (long)getpid());
Per Cederqvist's avatar
Per Cederqvist committed
82
83
84
85
    vfprintf(stderr, format, AP);

    fflush(stderr);
}
86
87
#else  /* !HAVE_VFPRINTF */
extern void
David Byers's avatar
David Byers committed
88
kom_log (const char * format, 
89
90
     int a, int b, int c, int d, int e, int f, int g)
{
91
    time_t clk;
92
93
    struct tm *t;

94
95
    time(&clk);
    t = localtime(&clk);
96

97
    fprintf(stderr, "%02d%02d%02d %02d:%02d:%02d %ld ",
98
	    t->tm_year, t->tm_mon + 1, t->tm_mday,
99
	    t->tm_hour, t->tm_min, t->tm_sec, (long)getpid());
100
101
102
103
104
105
    fprintf(stderr, format, a, b, c, d, e, f, g);

    fflush(stderr);
    
}
#endif /* !HAVE_VFPRINTF */
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


void
#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
restart_kom(const char * format, ...)
#else
restart_kom(format,
	    a, b, c, d, e, f, g)
     const char *format;
     int a, b, c, d, e, f, g;
#endif
{
#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
    va_list AP;
#endif
#if defined(HAVE_GETCWD)
    char pathname[1026];
#else /* !defined(HAVE_GETCWD) */
    char *getwd(char *); /* +++ should be in sys/param.h */
# if defined(MAXPATHLEN)
    char pathname[MAXPATHLEN];
# else
    char pathname[1024];
# endif /* !defined(MAXPATHLEN) */
#endif /* !defined(HAVE_GETCWD) */

#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
    va_start(AP, format);
David Byers's avatar
David Byers committed
134
    kom_logv(format, AP);
135
136
    va_end(AP);
#else
David Byers's avatar
David Byers committed
137
    kom_log(format, a, b, c, d, e, f, g);
138
139
#endif

David Byers's avatar
David Byers committed
140
    kom_log("Previous message is fatal. Will dump core now.\n");
141
142
143
144

#ifdef HAVE_GETCWD
    /* getcwd is POSIX, so try that first. */
    if (getcwd(pathname, 1026) == NULL)
David Byers's avatar
David Byers committed
145
	kom_log("getcwd failed: errno %d\n", errno);
146
    else
David Byers's avatar
David Byers committed
147
	kom_log("Search for the core in %s\n", pathname);
148
149
#else
    if ( getwd(pathname) == NULL )
David Byers's avatar
David Byers committed
150
	kom_log("getwd failed: %s\n", pathname);
151
    else
David Byers's avatar
David Byers committed
152
	kom_log("Search for the core in %s\n", pathname);
153
154
#endif
    
David Byers's avatar
David Byers committed
155
156
157
#ifdef AVOID_ABORTS
    exit(255);
#else
158
    abort();
David Byers's avatar
David Byers committed
159
#endif
160
}