YDLIDAR X2 SDK  V1.4.1
lock.h
1 /*
2  * lock.h
3  *
4  * Created on: 28 Mar 2018
5  * Author: Tony
6  * E-Mail: Tony@gmail.com
7  */
8 
9 #ifndef LOCK_H_
10 #define LOCK_H_
11 
12 
13 #ifdef HAVE_SYS_FILE_H
14 # include <sys/file.h>
15 #endif /* HAVE_SYS_FILE_H */
16 #ifdef LFS /* File Lock Server */
17 # include <sys/socket.h>
18 # include <netinet/in.h>
19 # include <arpa/inet.h>
20 #endif /* FLS */
21 #if defined(__linux__)
22 # include <linux/types.h> /* fix for linux-2.3.4? kernels */
23 # include <linux/serial.h>
24 # include <linux/version.h>
25 #endif /* __linux__ */
26 #if defined(__sun__)
27 # include <sys/filio.h>
28 # include <sys/mkdev.h>
29 #endif /* __sun__ */
30 #if defined(__hpux__)
31 # include <sys/modem.h>
32 #endif /* __hpux__ */
33 /* FIXME -- new file */
34 #if defined(__APPLE__)
35 # include <CoreFoundation/CoreFoundation.h>
36 # include <IOKit/IOKitLib.h>
37 # include <IOKit/serial/IOSerialKeys.h>
38 # include <IOKit/IOBSD.h>
39 #endif /* __APPLE__ */
40 #ifdef __unixware__
41 # include <sys/filio.h>
42 #endif /* __unixware__ */
43 #ifdef HAVE_PWD_H
44 #include <pwd.h>
45 #endif /* HAVE_PWD_H */
46 #ifdef HAVE_GRP_H
47 #include <grp.h>
48 #endif /* HAVE_GRP_H */
49 #include <math.h>
50 #ifdef LIBLOCKDEV
51 #include <lockdev.h>
52 #endif /* LIBLOCKDEV */
53 
54 
55 
56 /* Ports known on the OS */
57 #if defined(__linux__)
58 # define DEVICEDIR "/dev/"
59 # define LOCKDIR "/var/lock"
60 # define LOCKFILEPREFIX "LCK.."
61 # define FHS
62 #endif /* __linux__ */
63 #if defined(__QNX__)
64 # define DEVICEDIR "/dev/"
65 # define LOCKDIR ""
66 # define LOCKFILEPREFIX ""
67 #endif /* qnx */
68 #if defined(__sgi__) || defined(sgi)
69 # define DEVICEDIR "/dev/"
70 # define LOCKDIR "/usr/spool/uucp"
71 # define LOCKFILEPREFIX "LK."
72 # define UUCP
73 #endif /* __sgi__ || sgi */
74 #if defined(__FreeBSD__)
75 # define DEVICEDIR "/dev/"
76 # define LOCKDIR "/var/spool/lock"
77 # define LOCKFILEPREFIX "LK.."
78 # define UUCP
79 #endif /* __FreeBSD__ */
80 #if defined(__APPLE__)
81 # define DEVICEDIR "/dev/"
82 /*# define LOCKDIR "/var/spool/uucp"*/
83 # define LOCKDIR "/var/lock"
84 # define LOCKFILEPREFIX "LK."
85 # define UUCP
86 #endif /* __APPLE__ */
87 #if defined(__NetBSD__)
88 # define DEVICEDIR "/dev/"
89 # define LOCKDIR "/var/lock"
90 /*# define LOCKDIR "/usr/spool/uucp"*/
91 # define LOCKFILEPREFIX "LK."
92 # define UUCP
93 #endif /* __NetBSD__ */
94 #if defined(__unixware__)
95 # define DEVICEDIR "/dev/"
96 /* really this only fully works for OpenServer */
97 # define LOCKDIR "/var/spool/uucp/"
98 # define LOCKFILEPREFIX "LK."
99 /*
100 this needs work....
101 Jonathan Schilling <jls@caldera.com> writes:
102 This is complicated because as I said in my previous mail, there are
103 two kinds of SCO operating systems.
104 The one that most people want gnu.io for, including the guy who
105 asked the mailing list about SCO support a few days ago, is Open Server
106 (a/k/a "SCO UNIX"), which is SVR3-based. This uses old-style uucp locks,
107 of the form LCK..tty0a. That's what I implemented in the RXTX port I did,
108 and it works correctly.
109 The other SCO/Caldera OS, UnixWare/Open UNIX, uses the new-style
110 SVR4 locks, of the form LK.123.123.123. These OSes are a lot like
111 Solaris (UnixWare/Open UNIX come from AT&T SVR4 which had a joint
112 The other SCO/Caldera OS, UnixWare/Open UNIX, uses the new-style
113 SVR4 locks, of the form LK.123.123.123. These OSes are a lot like
114 Solaris (UnixWare/Open UNIX come from AT&T SVR4 which had a joint
115 heritage with Sun way back when). I saw that you added support
116 for this form of lock by RXTX 1.4-10 ... but it gets messy because,
117 as I said before, we use the same binary gnu.io files for both
118 UnixWare/Open UNIX and OpenServer. Thus we can't #ifdef one or the
119 other; it would have to be a runtime test. Your code and your macros
120 aren't set up for doing this (understandably!). So I didn't implement
121 these; the gnu.io locks won't fully work on UnixWare/Open UNIX
122 as a result, which I mentioned in the Release Notes.
123 What I would suggest is that you merge in the old-style LCK..tty0a lock
124 code that I used, since this will satisfy 90% of the SCO users. Then
125 I'll work on some way of getting UnixWare/Open UNIX locking to work
126 correctly, and give you those changes at a later date.
127 Jonathan
128 FIXME The lock type could be passed with -DOLDUUCP or -DUUCP based on
129 os.name in configure.in or perhaps system defines could determine the lock
130 type.
131 Trent
132 */
133 # define OLDUUCP
134 #endif
135 #if defined(__hpux__)
136 /* modif cath */
137 # define DEVICEDIR "/dev/"
138 # define LOCKDIR "/var/spool/uucp"
139 # define LOCKFILEPREFIX "LCK."
140 # define UUCP
141 #endif /* __hpux__ */
142 #if defined(__osf__) /* Digital Unix */
143 # define DEVICEDIR "/dev/"
144 # define LOCKDIR ""
145 # define LOCKFILEPREFIX "LK."
146 # define UUCP
147 #endif /* __osf__ */
148 #if defined(__sun__) /* Solaris */
149 # define DEVICEDIR "/dev/"
150 # define LOCKDIR "/var/spool/locks"
151 # define LOCKFILEPREFIX "LK."
152 /*
153 # define UUCP
154 */
155 #endif /* __sun__ */
156 #if defined(__BEOS__)
157 # define DEVICEDIR "/dev/ports/"
158 # define LOCKDIR ""
159 # define LOCKFILEPREFIX ""
160 # define UUCP
161 #endif /* __BEOS__ */
162 #if defined(WIN32)
163 # define DEVICEDIR "//./"
164 # define LOCKDIR ""
165 # define LOCKFILEPREFIX ""
166 #endif /* WIN32 */
167 
168 /* allow people to override the directories */
169 /* #define USER_LOCK_DIRECTORY "/home/tjarvi/1.5/build" */
170 #ifdef USER_LOCK_DIRECTORY
171 # define LOCKDIR USER_LOCK_DIRECTORY
172 #endif /* USER_LOCK_DIRECTORY */
173 
174 #ifdef DISABLE_LOCKFILES
175 #undef UUCP
176 #undef FHS
177 #undef OLDUUCP
178 #endif /* DISABLE_LOCKFILES */
179 
180 /* That should be all you need to look at in this file for porting */
181 #ifdef LFS /* Use a Lock File Server */
182 # define LOCK lfs_lock
183 # define UNLOCK lfs_unlock
184 #elif defined(UUCP)
185 # define LOCK uucp_lock
186 # define UNLOCK uucp_unlock
187 #elif defined(OLDUUCP)
188 /*
189  We can handle the old style if needed here see __unixware__ above.
190  defaulting to rxtx-1.4-8 behavior for now.
191  see also __sco__ in SerialImp.c when changing this for a possible
192  bug
193  FIXME
194 */
195 # define LOCK fhs_lock
196 # define UNLOCK fhs_unlock
197 #elif defined(FHS)
198 #ifdef LIBLOCKDEV
199 # define LOCK lib_lock_dev_lock
200 # define UNLOCK lib_lock_dev_unlock
201 #else
202 # define LOCK fhs_lock
203 # define UNLOCK fhs_unlock
204 #endif /* LIBLOCKDEV */
205 #else
206 # define LOCK system_does_not_lock
207 # define UNLOCK system_does_not_unlock
208 #endif /* UUCP */
209 
210 
211 
212 //#ifndef __WIN32__
213 //#define UUCP_LOCK_DIR "/var/lock"
214 
215 #ifdef __cplusplus
216 extern "C" {
217 #endif
218 //int uucp_lock( const char *file);
219 //int uucp_unlock(void);
220 int check_group_uucp();
221 int check_lock_pid( const char *file, int openpid );
222 int lock_device( const char * );
223 void unlock_device( const char * );
224 int is_device_locked( const char * );
225 int check_lock_status( const char * );
226 int lfs_unlock(const char *, int );
227 int lfs_lock( const char *, int);
228 int lib_lock_dev_unlock(const char *, int );
229 int lib_lock_dev_lock( const char *, int);
230 void fhs_unlock(const char *, int );
231 int fhs_lock( const char *, int);
232 void uucp_unlock( const char *, int );
233 int uucp_lock( const char *, int );
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 //#endif
240 
241 #endif /* LOCK_H_ */