dpkg.h 14 KB

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