dpkg.h 14 KB

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