]> cygwin.com Git - cygwin-apps/setup.git/blob - log.cc
2002-01-27 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / log.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@redhat.com>
13 *
14 */
15
16 /* The purpose of this file is to centralize all the logging functions. */
17
18 #if 0
19 static const char *cvsid =
20 "\n%%% $Id$\n";
21 #endif
22
23 #include "win32.h"
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <time.h>
28
29 #include "resource.h"
30 #include "msg.h"
31 #include "log.h"
32 #include "dialog.h"
33 #include "state.h"
34 #include "concat.h"
35 #include "mkdir.h"
36 #include "mount.h"
37
38 struct LogEnt
39 {
40 LogEnt *next;
41 int flags;
42 time_t when;
43 char msg[1];
44 };
45
46 static LogEnt *first_logent = 0;
47 static LogEnt **next_logent = &first_logent;
48
49 void
50 log (int flags, const char *fmt, ...)
51 {
52 char buf[1000];
53 va_list args;
54 va_start (args, fmt);
55 vsprintf (buf, fmt, args);
56
57 LogEnt *l = (LogEnt *) malloc (sizeof (LogEnt) + strlen (buf) + 20);
58 l->next = 0;
59 l->flags = flags;
60 time (&(l->when));
61 *next_logent = l;
62 next_logent = &(l->next);
63
64 char *b = l->msg;
65 if (flags & LOG_TIMESTAMP)
66 {
67 struct tm *tm = localtime (&(l->when));
68 strftime (b, 1000, "%Y/%m/%d %H:%M:%S ", tm);
69 b += strlen (b);
70 }
71
72 strcpy (b, buf);
73 msg ("LOG: %d %s", l->flags, l->msg);
74 }
75
76 void
77 log_save (int babble, const char *filename, int append)
78 {
79 static int been_here = 0;
80 if (been_here)
81 return;
82 been_here = 1;
83
84 mkdir_p (0, filename);
85
86 FILE *f = fopen (filename, append ? "at" : "wt");
87 if (!f)
88 {
89 fatal (NULL, IDS_NOLOGFILE, filename);
90 return;
91 }
92
93 LogEnt *l;
94
95 for (l = first_logent; l; l = l->next)
96 {
97 if (babble || !(l->flags & LOG_BABBLE))
98 {
99 fputs (l->msg, f);
100 if (l->msg[strlen (l->msg) - 1] != '\n')
101 fputc ('\n', f);
102 }
103 }
104
105 fclose (f);
106 been_here = 0;
107 }
108
109 void
110 exit_setup (int exit_code)
111 {
112 static int been_here = 0;
113 if (been_here)
114 ExitProcess (1);
115 been_here = 1;
116
117 if (exit_msg)
118 note (NULL, exit_msg);
119
120 log (LOG_TIMESTAMP, "Ending cygwin install");
121
122 if (source == IDC_SOURCE_DOWNLOAD || !get_root_dir ())
123 {
124 log_save (LOG_BABBLE, concat (local_dir, "/setup.log.full", 0), 0);
125 log_save (0, concat (local_dir, "/setup.log", 0), 1);
126 }
127 else
128 {
129 log_save (LOG_BABBLE, cygpath ("/setup.log.full", 0), 0);
130 log_save (0, cygpath ("/setup.log", 0), 1);
131 }
132
133 ExitProcess (exit_code);
134 }
This page took 0.039115 seconds and 5 git commands to generate.