dpkg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * dpkg.h - general header for Debian package handling
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright (C) 2000,2001 Wichert Akkerman <wichert@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #ifndef DPKG_H
  23. #define DPKG_H
  24. #include <setjmp.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <myopt.h>
  29. #ifdef HAVE_SYS_CDEFS_H
  30. #include <sys/cdefs.h>
  31. #endif
  32. #ifdef HAVE_STDDEF_H
  33. #include <stddef.h>
  34. #endif
  35. #ifdef PATH_MAX
  36. # define INTERPRETER_MAX PATH_MAX
  37. #else
  38. # define INTERPRETER_MAX 1024
  39. #endif
  40. #define ARCHIVEVERSION "2.0"
  41. #define SPLITVERSION "2.1"
  42. #define OLDARCHIVEVERSION "0.939000"
  43. #define SPLITPARTDEFMAX (450*1024)
  44. #define MAXFIELDNAME 200
  45. #define MAXCONFFILENAME 1000
  46. #define MAXDIVERTFILENAME 1024
  47. #define MAXCONTROLFILENAME 100
  48. #define BUILDCONTROLDIR "DEBIAN"
  49. #define EXTRACTCONTROLDIR BUILDCONTROLDIR
  50. #define DEBEXT ".deb"
  51. #define OLDDBEXT "-old"
  52. #define NEWDBEXT "-new"
  53. #define OLDOLDDEBDIR ".DEBIAN"
  54. #define OLDDEBDIR "DEBIAN"
  55. #define REMOVECONFFEXTS "~", ".bak", "%", \
  56. DPKGTEMPEXT, DPKGNEWEXT, DPKGOLDEXT, DPKGDISTEXT
  57. #ifndef ARCHBINFMT
  58. #define ARCHBINFMT
  59. #endif
  60. #define DPKG_VERSION_ARCH PACKAGE_VERSION " (" ARCHITECTURE ARCHBINFMT ")"
  61. #define NEWCONFFILEFLAG "newconffile"
  62. #define NONEXISTENTFLAG "nonexistent"
  63. #define DPKGTEMPEXT ".dpkg-tmp"
  64. #define DPKGNEWEXT ".dpkg-new"
  65. #define DPKGOLDEXT ".dpkg-old"
  66. #define DPKGDISTEXT ".dpkg-dist"
  67. #define CONTROLFILE "control"
  68. #define CONFFILESFILE "conffiles"
  69. #define PREINSTFILE "preinst"
  70. #define POSTINSTFILE "postinst"
  71. #define PRERMFILE "prerm"
  72. #define POSTRMFILE "postrm"
  73. #define LISTFILE "list"
  74. #define STATUSFILE "status"
  75. #define AVAILFILE "available"
  76. #define LOCKFILE "lock"
  77. #define CMETHOPTFILE "cmethopt"
  78. #define METHLOCKFILE "methlock"
  79. #define DIVERSIONSFILE "diversions"
  80. #define STATOVERRIDEFILE "statoverride"
  81. #define UPDATESDIR "updates/"
  82. #define INFODIR "info/"
  83. #define PARTSDIR "parts/"
  84. #define CONTROLDIRTMP "tmp.ci/"
  85. #define IMPORTANTTMP "tmp.i"
  86. #define REASSEMBLETMP "reassemble" DEBEXT
  87. #define IMPORTANTMAXLEN 10
  88. #define IMPORTANTFMT "%04d" /* change => also change lib/database.c:cleanup_updates */
  89. #define MAXUPDATES 50
  90. #define LOCALLIBDIR "/usr/local/lib/dpkg"
  91. #define METHODSDIR "methods"
  92. #define NOJOBCTRLSTOPENV "DPKG_NO_TSTP"
  93. #define SHELLENV "SHELL"
  94. #define DEFAULTSHELL "sh"
  95. #define PAGERENV "PAGER"
  96. #define DEFAULTPAGER "pager"
  97. #define IMETHODMAXLEN 50
  98. #define IOPTIONMAXLEN IMETHODMAXLEN
  99. #define METHODOPTIONSFILE "names"
  100. #define METHODSETUPSCRIPT "setup"
  101. #define METHODUPDATESCRIPT "update"
  102. #define METHODINSTALLSCRIPT "install"
  103. #define OPTIONSDESCPFX "desc."
  104. #define OPTIONINDEXMAXLEN 5
  105. #define PKGSCRIPTMAXARGS 10
  106. #define MD5HASHLEN 32
  107. #define CONFFOPTCELLS /* int conffoptcells[2] {* 1= user edited *} \
  108. [2] {* 1= distributor edited *} = */ \
  109. /* dist not */ /* dist edited */ \
  110. /* user did not edit */ { cfo_keep, cfo_install }, \
  111. /* user did edit */ { cfo_keep, cfo_prompt_keep }
  112. #define ARCHIVE_FILENAME_PATTERN "*.deb"
  113. #define BACKEND "dpkg-deb"
  114. #define DPKGQUERY "dpkg-query"
  115. #define SPLITTER "dpkg-split"
  116. #define DSELECT "dselect"
  117. #define DPKG "dpkg"
  118. #define DEBSIGVERIFY "/usr/bin/debsig-verify"
  119. #define TAR "tar"
  120. #define GZIP "gzip"
  121. #define BZIP2 "bzip2"
  122. #define LZMA "lzma"
  123. #define RM "rm"
  124. #define FIND "find"
  125. #define SHELL "sh"
  126. #define DIFF "diff"
  127. #define SHELLENVIR "SHELL"
  128. #define FIND_EXPRSTARTCHARS "-(),!"
  129. #define TARBLKSZ 512
  130. extern const char thisname[]; /* defined separately in each program */
  131. extern const char printforhelp[];
  132. #if HAVE_C_ATTRIBUTE
  133. # define CONSTANT __attribute__((constant))
  134. # define PRINTFFORMAT(si, tc) __attribute__((format(printf,si,tc)))
  135. # define NONRETURNING __attribute__((noreturn))
  136. # define UNUSED __attribute__((unused))
  137. #else
  138. # define CONSTANT
  139. # define PRINTFFORMAT(si, tc)
  140. # define NONRETURNING
  141. # define UNUSED
  142. #endif
  143. /*** from startup.c ***/
  144. #define standard_startup(ejbuf, argc, argv, prog, loadcfg, cmdinfos) do {\
  145. setlocale(LC_ALL, "");\
  146. bindtextdomain(PACKAGE, LOCALEDIR);\
  147. textdomain(PACKAGE);\
  148. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  149. error_unwind(ehflag_bombout); exit(2);\
  150. }\
  151. push_error_handler(ejbuf, print_error_fatal, NULL); \
  152. umask(022); /* Make sure all our status databases are readable. */\
  153. if (loadcfg)\
  154. loadcfgfile(prog, cmdinfos);\
  155. myopt(argv,cmdinfos);\
  156. } while (0)
  157. #define standard_shutdown(freemem) do {\
  158. set_error_display(NULL, NULL); \
  159. error_unwind(ehflag_normaltidy);\
  160. if (freemem)\
  161. nffreeall();\
  162. } while (0)
  163. /*** from ehandle.c ***/
  164. void push_error_handler(jmp_buf *jbufp,
  165. void (*printerror)(const char *, const char *),
  166. const char *contextstring);
  167. void set_error_display(void (*printerror)(const char *, const char *),
  168. const char *contextstring);
  169. void print_error_fatal(const char *emsg, const char *contextstring);
  170. void error_unwind(int flagset);
  171. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  172. void (*f2)(int argc, void **argv), int flagmask2,
  173. unsigned int nargs, ...);
  174. void push_checkpoint(int mask, int value);
  175. void pop_cleanup(int flagset);
  176. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  177. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  178. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  179. struct varbuf;
  180. void ohshit(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  181. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  182. void ohshite(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  183. void ohshitvb(struct varbuf*) NONRETURNING;
  184. void badusage(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  185. void werr(const char *what) NONRETURNING;
  186. void warningf(const char *fmt, ...) PRINTFFORMAT(1, 2);
  187. /*** from mlib.c ***/
  188. void setcloexec(int fd, const char* fn);
  189. void *m_malloc(size_t);
  190. void *m_realloc(void*, size_t);
  191. int m_fork(void);
  192. void m_dup2(int oldfd, int newfd);
  193. void m_pipe(int fds[2]);
  194. #define PROCPIPE 1
  195. #define PROCWARN 2
  196. #define PROCNOERR 4
  197. int checksubprocerr(int status, const char *description, int flags);
  198. int waitsubproc(pid_t pid, const char *description, int flags);
  199. #define BUFFER_WRITE_BUF 0
  200. #define BUFFER_WRITE_VBUF 1
  201. #define BUFFER_WRITE_FD 2
  202. #define BUFFER_WRITE_NULL 3
  203. #define BUFFER_WRITE_STREAM 4
  204. #define BUFFER_WRITE_MD5 5
  205. #define BUFFER_READ_FD 0
  206. #define BUFFER_READ_STREAM 1
  207. #define BUFFER_WRITE_SETUP 1 << 16
  208. #define BUFFER_READ_SETUP 1 << 17
  209. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  210. #define BUFFER_READ_SHUTDOWN 1 << 19
  211. typedef struct buffer_data *buffer_data_t;
  212. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  213. typedef union buffer_arg {
  214. void *ptr;
  215. int i;
  216. } buffer_arg;
  217. struct buffer_data {
  218. buffer_proc_t proc;
  219. buffer_arg data;
  220. int type;
  221. };
  222. #if HAVE_C99
  223. # define fd_md5(fd, hash, limit, ...)\
  224. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  225. hash, BUFFER_WRITE_MD5, NULL, \
  226. limit, __VA_ARGS__)
  227. # define stream_md5(file, hash, limit, ...)\
  228. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  229. hash, BUFFER_WRITE_MD5, NULL, \
  230. limit, __VA_ARGS__)
  231. # define fd_fd_copy(fd1, fd2, limit, ...)\
  232. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  233. fd2, BUFFER_WRITE_FD, NULL, \
  234. limit, __VA_ARGS__)
  235. # define fd_buf_copy(fd, buf, limit, ...)\
  236. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  237. buf, BUFFER_WRITE_BUF, NULL, \
  238. limit, __VA_ARGS__)
  239. # define fd_vbuf_copy(fd, buf, limit, ...)\
  240. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  241. buf, BUFFER_WRITE_VBUF, NULL, \
  242. limit, __VA_ARGS__)
  243. # define fd_null_copy(fd, limit, ...) \
  244. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  245. if(errno != ESPIPE) ohshite(__VA_ARGS__); \
  246. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  247. NULL, BUFFER_WRITE_NULL, NULL, \
  248. limit, __VA_ARGS__);\
  249. }
  250. # define stream_null_copy(file, limit, ...) \
  251. if (fseek(file, limit, SEEK_CUR) == -1) { \
  252. if(errno != EBADF) ohshite(__VA_ARGS__); \
  253. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  254. NULL, BUFFER_WRITE_NULL, NULL, \
  255. limit, __VA_ARGS__);\
  256. }
  257. # define stream_fd_copy(file, fd, limit, ...)\
  258. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  259. fd, BUFFER_WRITE_FD, NULL, \
  260. limit, __VA_ARGS__)
  261. #else /* HAVE_C99 */
  262. # define fd_md5(fd, hash, limit, desc...)\
  263. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  264. hash, BUFFER_WRITE_MD5, NULL, \
  265. limit, desc)
  266. # define stream_md5(file, hash, limit, desc...)\
  267. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  268. hash, BUFFER_WRITE_MD5, NULL, \
  269. limit, desc)
  270. # define fd_fd_copy(fd1, fd2, limit, desc...)\
  271. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  272. fd2, BUFFER_WRITE_FD, NULL, \
  273. limit, desc)
  274. # define fd_buf_copy(fd, buf, limit, desc...)\
  275. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  276. buf, BUFFER_WRITE_BUF, NULL, \
  277. limit, desc)
  278. # define fd_vbuf_copy(fd, buf, limit, desc...)\
  279. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  280. buf, BUFFER_WRITE_VBUF, NULL, \
  281. limit, desc)
  282. # define fd_null_copy(fd, limit, desc...) \
  283. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  284. if(errno != ESPIPE) ohshite(desc); \
  285. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  286. NULL, BUFFER_WRITE_NULL, NULL, \
  287. limit, desc);\
  288. }
  289. # define stream_null_copy(file, limit, desc...) \
  290. if (fseek(file, limit, SEEK_CUR) == -1) { \
  291. if(errno != EBADF) ohshite(desc); \
  292. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  293. NULL, BUFFER_WRITE_NULL, NULL, \
  294. limit, desc);\
  295. }
  296. # define stream_fd_copy(file, fd, limit, desc...)\
  297. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  298. fd, BUFFER_WRITE_FD, NULL, \
  299. limit, desc)
  300. #endif /* HAVE_C99 */
  301. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  302. int i, int typeOut, void *procOut,
  303. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  304. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  305. void *p2, int typeOut, void *procOut,
  306. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  307. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  308. void *p, int typeOut, void *procOut,
  309. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  310. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  311. int i2, int typeOut, void *procOut,
  312. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  313. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  314. buffer_arg argOut, int typeOut, void *procOut,
  315. off_t limit, const char *desc);
  316. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  317. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  318. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  319. extern volatile int onerr_abort;
  320. /*** from showcright.c ***/
  321. struct cmdinfo;
  322. void showcopyright(const struct cmdinfo*, const char*);
  323. /*** from utils.c ***/
  324. int cisdigit(int c);
  325. int cisalpha(int c);
  326. /*** from compression.c ***/
  327. enum compress_type {
  328. compress_type_cat,
  329. compress_type_gzip,
  330. compress_type_bzip2,
  331. compress_type_lzma,
  332. };
  333. void decompress_cat(enum compress_type type, int fd_in, int fd_out,
  334. char *desc, ...) NONRETURNING PRINTFFORMAT(4, 5);
  335. void compress_cat(enum compress_type type, int fd_in, int fd_out,
  336. const char *compression, char *desc, ...)
  337. NONRETURNING PRINTFFORMAT(5, 6);
  338. /*** from compat.c ***/
  339. #ifndef HAVE_STRERROR
  340. const char *strerror(int);
  341. #endif
  342. #ifndef HAVE_STRSIGNAL
  343. const char *strsignal(int);
  344. #endif
  345. #ifndef HAVE_SCANDIR
  346. struct dirent;
  347. int scandir(const char *dir, struct dirent ***namelist,
  348. int (*select)(const struct dirent *),
  349. int (*compar)(const void*, const void*));
  350. #endif
  351. #ifndef HAVE_ALPHASORT
  352. struct dirent;
  353. int alphasort(const struct dirent *a, const struct dirent *b);
  354. #endif
  355. #ifndef HAVE_UNSETENV
  356. void unsetenv(const char *x);
  357. #endif
  358. /*** other compatibility functions ***/
  359. #ifndef HAVE_STRTOUL
  360. #define strtoul strtol
  361. #endif
  362. #ifndef HAVE_VA_COPY
  363. #define va_copy(dest, src) (dest) = (src)
  364. #endif
  365. /* Define WCOREDUMP if we don't have it already - coredumps won't be
  366. * detected, though.
  367. */
  368. #ifndef WCOREDUMP
  369. #define WCOREDUMP(x) 0
  370. #endif
  371. /* Set BUILDOLDPKGFORMAT to 1 to build old-format archives by default.
  372. * */
  373. #ifndef BUILDOLDPKGFORMAT
  374. #define BUILDOLDPKGFORMAT 0
  375. #endif
  376. /* Take care of NLS matters. */
  377. #include <gettext.h>
  378. #if HAVE_LOCALE_H
  379. # include <locale.h>
  380. #endif
  381. /* Make gettext a little friendlier */
  382. #define _(String) gettext (String)
  383. #define N_(String) gettext_noop (String)
  384. #endif /* DPKG_H */