dpkg.h 15 KB

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