1 /* error.c -- Functions for handling errors. */
2 /* Copyright (C) 1993 Free Software Foundation, Inc.
4 This file is part of GNU Bash, the Bourne Again SHell.
6 Bash is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License along
17 with Bash; see the file COPYING. If not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <sys/types.h>
24 #if defined (HAVE_VFPRINTF)
39 extern int interactive_shell;
40 extern char *dollar_vars[];
41 extern char *shell_name;
42 extern char *the_current_maintainer;
43 #if defined (JOB_CONTROL)
44 extern pid_t shell_pgrp;
45 #endif /* JOB_CONTROL */
47 /* Return the name of the shell or the shell script for error reporting. */
51 char *name = (char *) NULL;
53 if (!interactive_shell)
54 name = dollar_vars[0];
55 if (!name && shell_name && *shell_name)
56 name = base_pathname (shell_name);
63 /* Report an error having to do with FILENAME. */
68 report_error ("%s: %s", filename, strerror (errno));
71 #if !defined (HAVE_VFPRINTF)
73 programming_error (reason, arg1, arg2, arg3, arg4, arg5)
76 #if defined (JOB_CONTROL)
77 give_terminal_to (shell_pgrp);
78 #endif /* JOB_CONTROL */
80 report_error (reason, arg1, arg2);
81 fprintf (stderr, "Report this to %s\n", the_current_maintainer);
82 fprintf (stderr, "Stopping myself...");
88 report_error (format, arg1, arg2, arg3, arg4, arg5)
91 fprintf (stderr, "%s: ", get_name_for_error ());
93 fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
94 fprintf (stderr, "\n");
95 if (exit_immediately_on_error)
100 fatal_error (format, arg1, arg2, arg3, arg4, arg5)
103 fprintf (stderr, "%s: ", get_name_for_error ());
105 fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
106 fprintf (stderr, "\n");
112 internal_error (format, arg1, arg2, arg3, arg4, arg5)
115 fprintf (stderr, "%s: ", get_name_for_error ());
117 fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
118 fprintf (stderr, "\n");
121 #else /* We have VARARGS support, so use it. */
124 programming_error (va_alist)
130 #if defined (JOB_CONTROL)
131 give_terminal_to (shell_pgrp);
132 #endif /* JOB_CONTROL */
135 format = va_arg (args, char *);
136 vfprintf (stderr, format, args);
137 fprintf (stderr, "\n");
140 fprintf (stderr, "Tell %s to fix this someday.\n", the_current_maintainer);
141 fprintf (stderr, "Stopping myself...");
147 report_error (va_alist)
153 fprintf (stderr, "%s: ", get_name_for_error ());
155 format = va_arg (args, char *);
156 vfprintf (stderr, format, args);
157 fprintf (stderr, "\n");
160 if (exit_immediately_on_error)
165 fatal_error (va_alist)
171 fprintf (stderr, "%s: ", get_name_for_error ());
173 format = va_arg (args, char *);
174 vfprintf (stderr, format, args);
175 fprintf (stderr, "\n");
182 internal_error (va_alist)
188 fprintf (stderr, "%s: ", get_name_for_error ());
190 format = va_arg (args, char *);
191 vfprintf (stderr, format, args);
192 fprintf (stderr, "\n");
203 fprintf(stderr, "TRACE: pid %d: ", getpid());
205 format = va_arg (args, char *);
206 vfprintf (stderr, format, args);
207 fprintf (stderr, "\n");
215 /* A trace function for silent debugging -- doesn't require a control
222 static FILE *tracefp = (FILE *)NULL;
225 tracefp = fopen("/usr/tmp/bash-trace.log", "a+");
230 fcntl (fileno (tracefp), F_SETFD, 1); /* close-on-exec */
232 fprintf(tracefp, "TRACE: pid %d: ", getpid());
235 format = va_arg (args, char *);
236 vfprintf (tracefp, format, args);
237 fprintf (tracefp, "\n");
244 #endif /* HAVE_VFPRINTF */