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"
43 #define CGI_SUBSYSTEM "libdns_sd"
46 static pthread_mutex_t linkage_mutex = PTHREAD_MUTEX_INITIALIZER;
47 static int linkage_warning = 0;
49 const char *avahi_exe_name(void) {
50 #ifdef HAVE_GETPROGNAME
52 #elif defined(__linux__)
53 static char exe_name[1024] = "";
54 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
56 /* Yes, I know, this is not portable. But who cares? It's for
57 * cosmetics only, anyway. */
59 pthread_mutex_lock(&mutex);
61 if (exe_name[0] == 0) {
64 if ((k = readlink("/proc/self/exe", exe_name, sizeof(exe_name)-1)) < 0)
65 snprintf(exe_name, sizeof(exe_name), "(unknown)");
69 assert((size_t) k <= sizeof(exe_name)-1);
72 if ((slash = strrchr(exe_name, '/')))
73 memmove(exe_name, slash+1, strlen(slash)+1);
77 pthread_mutex_unlock(&mutex);
82 #warning "avahi_exe_name() needs to be implemented for your operating system"
88 void avahi_warn(const char *fmt, ...) {
89 char msg[512] = "*** WARNING *** ";
97 vsnprintf(msg + n, sizeof(msg) - n, fmt, ap);
100 fprintf(stderr, "%s\n", msg);
102 openlog(avahi_exe_name(), LOG_PID, LOG_USER);
103 syslog(LOG_WARNING, "%s", msg);
107 void avahi_warn_linkage(void) {
110 pthread_mutex_lock(&linkage_mutex);
113 pthread_mutex_unlock(&linkage_mutex);
115 if (!w && !getenv("AVAHI_COMPAT_NOWARN")) {
116 avahi_warn("The program '%s' uses the "COMPAT_LAYER" compatibility layer of Avahi.", avahi_exe_name());
117 avahi_warn("Please fix your application to use the native API of Avahi!");
118 avahi_warn("For more information see <http://0pointer.de/avahi-compat?s="CGI_SUBSYSTEM"&e=%s>", avahi_exe_name());
122 void avahi_warn_unsupported(const char *function) {
123 avahi_warn("The program '%s' called '%s()' which is not supported (or only supported partially) in the "COMPAT_LAYER" compatibility layer of Avahi.", avahi_exe_name(), function);
124 avahi_warn("Please fix your application to use the native API of Avahi!");
125 avahi_warn("For more information see <http://0pointer.de/avahi-compat?s="CGI_SUBSYSTEM"&e=%s&f=%s>", avahi_exe_name(), function);