]> git.meshlink.io Git - catta/blob - avahi-compat-libdns_sd/warn.c
add more AVAHI_WARN_UNSUPPORTED lines
[catta] / avahi-compat-libdns_sd / warn.c
1 /* $Id$ */
2
3 /***
4   This file is part of avahi.
5  
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.
10  
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.
15  
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
19   USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <pthread.h>
27 #include <unistd.h>
28 #include <limits.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <assert.h>
33
34 #include "warn.h"
35
36 static pthread_mutex_t linkage_mutex = PTHREAD_MUTEX_INITIALIZER;
37 static int linkage_warning = 0;
38
39 static void get_exe_name(char *t, size_t l) {
40     int k;
41     char fn[1024];
42
43     /* Yes, I know, this is not portable. But who cares? It's
44      * for cosmetics only, anyway. */
45     
46     snprintf(fn, sizeof(fn), "/proc/%lu/exe", (unsigned long) getpid());
47
48     if ((k = readlink(fn, t, l-1)) < 0)
49         snprintf(t, l, "(unknown)");
50     else {
51         char *slash;
52
53         assert((size_t) k <= l-1);
54         t[k] = 0;
55
56         if ((slash = strrchr(t, '/')))
57             memmove(t, slash+1, strlen(slash)+1);
58     }
59 }
60
61 void avahi_warn_linkage(void) {
62     int w;
63     
64     pthread_mutex_lock(&linkage_mutex);
65     w = linkage_warning;
66     linkage_warning = 1;
67     pthread_mutex_unlock(&linkage_mutex);
68
69     if (!w && !getenv("AVAHI_BONJOUR_NOWARN")) {
70         char exename[256];
71         get_exe_name(exename, sizeof(exename));
72         
73         fprintf(stderr, "*** WARNING: The application '%s' uses the Bonjour compatiblity layer of Avahi. Please fix it to use the native API! ***\n", exename);
74     }
75 }
76
77 void avahi_warn_unsupported(const char *function) {
78     char exename[256];
79     get_exe_name(exename, sizeof(exename));
80
81     fprintf(stderr, "*** WARNING: The application '%s' called '%s()' which is not supported (or only supported partially) in the Bonjour compatiblity layer of Avahi. Please fix it to use the native API! ***\n", exename, function);
82 }
83
84
85