dpkg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. typedef void error_printer(const char *emsg, const char *contextstring);
  155. void push_error_handler(jmp_buf *jbufp, error_printer *printerror,
  156. const char *contextstring);
  157. void set_error_display(error_printer *printerror, const char *contextstring);
  158. void print_error_fatal(const char *emsg, const char *contextstring);
  159. void error_unwind(int flagset);
  160. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  161. void (*f2)(int argc, void **argv), int flagmask2,
  162. unsigned int nargs, ...);
  163. void push_checkpoint(int mask, int value);
  164. void pop_cleanup(int flagset);
  165. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  166. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  167. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  168. struct varbuf;
  169. void ohshit(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  170. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  171. void ohshite(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  172. void ohshitvb(struct varbuf*) NONRETURNING;
  173. void badusage(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  174. void werr(const char *what) NONRETURNING;
  175. void warningf(const char *fmt, ...) PRINTFFORMAT(1, 2);
  176. /*** log.c ***/
  177. extern const char *log_file;
  178. void log_message(const char *fmt, ...) PRINTFFORMAT(1, 2);
  179. /* FIXME: pipef and status_pipes should not be publicly exposed. */
  180. struct pipef {
  181. int fd;
  182. struct pipef *next;
  183. };
  184. extern struct pipef *status_pipes;
  185. void statusfd_send(const char *fmt, ...);
  186. /*** cleanup.c ***/
  187. void cu_closefile(int argc, void **argv);
  188. void cu_closepipe(int argc, void **argv);
  189. void cu_closedir(int argc, void **argv);
  190. void cu_closefd(int argc, void **argv);
  191. /*** lock.c ***/
  192. void lock_file(int *lockfd, const char *filename,
  193. const char *emsg, const char *emsg_eagain);
  194. void unlock_file(void);
  195. /*** from mlib.c ***/
  196. void setcloexec(int fd, const char* fn);
  197. void *m_malloc(size_t);
  198. void *m_realloc(void*, size_t);
  199. char *m_strdup(const char *str);
  200. int m_fork(void);
  201. void m_dup2(int oldfd, int newfd);
  202. void m_pipe(int fds[2]);
  203. #define PROCPIPE 1
  204. #define PROCWARN 2
  205. #define PROCNOERR 4
  206. int checksubprocerr(int status, const char *description, int flags);
  207. int waitsubproc(pid_t pid, const char *description, int flags);
  208. #define BUFFER_WRITE_BUF 0
  209. #define BUFFER_WRITE_VBUF 1
  210. #define BUFFER_WRITE_FD 2
  211. #define BUFFER_WRITE_NULL 3
  212. #define BUFFER_WRITE_STREAM 4
  213. #define BUFFER_WRITE_MD5 5
  214. #define BUFFER_READ_FD 0
  215. #define BUFFER_READ_STREAM 1
  216. #define BUFFER_WRITE_SETUP 1 << 16
  217. #define BUFFER_READ_SETUP 1 << 17
  218. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  219. #define BUFFER_READ_SHUTDOWN 1 << 19
  220. typedef struct buffer_data *buffer_data_t;
  221. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  222. typedef union buffer_arg {
  223. void *ptr;
  224. int i;
  225. } buffer_arg;
  226. struct buffer_data {
  227. buffer_proc_t proc;
  228. buffer_arg data;
  229. int type;
  230. };
  231. #if HAVE_C99
  232. # define fd_md5(fd, hash, limit, ...)\
  233. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  234. hash, BUFFER_WRITE_MD5, NULL, \
  235. limit, __VA_ARGS__)
  236. # define stream_md5(file, hash, limit, ...)\
  237. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  238. hash, BUFFER_WRITE_MD5, NULL, \
  239. limit, __VA_ARGS__)
  240. # define fd_fd_copy(fd1, fd2, limit, ...)\
  241. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  242. fd2, BUFFER_WRITE_FD, NULL, \
  243. limit, __VA_ARGS__)
  244. # define fd_buf_copy(fd, buf, limit, ...)\
  245. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  246. buf, BUFFER_WRITE_BUF, NULL, \
  247. limit, __VA_ARGS__)
  248. # define fd_vbuf_copy(fd, buf, limit, ...)\
  249. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  250. buf, BUFFER_WRITE_VBUF, NULL, \
  251. limit, __VA_ARGS__)
  252. # define fd_null_copy(fd, limit, ...) \
  253. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  254. if(errno != ESPIPE) ohshite(__VA_ARGS__); \
  255. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  256. NULL, BUFFER_WRITE_NULL, NULL, \
  257. limit, __VA_ARGS__);\
  258. }
  259. # define stream_null_copy(file, limit, ...) \
  260. if (fseek(file, limit, SEEK_CUR) == -1) { \
  261. if(errno != EBADF) ohshite(__VA_ARGS__); \
  262. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  263. NULL, BUFFER_WRITE_NULL, NULL, \
  264. limit, __VA_ARGS__);\
  265. }
  266. # define stream_fd_copy(file, fd, limit, ...)\
  267. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  268. fd, BUFFER_WRITE_FD, NULL, \
  269. limit, __VA_ARGS__)
  270. #else /* HAVE_C99 */
  271. # define fd_md5(fd, hash, limit, desc...)\
  272. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  273. hash, BUFFER_WRITE_MD5, NULL, \
  274. limit, desc)
  275. # define stream_md5(file, hash, limit, desc...)\
  276. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  277. hash, BUFFER_WRITE_MD5, NULL, \
  278. limit, desc)
  279. # define fd_fd_copy(fd1, fd2, limit, desc...)\
  280. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  281. fd2, BUFFER_WRITE_FD, NULL, \
  282. limit, desc)
  283. # define fd_buf_copy(fd, buf, limit, desc...)\
  284. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  285. buf, BUFFER_WRITE_BUF, NULL, \
  286. limit, desc)
  287. # define fd_vbuf_copy(fd, buf, limit, desc...)\
  288. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  289. buf, BUFFER_WRITE_VBUF, NULL, \
  290. limit, desc)
  291. # define fd_null_copy(fd, limit, desc...) \
  292. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  293. if(errno != ESPIPE) ohshite(desc); \
  294. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  295. NULL, BUFFER_WRITE_NULL, NULL, \
  296. limit, desc);\
  297. }
  298. # define stream_null_copy(file, limit, desc...) \
  299. if (fseek(file, limit, SEEK_CUR) == -1) { \
  300. if(errno != EBADF) ohshite(desc); \
  301. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  302. NULL, BUFFER_WRITE_NULL, NULL, \
  303. limit, desc);\
  304. }
  305. # define stream_fd_copy(file, fd, limit, desc...)\
  306. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  307. fd, BUFFER_WRITE_FD, NULL, \
  308. limit, desc)
  309. #endif /* HAVE_C99 */
  310. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  311. int i, int typeOut, void *procOut,
  312. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  313. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  314. void *p2, int typeOut, void *procOut,
  315. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  316. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  317. void *p, int typeOut, void *procOut,
  318. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  319. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  320. int i2, int typeOut, void *procOut,
  321. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  322. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  323. buffer_arg argOut, int typeOut, void *procOut,
  324. off_t limit, const char *desc);
  325. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  326. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  327. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  328. extern volatile int onerr_abort;
  329. /*** from utils.c ***/
  330. int cisdigit(int c);
  331. int cisalpha(int c);
  332. int cisspace(int c);
  333. int fgets_checked(char *buf, size_t bufsz, FILE *f, const char *fn);
  334. int fgets_must(char *buf, size_t bufsz, FILE *f, const char *fn);
  335. /*** from compression.c ***/
  336. enum compress_type {
  337. compress_type_cat,
  338. compress_type_gzip,
  339. compress_type_bzip2,
  340. compress_type_lzma,
  341. };
  342. void decompress_cat(enum compress_type type, int fd_in, int fd_out,
  343. char *desc, ...) NONRETURNING PRINTFFORMAT(4, 5);
  344. void compress_cat(enum compress_type type, int fd_in, int fd_out,
  345. const char *compression, char *desc, ...)
  346. NONRETURNING PRINTFFORMAT(5, 6);
  347. /*** from compat.c ***/
  348. #ifndef HAVE_STRERROR
  349. const char *strerror(int);
  350. #endif
  351. #ifndef HAVE_STRSIGNAL
  352. const char *strsignal(int);
  353. #endif
  354. #ifndef HAVE_SCANDIR
  355. struct dirent;
  356. int scandir(const char *dir, struct dirent ***namelist,
  357. int (*select)(const struct dirent *),
  358. int (*compar)(const void*, const void*));
  359. #endif
  360. #ifndef HAVE_ALPHASORT
  361. struct dirent;
  362. int alphasort(const struct dirent *a, const struct dirent *b);
  363. #endif
  364. #ifndef HAVE_UNSETENV
  365. void unsetenv(const char *x);
  366. #endif
  367. /*** other compatibility functions ***/
  368. #ifndef offsetof
  369. #define offsetof(st, m) ((size_t)&((st *)NULL)->m)
  370. #endif
  371. #ifndef HAVE_STRTOUL
  372. #define strtoul strtol
  373. #endif
  374. #ifndef HAVE_VA_COPY
  375. #define va_copy(dest, src) (dest) = (src)
  376. #endif
  377. /* Define WCOREDUMP if we don't have it already - coredumps won't be
  378. * detected, though.
  379. */
  380. #ifndef WCOREDUMP
  381. #define WCOREDUMP(x) 0
  382. #endif
  383. /* Set BUILDOLDPKGFORMAT to 1 to build old-format archives by default.
  384. * */
  385. #ifndef BUILDOLDPKGFORMAT
  386. #define BUILDOLDPKGFORMAT 0
  387. #endif
  388. /* Take care of NLS matters. */
  389. #include <gettext.h>
  390. #if HAVE_LOCALE_H
  391. # include <locale.h>
  392. #endif
  393. /* Make gettext a little friendlier */
  394. #define _(String) gettext (String)
  395. #define N_(String) gettext_noop (String)
  396. #endif /* DPKG_H */