rsync.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /*
  2. * Copyright (C) 1996, 2000 Andrew Tridgell
  3. * Copyright (C) 1996 Paul Mackerras
  4. * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
  5. * Copyright (C) 2003-2008 Wayne Davison
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, visit the http://fsf.org website.
  19. */
  20. #define False 0
  21. #define True 1
  22. #define BLOCK_SIZE 700
  23. #define RSYNC_RSH_ENV "RSYNC_RSH"
  24. #define RSYNC_RSH_IO_ENV "RSYNC_RSH_IO"
  25. #define RSYNC_NAME "rsync"
  26. /* RSYNCD_SYSCONF is now set in config.h */
  27. #define RSYNCD_USERCONF "rsyncd.conf"
  28. #define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
  29. #define URL_PREFIX "rsync://"
  30. #define SYMLINK_PREFIX "/rsyncd-munged/"
  31. #define SYMLINK_PREFIX_LEN ((int)sizeof SYMLINK_PREFIX - 1)
  32. #define BACKUP_SUFFIX "~"
  33. /* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
  34. incompatible with older versions :-( */
  35. #define CHAR_OFFSET 0
  36. /* These flags are only used during the flist transfer. */
  37. #define XMIT_TOP_DIR (1<<0)
  38. #define XMIT_SAME_MODE (1<<1)
  39. #define XMIT_SAME_RDEV_pre28 (1<<2) /* protocols 20 - 27 */
  40. #define XMIT_EXTENDED_FLAGS (1<<2) /* protocols 28 - now */
  41. #define XMIT_SAME_UID (1<<3)
  42. #define XMIT_SAME_GID (1<<4)
  43. #define XMIT_SAME_NAME (1<<5)
  44. #define XMIT_LONG_NAME (1<<6)
  45. #define XMIT_SAME_TIME (1<<7)
  46. #define XMIT_SAME_RDEV_MAJOR (1<<8) /* protocols 28 - now (devices only) */
  47. #define XMIT_NO_CONTENT_DIR (1<<8) /* protocols 30 - now (dirs only) */
  48. #define XMIT_HLINKED (1<<9) /* protocols 28 - now */
  49. #define XMIT_SAME_DEV_pre30 (1<<10) /* protocols 28 - 29 */
  50. #define XMIT_USER_NAME_FOLLOWS (1<<10) /* protocols 30 - now */
  51. #define XMIT_RDEV_MINOR_8_pre30 (1<<11) /* protocols 28 - 29 */
  52. #define XMIT_GROUP_NAME_FOLLOWS (1<<11) /* protocols 30 - now */
  53. #define XMIT_HLINK_FIRST (1<<12) /* protocols 30 - now (HLINKED files only) */
  54. /* These flags are used in the live flist data. */
  55. #define FLAG_TOP_DIR (1<<0) /* sender/receiver/generator */
  56. #define FLAG_FILE_SENT (1<<1) /* sender/receiver/generator */
  57. #define FLAG_DIR_CREATED (1<<1) /* generator */
  58. #define FLAG_CONTENT_DIR (1<<2) /* sender/receiver/generator */
  59. #define FLAG_MOUNT_DIR (1<<3) /* sender/generator (dirs only) */
  60. #define FLAG_SKIP_HLINK (1<<3) /* receiver/generator (w/FLAG_HLINKED) */
  61. #define FLAG_DUPLICATE (1<<4) /* sender */
  62. #define FLAG_MISSING_DIR (1<<4) /* generator */
  63. #define FLAG_HLINKED (1<<5) /* receiver/generator (checked on all types) */
  64. #define FLAG_HLINK_FIRST (1<<6) /* receiver/generator (w/FLAG_HLINKED) */
  65. #define FLAG_IMPLIED_DIR (1<<6) /* sender/receiver/generator (dirs only) */
  66. #define FLAG_HLINK_LAST (1<<7) /* receiver/generator */
  67. #define FLAG_HLINK_DONE (1<<8) /* receiver/generator (checked on all types) */
  68. #define FLAG_LENGTH64 (1<<9) /* sender/receiver/generator */
  69. #define FLAG_SKIP_GROUP (1<<10) /* receiver/generator */
  70. #define FLAG_TIME_FAILED (1<<11)/* generator */
  71. /* These flags are passed to functions but not stored. */
  72. #define FLAG_DIVERT_DIRS (1<<16)/* sender */
  73. #define BITS_SET(val,bits) (((val) & (bits)) == (bits))
  74. #define BITS_SETnUNSET(val,onbits,offbits) (((val) & ((onbits)|(offbits))) == (onbits))
  75. #define BITS_EQUAL(b1,b2,mask) (((unsigned)(b1) & (unsigned)(mask)) \
  76. == ((unsigned)(b2) & (unsigned)(mask)))
  77. /* update this if you make incompatible changes */
  78. #define PROTOCOL_VERSION 30
  79. /* This is used when working on a new protocol version in CVS, and should
  80. * be a new non-zero value for each CVS change that affects the protocol.
  81. * It must ALWAYS be 0 when the protocol goes final! */
  82. #define SUBPROTOCOL_VERSION 0
  83. /* We refuse to interoperate with versions that are not in this range.
  84. * Note that we assume we'll work with later versions: the onus is on
  85. * people writing them to make sure that they don't send us anything
  86. * we won't understand.
  87. *
  88. * Interoperation with old but supported protocol versions
  89. * should cause a warning to be printed. At a future date
  90. * the old protocol will become the minimum and
  91. * compatibility code removed.
  92. *
  93. * There are two possible explanations for the limit at
  94. * MAX_PROTOCOL_VERSION: either to allow new major-rev versions that
  95. * do not interoperate with us, and (more likely) so that we can
  96. * detect an attempt to connect rsync to a non-rsync server, which is
  97. * unlikely to begin by sending a byte between MIN_PROTOCL_VERSION and
  98. * MAX_PROTOCOL_VERSION. */
  99. #define MIN_PROTOCOL_VERSION 20
  100. #define OLD_PROTOCOL_VERSION 25
  101. #define MAX_PROTOCOL_VERSION 40
  102. #define FILECNT_LOOKAHEAD 1000
  103. #define RSYNC_PORT 873
  104. #define SPARSE_WRITE_SIZE (1024)
  105. #define WRITE_SIZE (32*1024)
  106. #define CHUNK_SIZE (32*1024)
  107. #define MAX_MAP_SIZE (256*1024)
  108. #define IO_BUFFER_SIZE (4092)
  109. #define MAX_BLOCK_SIZE ((int32)1 << 17)
  110. /* For compatibility with older rsyncs */
  111. #define OLD_MAX_BLOCK_SIZE ((int32)1 << 29)
  112. #define IOERR_GENERAL (1<<0) /* For backward compatibility, this must == 1 */
  113. #define IOERR_VANISHED (1<<1)
  114. #define IOERR_DEL_LIMIT (1<<2)
  115. #define MAX_ARGS 1000
  116. #define MAX_BASIS_DIRS 20
  117. #define MAX_SERVER_ARGS (MAX_BASIS_DIRS*2 + 100)
  118. #define MPLEX_BASE 7
  119. #define NO_FILTERS 0
  120. #define SERVER_FILTERS 1
  121. #define ALL_FILTERS 2
  122. #define XFLG_FATAL_ERRORS (1<<0)
  123. #define XFLG_OLD_PREFIXES (1<<1)
  124. #define XFLG_ANCHORED2ABS (1<<2) /* leading slash indicates absolute */
  125. #define XFLG_ABS_IF_SLASH (1<<3) /* leading or interior slash is absolute */
  126. #define XFLG_DIR2WILD3 (1<<4) /* dir/ match gets trailing *** added */
  127. #define ATTRS_REPORT (1<<0)
  128. #define ATTRS_SKIP_MTIME (1<<1)
  129. #define FULL_FLUSH 1
  130. #define NORMAL_FLUSH 0
  131. #define PDIR_CREATE 1
  132. #define PDIR_DELETE 0
  133. /* Note: 0x00 - 0x7F are used for basis_dir[] indexes! */
  134. #define FNAMECMP_BASIS_DIR_LOW 0x00 /* Must remain 0! */
  135. #define FNAMECMP_BASIS_DIR_HIGH 0x7F
  136. #define FNAMECMP_FNAME 0x80
  137. #define FNAMECMP_PARTIAL_DIR 0x81
  138. #define FNAMECMP_BACKUP 0x82
  139. #define FNAMECMP_FUZZY 0x83
  140. /* For use by the itemize_changes code */
  141. #define ITEM_REPORT_ATIME (1<<0)
  142. #define ITEM_REPORT_CHANGE (1<<1)
  143. #define ITEM_REPORT_SIZE (1<<2) /* regular files only */
  144. #define ITEM_REPORT_TIMEFAIL (1<<2) /* symlinks only */
  145. #define ITEM_REPORT_TIME (1<<3)
  146. #define ITEM_REPORT_PERMS (1<<4)
  147. #define ITEM_REPORT_OWNER (1<<5)
  148. #define ITEM_REPORT_GROUP (1<<6)
  149. #define ITEM_REPORT_ACL (1<<7)
  150. #define ITEM_REPORT_XATTR (1<<8)
  151. #define ITEM_BASIS_TYPE_FOLLOWS (1<<11)
  152. #define ITEM_XNAME_FOLLOWS (1<<12)
  153. #define ITEM_IS_NEW (1<<13)
  154. #define ITEM_LOCAL_CHANGE (1<<14)
  155. #define ITEM_TRANSFER (1<<15)
  156. /* These are outside the range of the transmitted flags. */
  157. #define ITEM_MISSING_DATA (1<<16) /* used by log_formatted() */
  158. #define ITEM_DELETED (1<<17) /* used by log_formatted() */
  159. #define ITEM_MATCHED (1<<18) /* used by itemize() */
  160. #define SIGNIFICANT_ITEM_FLAGS (~(\
  161. ITEM_BASIS_TYPE_FOLLOWS | ITEM_XNAME_FOLLOWS | ITEM_LOCAL_CHANGE))
  162. #define CFN_KEEP_DOT_DIRS (1<<0)
  163. #define CFN_KEEP_TRAILING_SLASH (1<<1)
  164. #define CFN_DROP_TRAILING_DOT_DIR (1<<2)
  165. #define CFN_COLLAPSE_DOT_DOT_DIRS (1<<3)
  166. #define SP_DEFAULT 0
  167. #define SP_KEEP_DOT_DIRS (1<<0)
  168. #define CD_NORMAL 0
  169. #define CD_SKIP_CHDIR 1
  170. /* Log-message categories. FLOG only goes to the log file, not the client;
  171. * FCLIENT is the opposite. */
  172. enum logcode {
  173. FNONE=0, /* never sent */
  174. FERROR_XFER=1, FINFO=2, /* sent over socket for any protocol */
  175. FERROR=3, FWARNING=4, /* sent over socket for protocols >= 30 */
  176. FERROR_SOCKET=5, FLOG=6, /* only sent via receiver -> generator pipe */
  177. FERROR_UTF8=8, /* only sent via receiver -> generator pipe */
  178. FCLIENT=7 /* never transmitted (e.g. server converts to FINFO) */
  179. };
  180. /* Messages types that are sent over the message channel. The logcode
  181. * values must all be present here with identical numbers. */
  182. enum msgcode {
  183. MSG_DATA=0, /* raw data on the multiplexed stream */
  184. MSG_ERROR_XFER=FERROR_XFER, MSG_INFO=FINFO, /* remote logging */
  185. MSG_ERROR=FERROR, MSG_WARNING=FWARNING, /* protocol-30 remote logging */
  186. MSG_ERROR_SOCKET=FERROR_SOCKET, /* sibling logging */
  187. MSG_ERROR_UTF8=FERROR_UTF8, /* sibling logging */
  188. MSG_LOG=FLOG, MSG_CLIENT=FCLIENT, /* sibling logging */
  189. MSG_REDO=9, /* reprocess indicated flist index */
  190. MSG_FLIST=20, /* extra file list over sibling socket */
  191. MSG_FLIST_EOF=21,/* we've transmitted all the file lists */
  192. MSG_IO_ERROR=22,/* the sending side had an I/O error */
  193. MSG_NOOP=42, /* a do-nothing message */
  194. MSG_SUCCESS=100,/* successfully updated indicated flist index */
  195. MSG_DELETED=101,/* successfully deleted a file on receiving side */
  196. MSG_NO_SEND=102,/* sender failed to open a file we wanted */
  197. MSG_DONE=86 /* current phase is done */
  198. };
  199. #define NDX_DONE -1
  200. #define NDX_FLIST_EOF -2
  201. #define NDX_FLIST_OFFSET -101
  202. #include "errcode.h"
  203. #include "config.h"
  204. /* The default RSYNC_RSH is always set in config.h. */
  205. #include <stdio.h>
  206. #ifdef HAVE_SYS_TYPES_H
  207. # include <sys/types.h>
  208. #endif
  209. #ifdef HAVE_SYS_STAT_H
  210. # include <sys/stat.h>
  211. #endif
  212. #ifdef STDC_HEADERS
  213. # include <stdlib.h>
  214. # include <stddef.h>
  215. #else
  216. # ifdef HAVE_STDLIB_H
  217. # include <stdlib.h>
  218. # endif
  219. #endif
  220. #ifdef HAVE_STRING_H
  221. # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
  222. # include <memory.h>
  223. # endif
  224. # include <string.h>
  225. #endif
  226. #ifdef HAVE_STRINGS_H
  227. # include <strings.h>
  228. #endif
  229. #ifdef HAVE_INTTYPES_H
  230. # include <inttypes.h>
  231. #endif
  232. #ifdef HAVE_STDINT_H
  233. # include <stdint.h>
  234. #endif
  235. #ifdef HAVE_UNISTD_H
  236. # include <unistd.h>
  237. #endif
  238. #ifdef HAVE_SYS_PARAM_H
  239. #include <sys/param.h>
  240. #endif
  241. #if defined HAVE_MALLOC_H && (defined HAVE_MALLINFO || !defined HAVE_STDLIB_H)
  242. #include <malloc.h>
  243. #endif
  244. #ifdef HAVE_SYS_SOCKET_H
  245. #include <sys/socket.h>
  246. #endif
  247. #ifdef TIME_WITH_SYS_TIME
  248. #include <sys/time.h>
  249. #include <time.h>
  250. #else
  251. #ifdef HAVE_SYS_TIME_H
  252. #include <sys/time.h>
  253. #else
  254. #include <time.h>
  255. #endif
  256. #endif
  257. #ifdef HAVE_FCNTL_H
  258. #include <fcntl.h>
  259. #else
  260. #ifdef HAVE_SYS_FCNTL_H
  261. #include <sys/fcntl.h>
  262. #endif
  263. #endif
  264. #ifdef HAVE_SYS_IOCTL_H
  265. #include <sys/ioctl.h>
  266. #endif
  267. #ifdef HAVE_SYS_FILIO_H
  268. #include <sys/filio.h>
  269. #endif
  270. #include <signal.h>
  271. #ifdef HAVE_SYS_WAIT_H
  272. #include <sys/wait.h>
  273. #endif
  274. #ifdef HAVE_CTYPE_H
  275. #include <ctype.h>
  276. #endif
  277. #ifdef HAVE_GRP_H
  278. #include <grp.h>
  279. #endif
  280. #include <errno.h>
  281. #ifdef HAVE_UTIME_H
  282. #include <utime.h>
  283. #endif
  284. #ifdef HAVE_SYS_SELECT_H
  285. #include <sys/select.h>
  286. #endif
  287. #ifdef HAVE_SYS_MODE_H
  288. /* apparently AIX needs this for S_ISLNK */
  289. #ifndef S_ISLNK
  290. #include <sys/mode.h>
  291. #endif
  292. #endif
  293. /* these are needed for the uid/gid mapping code */
  294. #include <pwd.h>
  295. #include <grp.h>
  296. #include <stdarg.h>
  297. #include <netinet/in.h>
  298. #include <arpa/inet.h>
  299. #ifdef HAVE_NETDB_H
  300. #include <netdb.h>
  301. #endif
  302. #include <syslog.h>
  303. #include <sys/file.h>
  304. #ifdef HAVE_DIRENT_H
  305. # include <dirent.h>
  306. #else
  307. # define dirent direct
  308. # ifdef HAVE_SYS_NDIR_H
  309. # include <sys/ndir.h>
  310. # endif
  311. # ifdef HAVE_SYS_DIR_H
  312. # include <sys/dir.h>
  313. # endif
  314. # ifdef HAVE_NDIR_H
  315. # include <ndir.h>
  316. # endif
  317. #endif
  318. #ifdef MAJOR_IN_MKDEV
  319. #include <sys/mkdev.h>
  320. # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
  321. # define makedev mkdev
  322. # endif
  323. #elif defined MAJOR_IN_SYSMACROS
  324. #include <sys/sysmacros.h>
  325. #endif
  326. #ifdef MAKEDEV_TAKES_3_ARGS
  327. #define MAKEDEV(devmajor,devminor) makedev(0,devmajor,devminor)
  328. #else
  329. #define MAKEDEV(devmajor,devminor) makedev(devmajor,devminor)
  330. #endif
  331. #ifdef HAVE_COMPAT_H
  332. #include <compat.h>
  333. #endif
  334. #ifdef HAVE_LIMITS_H
  335. # include <limits.h>
  336. #endif
  337. #if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
  338. #include <iconv.h>
  339. #ifndef ICONV_CONST
  340. #define ICONV_CONST
  341. #endif
  342. #else
  343. #ifdef ICONV_CONST
  344. #undef ICONV_CONST
  345. #endif
  346. #ifdef ICONV_OPTION
  347. #undef ICONV_OPTION
  348. #endif
  349. #ifdef iconv_t
  350. #undef iconv_t
  351. #endif
  352. #define iconv_t int
  353. #endif
  354. #include <assert.h>
  355. #include "lib/pool_alloc.h"
  356. #ifndef HAVE_ID_T
  357. typedef unsigned int id_t;
  358. #endif
  359. #ifndef HAVE_PID_T
  360. typedef int pid_t;
  361. #endif
  362. #ifndef HAVE_MODE_T
  363. typedef unsigned int mode_t;
  364. #endif
  365. #ifndef HAVE_OFF_T
  366. typedef long off_t;
  367. #endif
  368. #ifndef HAVE_SIZE_T
  369. typedef unsigned int size_t;
  370. #endif
  371. #define BOOL int
  372. #ifndef uchar
  373. #define uchar unsigned char
  374. #endif
  375. #ifdef SIGNED_CHAR_OK
  376. #define schar signed char
  377. #else
  378. #define schar char
  379. #endif
  380. #ifndef int16
  381. #if SIZEOF_INT16_T == 2
  382. # define int16 int16_t
  383. #else
  384. # define int16 short
  385. #endif
  386. #endif
  387. #ifndef uint16
  388. #if SIZEOF_UINT16_T == 2
  389. # define uint16 uint16_t
  390. #else
  391. # define uint16 unsigned int16
  392. #endif
  393. #endif
  394. /* Find a variable that is either exactly 32-bits or longer.
  395. * If some code depends on 32-bit truncation, it will need to
  396. * take special action in a "#if SIZEOF_INT32 > 4" section. */
  397. #ifndef int32
  398. #if SIZEOF_INT32_T == 4
  399. # define int32 int32_t
  400. # define SIZEOF_INT32 4
  401. #elif SIZEOF_INT == 4
  402. # define int32 int
  403. # define SIZEOF_INT32 4
  404. #elif SIZEOF_LONG == 4
  405. # define int32 long
  406. # define SIZEOF_INT32 4
  407. #elif SIZEOF_SHORT == 4
  408. # define int32 short
  409. # define SIZEOF_INT32 4
  410. #elif SIZEOF_INT > 4
  411. # define int32 int
  412. # define SIZEOF_INT32 SIZEOF_INT
  413. #elif SIZEOF_LONG > 4
  414. # define int32 long
  415. # define SIZEOF_INT32 SIZEOF_LONG
  416. #else
  417. # error Could not find a 32-bit integer variable
  418. #endif
  419. #else
  420. # define SIZEOF_INT32 4
  421. #endif
  422. #ifndef uint32
  423. #if SIZEOF_UINT32_T == 4
  424. # define uint32 uint32_t
  425. #else
  426. # define uint32 unsigned int32
  427. #endif
  428. #endif
  429. #if SIZEOF_OFF_T == 8 || !SIZEOF_OFF64_T || !defined HAVE_STRUCT_STAT64
  430. #define OFF_T off_t
  431. #define STRUCT_STAT struct stat
  432. #define SIZEOF_CAPITAL_OFF_T SIZEOF_OFF_T
  433. #else
  434. #define OFF_T off64_t
  435. #define STRUCT_STAT struct stat64
  436. #define USE_STAT64_FUNCS 1
  437. #define SIZEOF_CAPITAL_OFF_T SIZEOF_OFF64_T
  438. #endif
  439. /* CAVEAT: on some systems, int64 will really be a 32-bit integer IFF
  440. * that's the maximum size the file system can handle and there is no
  441. * 64-bit type available. The rsync source must therefore take steps
  442. * to ensure that any code that really requires a 64-bit integer has
  443. * it (e.g. the checksum code uses two 32-bit integers for its 64-bit
  444. * counter). */
  445. #if SIZEOF_INT64_T == 8
  446. # define int64 int64_t
  447. # define SIZEOF_INT64 8
  448. #elif SIZEOF_LONG == 8
  449. # define int64 long
  450. # define SIZEOF_INT64 8
  451. #elif SIZEOF_INT == 8
  452. # define int64 int
  453. # define SIZEOF_INT64 8
  454. #elif SIZEOF_LONG_LONG == 8
  455. # define int64 long long
  456. # define SIZEOF_INT64 8
  457. #elif SIZEOF_OFF64_T == 8
  458. # define int64 off64_t
  459. # define SIZEOF_INT64 8
  460. #elif SIZEOF_OFF_T == 8
  461. # define int64 off_t
  462. # define SIZEOF_INT64 8
  463. #elif SIZEOF_INT > 8
  464. # define int64 int
  465. # define SIZEOF_INT64 SIZEOF_INT
  466. #elif SIZEOF_LONG > 8
  467. # define int64 long
  468. # define SIZEOF_INT64 SIZEOF_LONG
  469. #elif SIZEOF_LONG_LONG > 8
  470. # define int64 long long
  471. # define SIZEOF_INT64 SIZEOF_LONG_LONG
  472. #else
  473. /* As long as it gets... */
  474. # define int64 off_t
  475. # define SIZEOF_INT64 SIZEOF_OFF_T
  476. #endif
  477. struct hashtable {
  478. void *nodes;
  479. int32 size, entries;
  480. uint32 node_size;
  481. int key64;
  482. };
  483. struct ht_int32_node {
  484. void *data;
  485. int32 key;
  486. };
  487. struct ht_int64_node {
  488. void *data;
  489. int64 key;
  490. };
  491. #define HT_NODE(tbl, bkts, i) ((void*)((char*)(bkts) + (i)*(tbl)->node_size))
  492. #define HT_KEY(node, k64) ((k64)? ((struct ht_int64_node*)(node))->key \
  493. : (int64)((struct ht_int32_node*)(node))->key)
  494. #ifndef MIN
  495. #define MIN(a,b) ((a)<(b)?(a):(b))
  496. #endif
  497. #ifndef MAX
  498. #define MAX(a,b) ((a)>(b)?(a):(b))
  499. #endif
  500. #ifndef MAXHOSTNAMELEN
  501. #define MAXHOSTNAMELEN 256
  502. #endif
  503. #define SUM_LENGTH 16
  504. #define SHORT_SUM_LENGTH 2
  505. #define BLOCKSUM_BIAS 10
  506. #ifndef MAXPATHLEN
  507. #define MAXPATHLEN 1024
  508. #endif
  509. /* We want a roomy line buffer that can hold more than MAXPATHLEN,
  510. * and significantly more than an overly short MAXPATHLEN. */
  511. #if MAXPATHLEN < 4096
  512. #define BIGPATHBUFLEN (4096+1024)
  513. #else
  514. #define BIGPATHBUFLEN (MAXPATHLEN+1024)
  515. #endif
  516. #ifndef NAME_MAX
  517. #define NAME_MAX 255
  518. #endif
  519. #ifndef INADDR_NONE
  520. #define INADDR_NONE 0xffffffff
  521. #endif
  522. #ifndef IN_LOOPBACKNET
  523. #define IN_LOOPBACKNET 127
  524. #endif
  525. #if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
  526. #define ACLS_NEED_MASK 1
  527. #endif
  528. union file_extras {
  529. int32 num;
  530. uint32 unum;
  531. };
  532. struct file_struct {
  533. const char *dirname; /* The dir info inside the transfer */
  534. time_t modtime; /* When the item was last modified */
  535. uint32 len32; /* Lowest 32 bits of the file's length */
  536. uint16 mode; /* The item's type and permissions */
  537. uint16 flags; /* The FLAG_* bits for this item */
  538. const char basename[1]; /* The basename (AKA filename) follows */
  539. };
  540. extern int file_extra_cnt;
  541. extern int inc_recurse;
  542. extern int uid_ndx;
  543. extern int gid_ndx;
  544. extern int acls_ndx;
  545. extern int xattrs_ndx;
  546. #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename))
  547. #define EXTRA_LEN (sizeof (union file_extras))
  548. #define PTR_EXTRA_CNT ((sizeof (char *) + EXTRA_LEN - 1) / EXTRA_LEN)
  549. #define DEV_EXTRA_CNT 2
  550. #define DIRNODE_EXTRA_CNT 3
  551. #define SUM_EXTRA_CNT ((MAX_DIGEST_LEN + EXTRA_LEN - 1) / EXTRA_LEN)
  552. #define REQ_EXTRA(f,ndx) ((union file_extras*)(f) - (ndx))
  553. #define OPT_EXTRA(f,bump) ((union file_extras*)(f) - file_extra_cnt - 1 - (bump))
  554. #define LEN64_BUMP(f) ((f)->flags & FLAG_LENGTH64 ? 1 : 0)
  555. #define HLINK_BUMP(f) ((f)->flags & (FLAG_HLINKED|FLAG_HLINK_DONE) ? inc_recurse+1 : 0)
  556. #define ACL_BUMP(f) (acls_ndx ? 1 : 0)
  557. /* The length applies to all items. */
  558. #if SIZEOF_INT64 < 8
  559. #define F_LENGTH(f) ((int64)(f)->len32)
  560. #else
  561. #define F_LENGTH(f) ((int64)(f)->len32 + ((f)->flags & FLAG_LENGTH64 \
  562. ? (int64)OPT_EXTRA(f, 0)->unum << 32 : 0))
  563. #endif
  564. /* If there is a symlink string, it is always right after the basename */
  565. #define F_SYMLINK(f) ((f)->basename + strlen((f)->basename) + 1)
  566. /* The sending side always has this available: */
  567. #define F_PATHNAME(f) (*(const char**)REQ_EXTRA(f, PTR_EXTRA_CNT))
  568. /* The receiving side always has this available: */
  569. #define F_DEPTH(f) REQ_EXTRA(f, 1)->num
  570. /* When the associated option is on, all entries will have these present: */
  571. #define F_OWNER(f) REQ_EXTRA(f, uid_ndx)->unum
  572. #define F_GROUP(f) REQ_EXTRA(f, gid_ndx)->unum
  573. #define F_ACL(f) REQ_EXTRA(f, acls_ndx)->num
  574. #define F_XATTR(f) REQ_EXTRA(f, xattrs_ndx)->num
  575. #define F_NDX(f) REQ_EXTRA(f, unsort_ndx)->num
  576. /* These items are per-entry optional: */
  577. #define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num /* non-dirs */
  578. #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f)+inc_recurse)->num /* non-dirs */
  579. #define F_DIR_NODE_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) \
  580. + DIRNODE_EXTRA_CNT - 1)->num) /* sender dirs */
  581. #define F_DIR_RELNAMES_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + DIRNODE_EXTRA_CNT \
  582. + PTR_EXTRA_CNT - 1)->num) /* sender dirs */
  583. #define F_DIR_DEFACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum /* receiver dirs */
  584. #define F_DIR_DEV_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + ACL_BUMP(f) \
  585. + DEV_EXTRA_CNT - 1)->unum) /* receiver dirs */
  586. /* This optional item might follow an F_HL_*() item.
  587. * (Note: a device doesn't need to check LEN64_BUMP(f).) */
  588. #define F_RDEV_P(f) (&OPT_EXTRA(f, HLINK_BUMP(f) + DEV_EXTRA_CNT - 1)->unum)
  589. /* The sum is only present on regular files. */
  590. #define F_SUM(f) ((char*)OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f) \
  591. + SUM_EXTRA_CNT - 1))
  592. /* Some utility defines: */
  593. #define F_IS_ACTIVE(f) (f)->basename[0]
  594. #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)
  595. #define F_HLINK_NOT_FIRST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_FIRST)
  596. #define F_HLINK_NOT_LAST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_LAST)
  597. /* These access the F_DIR_DEV_P() and F_RDEV_P() values: */
  598. #define DEV_MAJOR(a) (a)[0]
  599. #define DEV_MINOR(a) (a)[1]
  600. /* These access the F_DIRS_NODE_P() values: */
  601. #define DIR_PARENT(a) (a)[0]
  602. #define DIR_FIRST_CHILD(a) (a)[1]
  603. #define DIR_NEXT_SIBLING(a) (a)[2]
  604. /*
  605. * Start the flist array at FLIST_START entries and grow it
  606. * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
  607. */
  608. #define FLIST_START (32 * 1024)
  609. #define FLIST_LINEAR (FLIST_START * 512)
  610. /*
  611. * Extent size for allocation pools: A minimum size of 128KB
  612. * is needed to mmap them so that freeing will release the
  613. * space to the OS.
  614. *
  615. * Larger sizes reduce leftover fragments and speed free calls
  616. * (when they happen). Smaller sizes increase the chance of
  617. * freed allocations freeing whole extents.
  618. */
  619. #define NORMAL_EXTENT (256 * 1024)
  620. #define SMALL_EXTENT (128 * 1024)
  621. #define FLIST_TEMP (1<<1)
  622. struct file_list {
  623. struct file_list *next, *prev;
  624. struct file_struct **files, **sorted;
  625. alloc_pool_t file_pool;
  626. void *pool_boundary;
  627. int used, malloced;
  628. int low, high; /* 0-relative index values excluding empties */
  629. int ndx_start; /* the start offset for inc_recurse mode */
  630. int flist_num; /* 1-relative file_list number or 0 */
  631. int parent_ndx; /* dir_flist index of parent directory */
  632. int in_progress, to_redo;
  633. };
  634. #define SUMFLG_SAME_OFFSET (1<<0)
  635. struct sum_buf {
  636. OFF_T offset; /**< offset in file of this chunk */
  637. int32 len; /**< length of chunk of file */
  638. uint32 sum1; /**< simple checksum */
  639. int32 chain; /**< next hash-table collision */
  640. short flags; /**< flag bits */
  641. char sum2[SUM_LENGTH]; /**< checksum */
  642. };
  643. struct sum_struct {
  644. OFF_T flength; /**< total file length */
  645. struct sum_buf *sums; /**< points to info for each chunk */
  646. int32 count; /**< how many chunks */
  647. int32 blength; /**< block_length */
  648. int32 remainder; /**< flength % block_length */
  649. int s2length; /**< sum2_length */
  650. };
  651. struct map_struct {
  652. OFF_T file_size; /* File size (from stat) */
  653. OFF_T p_offset; /* Window start */
  654. OFF_T p_fd_offset; /* offset of cursor in fd ala lseek */
  655. char *p; /* Window pointer */
  656. int32 p_size; /* Largest window size we allocated */
  657. int32 p_len; /* Latest (rounded) window size */
  658. int32 def_window_size; /* Default window size */
  659. int fd; /* File Descriptor */
  660. int status; /* first errno from read errors */
  661. };
  662. #define MATCHFLG_WILD (1<<0) /* pattern has '*', '[', and/or '?' */
  663. #define MATCHFLG_WILD2 (1<<1) /* pattern has '**' */
  664. #define MATCHFLG_WILD2_PREFIX (1<<2) /* pattern starts with "**" */
  665. #define MATCHFLG_WILD3_SUFFIX (1<<3) /* pattern ends with "***" */
  666. #define MATCHFLG_ABS_PATH (1<<4) /* path-match on absolute path */
  667. #define MATCHFLG_INCLUDE (1<<5) /* this is an include, not an exclude */
  668. #define MATCHFLG_DIRECTORY (1<<6) /* this matches only directories */
  669. #define MATCHFLG_WORD_SPLIT (1<<7) /* split rules on whitespace */
  670. #define MATCHFLG_NO_INHERIT (1<<8) /* don't inherit these rules */
  671. #define MATCHFLG_NO_PREFIXES (1<<9) /* parse no prefixes from patterns */
  672. #define MATCHFLG_MERGE_FILE (1<<10)/* specifies a file to merge */
  673. #define MATCHFLG_PERDIR_MERGE (1<<11)/* merge-file is searched per-dir */
  674. #define MATCHFLG_EXCLUDE_SELF (1<<12)/* merge-file name should be excluded */
  675. #define MATCHFLG_FINISH_SETUP (1<<13)/* per-dir merge file needs setup */
  676. #define MATCHFLG_NEGATE (1<<14)/* rule matches when pattern does not */
  677. #define MATCHFLG_CVS_IGNORE (1<<15)/* rule was -C or :C */
  678. #define MATCHFLG_SENDER_SIDE (1<<16)/* rule applies to the sending side */
  679. #define MATCHFLG_RECEIVER_SIDE (1<<17)/* rule applies to the receiving side */
  680. #define MATCHFLG_CLEAR_LIST (1<<18)/* this item is the "!" token */
  681. #define MATCHFLG_PERISHABLE (1<<19)/* perishable if parent dir goes away */
  682. #define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \
  683. | MATCHFLG_DIRECTORY | MATCHFLG_SENDER_SIDE \
  684. | MATCHFLG_NEGATE | MATCHFLG_RECEIVER_SIDE \
  685. | MATCHFLG_PERISHABLE)
  686. struct filter_struct {
  687. struct filter_struct *next;
  688. char *pattern;
  689. uint32 match_flags;
  690. union {
  691. int slash_cnt;
  692. struct filter_list_struct *mergelist;
  693. } u;
  694. };
  695. struct filter_list_struct {
  696. struct filter_struct *head;
  697. struct filter_struct *tail;
  698. char *debug_type;
  699. };
  700. struct stats {
  701. int64 total_size;
  702. int64 total_transferred_size;
  703. int64 total_written;
  704. int64 total_read;
  705. int64 literal_data;
  706. int64 matched_data;
  707. int64 flist_buildtime;
  708. int64 flist_xfertime;
  709. int64 flist_size;
  710. int num_files;
  711. int num_transferred_files;
  712. };
  713. struct chmod_mode_struct;
  714. #define EMPTY_ITEM_LIST {NULL, 0, 0}
  715. typedef struct {
  716. void *items;
  717. size_t count;
  718. size_t malloced;
  719. } item_list;
  720. #define EXPAND_ITEM_LIST(lp, type, incr) \
  721. (type*)expand_item_list(lp, sizeof (type), #type, incr)
  722. #define EMPTY_XBUF {NULL, 0, 0, 0}
  723. typedef struct {
  724. char *buf;
  725. size_t pos; /* pos = read pos in the buf */
  726. size_t len; /* len = chars following pos */
  727. size_t size; /* size = total space in buf */
  728. } xbuf;
  729. #define INIT_XBUF(xb, str, ln, sz) (xb).buf = (str), (xb).len = (ln), (xb).size = (sz), (xb).pos = 0
  730. #define INIT_XBUF_STRLEN(xb, str) (xb).buf = (str), (xb).len = strlen((xb).buf), (xb).size = (-1), (xb).pos = 0
  731. /* This one is used to make an output xbuf based on a char[] buffer: */
  732. #define INIT_CONST_XBUF(xb, bf) (xb).buf = (bf), (xb).size = sizeof (bf), (xb).len = (xb).pos = 0
  733. #define ICB_EXPAND_OUT (1<<0)
  734. #define ICB_INCLUDE_BAD (1<<1)
  735. #define ICB_INCLUDE_INCOMPLETE (1<<2)
  736. #define RL_EOL_NULLS (1<<0)
  737. #define RL_DUMP_COMMENTS (1<<1)
  738. #define RL_CONVERT (1<<2)
  739. typedef struct {
  740. char name_type;
  741. char fname[1]; /* has variable size */
  742. } relnamecache;
  743. #include "byteorder.h"
  744. #include "lib/mdigest.h"
  745. #include "lib/wildmatch.h"
  746. #include "lib/permstring.h"
  747. #include "lib/addrinfo.h"
  748. #ifndef __GNUC__
  749. #define __attribute__(x)
  750. #else
  751. # if __GNUC__ <= 2
  752. # define NORETURN
  753. # endif
  754. #endif
  755. #define UNUSED(x) x __attribute__((__unused__))
  756. #ifndef NORETURN
  757. #define NORETURN __attribute__((__noreturn__))
  758. #endif
  759. typedef struct {
  760. STRUCT_STAT st;
  761. #ifdef SUPPORT_ACLS
  762. struct rsync_acl *acc_acl; /* access ACL */
  763. struct rsync_acl *def_acl; /* default ACL */
  764. #endif
  765. #ifdef SUPPORT_XATTRS
  766. item_list *xattr;
  767. #endif
  768. } stat_x;
  769. #define ACL_READY(sx) ((sx).acc_acl != NULL)
  770. #define XATTR_READY(sx) ((sx).xattr != NULL)
  771. #include "proto.h"
  772. #ifndef SUPPORT_XATTRS
  773. #define x_stat(fn,fst,xst) do_stat(fn,fst)
  774. #define x_lstat(fn,fst,xst) do_lstat(fn,fst)
  775. #define x_fstat(fd,fst,xst) do_fstat(fd,fst)
  776. #endif
  777. /* We have replacement versions of these if they're missing. */
  778. #ifndef HAVE_ASPRINTF
  779. int asprintf(char **ptr, const char *format, ...);
  780. #endif
  781. #ifndef HAVE_VASPRINTF
  782. int vasprintf(char **ptr, const char *format, va_list ap);
  783. #endif
  784. #if !defined HAVE_VSNPRINTF || !defined HAVE_C99_VSNPRINTF
  785. #define vsnprintf rsync_vsnprintf
  786. int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
  787. #endif
  788. #if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
  789. #define snprintf rsync_snprintf
  790. int snprintf(char *str, size_t count, const char *fmt,...);
  791. #endif
  792. #ifndef HAVE_STRERROR
  793. extern char *sys_errlist[];
  794. #define strerror(i) sys_errlist[i]
  795. #endif
  796. #ifndef HAVE_STRCHR
  797. # define strchr index
  798. # define strrchr rindex
  799. #endif
  800. #ifndef HAVE_ERRNO_DECL
  801. extern int errno;
  802. #endif
  803. #ifdef HAVE_READLINK
  804. #define SUPPORT_LINKS 1
  805. #endif
  806. #ifdef HAVE_LINK
  807. #define SUPPORT_HARD_LINKS 1
  808. #endif
  809. #ifdef HAVE_SIGACTION
  810. #define SIGACTION(n,h) sigact.sa_handler=(h), sigaction((n),&sigact,NULL)
  811. #define signal(n,h) we_need_to_call_SIGACTION_not_signal(n,h)
  812. #else
  813. #define SIGACTION(n,h) signal(n,h)
  814. #endif
  815. #ifndef EWOULDBLOCK
  816. #define EWOULDBLOCK EAGAIN
  817. #endif
  818. #ifndef STDIN_FILENO
  819. #define STDIN_FILENO 0
  820. #endif
  821. #ifndef STDOUT_FILENO
  822. #define STDOUT_FILENO 1
  823. #endif
  824. #ifndef STDERR_FILENO
  825. #define STDERR_FILENO 2
  826. #endif
  827. #ifndef S_IRUSR
  828. #define S_IRUSR 0400
  829. #endif
  830. #ifndef S_IWUSR
  831. #define S_IWUSR 0200
  832. #endif
  833. #ifndef ACCESSPERMS
  834. #define ACCESSPERMS 0777
  835. #endif
  836. #ifndef S_ISVTX
  837. #define S_ISVTX 0
  838. #endif
  839. #define CHMOD_BITS (S_ISUID | S_ISGID | S_ISVTX | ACCESSPERMS)
  840. #ifndef _S_IFMT
  841. #define _S_IFMT 0170000
  842. #endif
  843. #ifndef _S_IFLNK
  844. #define _S_IFLNK 0120000
  845. #endif
  846. #ifndef S_ISLNK
  847. #define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
  848. #endif
  849. #ifndef S_ISBLK
  850. #define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
  851. #endif
  852. #ifndef S_ISCHR
  853. #define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
  854. #endif
  855. #ifndef S_ISSOCK
  856. #ifdef _S_IFSOCK
  857. #define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
  858. #else
  859. #define S_ISSOCK(mode) (0)
  860. #endif
  861. #endif
  862. #ifndef S_ISFIFO
  863. #ifdef _S_IFIFO
  864. #define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
  865. #else
  866. #define S_ISFIFO(mode) (0)
  867. #endif
  868. #endif
  869. #ifndef S_ISDIR
  870. #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
  871. #endif
  872. #ifndef S_ISREG
  873. #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
  874. #endif
  875. /* work out what fcntl flag to use for non-blocking */
  876. #ifdef O_NONBLOCK
  877. # define NONBLOCK_FLAG O_NONBLOCK
  878. #elif defined SYSV
  879. # define NONBLOCK_FLAG O_NDELAY
  880. #else
  881. # define NONBLOCK_FLAG FNDELAY
  882. #endif
  883. #ifndef INADDR_LOOPBACK
  884. #define INADDR_LOOPBACK 0x7f000001
  885. #endif
  886. #ifndef INADDR_NONE
  887. #define INADDR_NONE 0xffffffff
  888. #endif
  889. #define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
  890. #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
  891. /* Initial mask on permissions given to temporary files. Mask off setuid
  892. bits and group access because of potential race-condition security
  893. holes, and mask other access because mode 707 is bizarre */
  894. #define INITACCESSPERMS 0700
  895. /* handler for null strings in printf format */
  896. #define NS(s) ((s)?(s):"<NULL>")
  897. /* Convenient wrappers for malloc and realloc. Use them. */
  898. #define new(type) ((type*)malloc(sizeof (type)))
  899. #define new0(type) ((type*)calloc(1, sizeof (type)))
  900. #define new_array(type, num) ((type*)_new_array((num), sizeof (type), 0))
  901. #define new_array0(type, num) ((type*)_new_array((num), sizeof (type), 1))
  902. #define realloc_array(ptr, type, num) ((type*)_realloc_array((ptr), sizeof(type), (num)))
  903. /* use magic gcc attributes to catch format errors */
  904. void rprintf(enum logcode , const char *, ...)
  905. __attribute__((format (printf, 2, 3)))
  906. ;
  907. /* This is just like rprintf, but it also tries to print some
  908. * representation of the error code. Normally errcode = errno. */
  909. void rsyserr(enum logcode, int, const char *, ...)
  910. __attribute__((format (printf, 3, 4)))
  911. ;
  912. /* Make sure that the O_BINARY flag is defined. */
  913. #ifndef O_BINARY
  914. #define O_BINARY 0
  915. #endif
  916. #ifndef HAVE_STRLCPY
  917. size_t strlcpy(char *d, const char *s, size_t bufsize);
  918. #endif
  919. #ifndef HAVE_STRLCAT
  920. size_t strlcat(char *d, const char *s, size_t bufsize);
  921. #endif
  922. #ifndef WEXITSTATUS
  923. #define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
  924. #endif
  925. #ifndef WIFEXITED
  926. #define WIFEXITED(stat) ((int)((stat)&0xFF) == 0)
  927. #endif
  928. #define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)
  929. #ifdef HAVE_GETEUID
  930. #define MY_UID() geteuid()
  931. #else
  932. #define MY_UID() getuid()
  933. #endif
  934. #ifdef HAVE_GETEGID
  935. #define MY_GID() getegid()
  936. #else
  937. #define MY_GID() getgid()
  938. #endif
  939. #ifdef FORCE_FD_ZERO_MEMSET
  940. #undef FD_ZERO
  941. #define FD_ZERO(fdsetp) memset(fdsetp, 0, sizeof (fd_set))
  942. #endif
  943. extern int verbose;
  944. #ifndef HAVE_INET_NTOP
  945. const char *inet_ntop(int af, const void *src, char *dst, size_t size);
  946. #endif
  947. #ifndef HAVE_INET_PTON
  948. int inet_pton(int af, const char *src, void *dst);
  949. #endif
  950. #ifdef MAINTAINER_MODE
  951. const char *get_panic_action(void);
  952. #endif