log.c 3.52 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: log.c,v 0.17 1998/07/12 01:23:47 ceder 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.
 */

31
static const char *
32
rcsid = "$Id: log.c,v 0.17 1998/07/12 01:23:47 ceder Exp $";
33
34
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
35

Per Cederqvist's avatar
Per Cederqvist committed
36
37
38
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
39
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
40
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
41
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
42
#include <unistd.h>
43
#include <errno.h>
Per Cederqvist's avatar
Per Cederqvist committed
44

Per Cederqvist's avatar
Per Cederqvist committed
45
#include "log.h"
46
#include "lyskomd.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
48
49
50
51

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

Per Cederqvist's avatar
Per Cederqvist committed
52
#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
Per Cederqvist's avatar
Per Cederqvist committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)
{
67
    time_t clk;
68
    struct tm *t;
Per Cederqvist's avatar
Per Cederqvist committed
69

70
71
    time(&clk);
    t = localtime(&clk);
Per Cederqvist's avatar
Per Cederqvist committed
72

73
    fprintf(stderr, "%02d%02d%02d %02d:%02d:%02d %ld ",
74
	    t->tm_year, t->tm_mon + 1, t->tm_mday,
75
	    t->tm_hour, t->tm_min, t->tm_sec, (long)getpid());
Per Cederqvist's avatar
Per Cederqvist committed
76
77
78
79
    vfprintf(stderr, format, AP);

    fflush(stderr);
}
80
81
82
83
84
#else  /* !HAVE_VFPRINTF */
extern void
log (const char * format, 
     int a, int b, int c, int d, int e, int f, int g)
{
85
    time_t clk;
86
87
    struct tm *t;

88
89
    time(&clk);
    t = localtime(&clk);
90

91
    fprintf(stderr, "%02d%02d%02d %02d:%02d:%02d %ld ",
92
	    t->tm_year, t->tm_mon + 1, t->tm_mday,
93
	    t->tm_hour, t->tm_min, t->tm_sec, (long)getpid());
94
95
96
97
98
99
    fprintf(stderr, format, a, b, c, d, e, f, g);

    fflush(stderr);
    
}
#endif /* !HAVE_VFPRINTF */
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150


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();
}