1 /* Copyright (C) 1993,1994,1995,1997,2000,2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 #include <sys/syslog.h>
30 #include <not-cancel.h>
32 #ifdef FATAL_PREPARE_INCLUDE
33 #include FATAL_PREPARE_INCLUDE
40 struct str_list
*next
;
44 /* Abort with an error message. */
46 __libc_message (int do_abort
, const char *fmt
, ...)
53 va_copy (ap_copy
, ap
);
59 /* Open a descriptor for /dev/tty unless the user explicitly
60 requests errors on standard error. */
61 const char *on_2
= __secure_getenv ("LIBC_FATAL_STDERR_");
62 if (on_2
== NULL
|| *on_2
== '\0')
63 fd
= open_not_cancel_2 (_PATH_TTY
, O_RDWR
| O_NOCTTY
| O_NDELAY
);
68 struct str_list
*list
= NULL
;
74 /* Find the next "%s" or the end of the string. */
76 while (next
[0] != '%' || next
[1] != 's')
78 next
= __strchrnul (next
+ 1, '%');
84 /* Determine what to print. */
87 if (cp
[0] == '%' && cp
[1] == 's')
89 str
= va_arg (ap
, const char *);
100 struct str_list
*newp
= alloca (sizeof (struct str_list
));
108 bool written
= false;
111 struct iovec
*iov
= alloca (nlist
* sizeof (struct iovec
));
114 for (int cnt
= nlist
- 1; cnt
>= 0; --cnt
)
116 iov
[cnt
].iov_base
= list
->str
;
117 iov
[cnt
].iov_len
= list
->len
;
122 if (TEMP_FAILURE_RETRY (__writev (fd
, iov
, nlist
)) == total
)
128 /* If we had no success writing the message, use syslog. */
130 vsyslog (LOG_ERR
, fmt
, ap_copy
);
133 /* Kill the application. */
139 __libc_fatal (message
)
142 __libc_message (1, "%s", message
);
144 libc_hidden_def (__libc_fatal
)