4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
39 #define COMPAT_LAYER "Apple Bonjour"
42 static pthread_mutex_t linkage_mutex = PTHREAD_MUTEX_INITIALIZER;
43 static int linkage_warning = 0;
45 const char *avahi_exe_name(void) {
46 static char exe_name[1024] = "";
47 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
49 /* Yes, I know, this is not portable. But who cares? It's for
50 * cosmetics only, anyway. */
52 pthread_mutex_lock(&mutex);
54 if (exe_name[0] == 0) {
58 snprintf(fn, sizeof(fn), "/proc/%lu/exe", (unsigned long) getpid());
60 if ((k = readlink(fn, exe_name, sizeof(exe_name)-1)) < 0)
61 snprintf(exe_name, sizeof(exe_name), "(unknown)");
65 assert((size_t) k <= sizeof(exe_name)-1);
68 if ((slash = strrchr(exe_name, '/')))
69 memmove(exe_name, slash+1, strlen(slash)+1);
73 pthread_mutex_unlock(&mutex);
78 void avahi_warn(const char *fmt, ...) {
79 char msg[512] = "*** WARNING *** ";
87 vsnprintf(msg + n, sizeof(msg) - n, fmt, ap);
90 fprintf(stderr, "%s\n", msg);
92 openlog(avahi_exe_name(), LOG_PID, LOG_USER);
93 syslog(LOG_WARNING, "%s", msg);
97 void avahi_warn_linkage(void) {
100 pthread_mutex_lock(&linkage_mutex);
103 pthread_mutex_unlock(&linkage_mutex);
105 if (!w && !getenv("AVAHI_COMPAT_NOWARN"))
106 avahi_warn("The programme '%s' uses the "COMPAT_LAYER" compatiblity layer of Avahi. "
107 "Please fix your application to use the native API of Avahi!",
111 void avahi_warn_unsupported(const char *function) {
112 avahi_warn("The programme '%s' called '%s()' which is not supported (or only supported partially) in the "COMPAT_LAYER" compatiblity layer of Avahi. "
113 "Please fix your application to use the native API of Avahi!",
114 avahi_exe_name(), function);