log.c 3.57 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
David Byers's avatar
David Byers committed
2
 * $Id: log.c,v 0.18 1998/12/26 22:40:41 byers Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1992, 1993, 1994, 1995  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y 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 *
David Byers's avatar
David Byers committed
38
rcsid = "$Id: log.c,v 0.18 1998/12/26 22:40:41 byers 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
60
61
62
63
64
65
66
67
68
69
70
71
72
extern void
log (const char * format, ...)
{
    va_list AP;

    va_start(AP, format);
    logv(format, AP);
    va_end(AP);
}


extern void
logv (const char *format, va_list AP)
{
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
88
89
90
#else  /* !HAVE_VFPRINTF */
extern void
log (const char * format, 
     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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156


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);
    logv(format, AP);
    va_end(AP);
#else
    log(format, a, b, c, d, e, f, g);
#endif

    log("Previous message is fatal. Will dump core now.\n");

#ifdef HAVE_GETCWD
    /* getcwd is POSIX, so try that first. */
    if (getcwd(pathname, 1026) == NULL)
	log("getcwd failed: errno %d\n", errno);
    else
	log("Search for the core in %s\n", pathname);
#else
    if ( getwd(pathname) == NULL )
	log("getwd failed: %s\n", pathname);
    else
	log("Search for the core in %s\n", pathname);
#endif
    
    abort();
}