Tizen 2.1 base
[toolchains/fakeroot.git] / communicate.h
1 #ifndef FAKEROOT_COMMUNICATE_H
2 #define FAKEROOT_COMMUNICATE_H
3
4 #include "config.h"
5 #include "fakerootconfig.h"
6
7 #define LCHOWN_SUPPORT
8
9 /* I've got a chicken-and-egg problem here. I want to have
10    stat64 support, only running on glibc2.1 or later. To
11    find out what glibc we've got installed, I need to 
12    #include <features.h>.
13    But, before including that file, I have to define _LARGEFILE64_SOURCE
14    etc, cause otherwise features.h will not define it's internal defines.
15    As I assume that pre-2.1 libc's will just ignore those _LARGEFILE64_SOURCE
16    defines, I hope I can get away with this approach:
17 */
18   
19 /*First, unconditionally define these, so that glibc 2.1 features.h defines
20   the needed 64 bits defines*/
21 #ifndef _LARGEFILE64_SOURCE
22 # define _LARGEFILE64_SOURCE 
23 #endif
24 #ifndef _LARGEFILE_SOURCE
25 # define _LARGEFILE_SOURCE 
26 #endif
27
28 /* Then include features.h, to find out what glibc we run */
29 #ifdef HAVE_FEATURES_H
30 # include <features.h>
31 #endif
32
33 #ifdef HAVE_SYS_FEATURE_TESTS_H
34 # include <sys/feature_tests.h>
35 #endif
36
37 /* Then decide whether we do or do not use the stat64 support */
38 #if (defined(sun) && !defined(__SunOS_5_5_1) && !defined(_LP64)) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
39 # define STAT64_SUPPORT
40 #else
41 # warning Not using stat64 support
42 /* if glibc is 2.0 or older, undefine these again */
43 # undef STAT64_SUPPORT
44 # undef _LARGEFILE64_SOURCE
45 # undef _LARGEFILE_SOURCE
46 #endif
47
48 /* Sparc glibc 2.0.100 is broken, dlsym segfaults on --fxstat64.. 
49 #define STAT64_SUPPORT */
50
51 #include <sys/types.h>
52 #include <sys/stat.h>
53 #include <sys/utsname.h>
54 #ifdef HAVE_STDINT_H
55 # include <stdint.h>
56 #endif
57 #ifdef HAVE_INTTYPES_H
58 # include <inttypes.h>
59 #endif
60
61 #ifndef FAKEROOT_FAKENET
62 # define FAKEROOTKEY_ENV          "FAKEROOTKEY"
63 #endif /* ! FAKEROOT_FAKENET */
64
65 #define FAKEROOTUID_ENV           "FAKEROOTUID"
66 #define FAKEROOTGID_ENV           "FAKEROOTGID"
67 #define FAKEROOTEUID_ENV          "FAKEROOTEUID"
68 #define FAKEROOTEGID_ENV          "FAKEROOTEGID"
69 #define FAKEROOTSUID_ENV          "FAKEROOTSUID"
70 #define FAKEROOTSGID_ENV          "FAKEROOTSGID"
71 #define FAKEROOTFUID_ENV          "FAKEROOTFUID"
72 #define FAKEROOTFGID_ENV          "FAKEROOTFGID"
73 #define FAKEROOTDONTTRYCHOWN_ENV  "FAKEROOTDONTTRYCHOWN"
74
75 #define FAKELIBDIR                "/usr/lib/fakeroot"
76 #define FAKELIBNAME               "libfakeroot.so.0"
77 #ifdef FAKEROOT_FAKENET
78 # define FD_BASE_ENV              "FAKEROOT_FD_BASE"
79 #endif /* FAKEROOT_FAKENET */
80 #ifdef FAKEROOT_DB_PATH
81 # define DB_SEARCH_PATHS_ENV      "FAKEROOT_DB_SEARCH_PATHS"
82 #endif /* FAKEROOT_DB_PATH */
83
84 #ifdef __GNUC__
85 # define UNUSED __attribute__((unused))
86 #else
87 # define UNUSED
88 #endif
89
90 #ifndef S_ISTXT
91 # define S_ISTXT S_ISVTX
92 #endif
93
94 #ifndef ALLPERMS
95 # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
96 #endif
97
98 /* Define big enough _constant size_ types for the various types of the
99    stat struct. I cannot (or rather, shouldn't) use struct stat itself
100    in the communication between the fake-daemon and the client (libfake),
101    as the sizes elements of struct stat may depend on the compiler or
102    compile time options of the C compiler, or the C library used. Thus,
103    the fake-daemon may have to communicate with two clients that have
104    different views of struct stat (this is the case for libc5 and
105    libc6 (glibc2) compiled programmes on Linux). This currently isn't
106    enabled any more, but used to be in libtricks.
107 */
108
109 enum {chown_func,
110         /*2*/  chmod_func,
111         /*3*/  mknod_func, 
112                stat_func,
113         /*5*/  unlink_func,
114                debugdata_func,
115                reqoptions_func,
116                last_func};
117
118 #include "message.h"
119
120 extern const char *env_var_set(const char *env);
121 #ifndef STUPID_ALPHA_HACK
122 extern void send_stat(const struct stat *st, func_id_t f);
123 #else
124 extern void send_stat(const struct stat *st, func_id_t f,int ver);
125 #endif
126 extern void send_fakem(const struct fake_msg *buf);
127 #ifndef STUPID_ALPHA_HACK
128 extern void send_get_stat(struct stat *buf);
129 #else
130 extern void send_get_stat(struct stat *buf,int ver);
131 #endif
132 extern void cpyfakefake (struct fakestat *b1, const struct fakestat *b2);
133 #ifndef STUPID_ALPHA_HACK
134 extern void cpystatfakem(struct     stat *st, const struct fake_msg *buf);
135 #else
136 extern void cpystatfakem(struct     stat *st, const struct fake_msg *buf, int ver);
137 #endif
138
139 #ifndef FAKEROOT_FAKENET
140 extern int init_get_msg();
141 extern key_t get_ipc_key(key_t new_key);
142 # ifndef STUPID_ALPHA_HACK
143 extern void cpyfakemstat(struct fake_msg *b1, const struct stat *st);
144 # else
145 extern void cpyfakemstat(struct fake_msg *b1, const struct stat *st, int ver);
146 # endif
147 #else /* FAKEROOT_FAKENET */
148 # ifdef FAKEROOT_LIBFAKEROOT
149 extern volatile int comm_sd;
150 extern void lock_comm_sd(void);
151 extern void unlock_comm_sd(void);
152 # endif
153 #endif /* FAKEROOT_FAKENET */
154
155 #ifdef STAT64_SUPPORT  
156 #ifndef STUPID_ALPHA_HACK
157 extern void send_stat64(const struct stat64 *st, func_id_t f);
158 extern void send_get_stat64(struct stat64 *buf);
159 #else
160 extern void send_stat64(const struct stat64 *st, func_id_t f, int ver);
161 extern void send_get_stat64(struct stat64 *buf, int ver);
162 #endif
163 extern void stat64from32(struct stat64 *s64, const struct stat *s32);
164 extern void stat32from64(struct stat *s32, const struct stat64 *s64);
165 #endif
166
167 #ifndef FAKEROOT_FAKENET
168 extern int msg_snd;
169 extern int msg_get;
170 extern int sem_id;
171 #endif /* ! FAKEROOT_FAKENET */
172
173 #endif