dpkg.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. #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. #define DPKG_VERSION_ARCH PACKAGE_VERSION " (" ARCHITECTURE ")"
  59. #define NEWCONFFILEFLAG "newconffile"
  60. #define NONEXISTENTFLAG "nonexistent"
  61. #define DPKGTEMPEXT ".dpkg-tmp"
  62. #define DPKGNEWEXT ".dpkg-new"
  63. #define DPKGOLDEXT ".dpkg-old"
  64. #define DPKGDISTEXT ".dpkg-dist"
  65. #define CONTROLFILE "control"
  66. #define CONFFILESFILE "conffiles"
  67. #define PREINSTFILE "preinst"
  68. #define POSTINSTFILE "postinst"
  69. #define PRERMFILE "prerm"
  70. #define POSTRMFILE "postrm"
  71. #define LISTFILE "list"
  72. #define TRIGGERSCIFILE "triggers"
  73. #define STATUSFILE "status"
  74. #define AVAILFILE "available"
  75. #define LOCKFILE "lock"
  76. #define DIVERSIONSFILE "diversions"
  77. #define STATOVERRIDEFILE "statoverride"
  78. #define UPDATESDIR "updates/"
  79. #define INFODIR "info/"
  80. #define PARTSDIR "parts/"
  81. #define TRIGGERSDIR "triggers/"
  82. #define TRIGGERSFILEFILE "File"
  83. #define TRIGGERSDEFERREDFILE "Unincorp"
  84. #define TRIGGERSLOCKFILE "Lock"
  85. #define CONTROLDIRTMP "tmp.ci/"
  86. #define IMPORTANTTMP "tmp.i"
  87. #define REASSEMBLETMP "reassemble" DEBEXT
  88. #define IMPORTANTMAXLEN 10
  89. #define IMPORTANTFMT "%04d"
  90. #define MAXUPDATES 250
  91. #define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
  92. #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
  93. #define LOCALLIBDIR "/usr/local/lib/dpkg"
  94. #define NOJOBCTRLSTOPENV "DPKG_NO_TSTP"
  95. #define SHELLENV "SHELL"
  96. #define DEFAULTSHELL "sh"
  97. #define PAGERENV "PAGER"
  98. #define DEFAULTPAGER "pager"
  99. #define PKGSCRIPTMAXARGS 10
  100. #define MD5HASHLEN 32
  101. #define MAXTRIGDIRECTIVE 256
  102. #define CONFFOPTCELLS /* int conffoptcells[2] {* 1= user edited *} \
  103. [2] {* 1= distributor edited *} = */ \
  104. /* dist not */ /* dist edited */ \
  105. /* user did not edit */ { cfo_keep, cfo_install }, \
  106. /* user did edit */ { cfo_keep, cfo_prompt_keep }
  107. #define ARCHIVE_FILENAME_PATTERN "*.deb"
  108. #define BACKEND "dpkg-deb"
  109. #define DPKGQUERY "dpkg-query"
  110. #define SPLITTER "dpkg-split"
  111. #define DSELECT "dselect"
  112. #define DPKG "dpkg"
  113. #define DEBSIGVERIFY "/usr/bin/debsig-verify"
  114. #define TAR "tar"
  115. #define GZIP "gzip"
  116. #define BZIP2 "bzip2"
  117. #define LZMA "lzma"
  118. #define RM "rm"
  119. #define FIND "find"
  120. #define SHELL "sh"
  121. #define DIFF "diff"
  122. #define SHELLENVIR "SHELL"
  123. #define FIND_EXPRSTARTCHARS "-(),!"
  124. #define TARBLKSZ 512
  125. extern const char thisname[]; /* defined separately in each program */
  126. extern const char printforhelp[];
  127. /*** from startup.c ***/
  128. #define standard_startup(ejbuf) do {\
  129. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  130. error_unwind(ehflag_bombout); exit(2);\
  131. }\
  132. push_error_handler(ejbuf, print_error_fatal, NULL); \
  133. umask(022); /* Make sure all our status databases are readable. */\
  134. } while (0)
  135. #define standard_shutdown() do { \
  136. set_error_display(NULL, NULL); \
  137. error_unwind(ehflag_normaltidy);\
  138. } while (0)
  139. /*** from ehandle.c ***/
  140. extern volatile int onerr_abort;
  141. typedef void error_printer(const char *emsg, const char *contextstring);
  142. void push_error_handler(jmp_buf *jbufp, error_printer *printerror,
  143. const char *contextstring);
  144. void set_error_display(error_printer *printerror, const char *contextstring);
  145. void print_error_fatal(const char *emsg, const char *contextstring);
  146. void error_unwind(int flagset);
  147. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  148. void (*f2)(int argc, void **argv), int flagmask2,
  149. unsigned int nargs, ...);
  150. void push_checkpoint(int mask, int value);
  151. void pop_cleanup(int flagset);
  152. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  153. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  154. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  155. struct varbuf;
  156. void ohshit(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  157. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  158. void ohshite(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  159. void ohshitvb(struct varbuf*) NONRETURNING;
  160. void badusage(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  161. void werr(const char *what) NONRETURNING;
  162. void warning(const char *fmt, ...) PRINTFFORMAT(1, 2);
  163. /*** log.c ***/
  164. extern const char *log_file;
  165. void log_message(const char *fmt, ...) PRINTFFORMAT(1, 2);
  166. /* FIXME: pipef and status_pipes should not be publicly exposed. */
  167. struct pipef {
  168. int fd;
  169. struct pipef *next;
  170. };
  171. extern struct pipef *status_pipes;
  172. void statusfd_send(const char *fmt, ...);
  173. /*** cleanup.c ***/
  174. void cu_closefile(int argc, void **argv);
  175. void cu_closepipe(int argc, void **argv);
  176. void cu_closedir(int argc, void **argv);
  177. void cu_closefd(int argc, void **argv);
  178. /*** lock.c ***/
  179. void lock_file(int *lockfd, const char *filename,
  180. const char *emsg, const char *emsg_eagain);
  181. void unlock_file(void);
  182. /*** from mlib.c ***/
  183. void setcloexec(int fd, const char* fn);
  184. void *m_malloc(size_t);
  185. void *m_realloc(void*, size_t);
  186. char *m_strdup(const char *str);
  187. int m_fork(void);
  188. void m_dup2(int oldfd, int newfd);
  189. void m_pipe(int fds[2]);
  190. #define PROCPIPE 1
  191. #define PROCWARN 2
  192. #define PROCNOERR 4
  193. int checksubprocerr(int status, const char *description, int flags);
  194. int waitsubproc(pid_t pid, const char *description, int flags);
  195. #define BUFFER_WRITE_BUF 0
  196. #define BUFFER_WRITE_VBUF 1
  197. #define BUFFER_WRITE_FD 2
  198. #define BUFFER_WRITE_NULL 3
  199. #define BUFFER_WRITE_STREAM 4
  200. #define BUFFER_WRITE_MD5 5
  201. #define BUFFER_READ_FD 0
  202. #define BUFFER_READ_STREAM 1
  203. #define BUFFER_WRITE_SETUP 1 << 16
  204. #define BUFFER_READ_SETUP 1 << 17
  205. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  206. #define BUFFER_READ_SHUTDOWN 1 << 19
  207. typedef struct buffer_data *buffer_data_t;
  208. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  209. typedef union buffer_arg {
  210. void *ptr;
  211. int i;
  212. } buffer_arg;
  213. struct buffer_data {
  214. buffer_proc_t proc;
  215. buffer_arg data;
  216. int type;
  217. };
  218. #if HAVE_C99
  219. # define fd_md5(fd, hash, limit, ...)\
  220. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  221. hash, BUFFER_WRITE_MD5, NULL, \
  222. limit, __VA_ARGS__)
  223. # define stream_md5(file, hash, limit, ...)\
  224. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  225. hash, BUFFER_WRITE_MD5, NULL, \
  226. limit, __VA_ARGS__)
  227. # define fd_fd_copy(fd1, fd2, limit, ...)\
  228. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  229. fd2, BUFFER_WRITE_FD, NULL, \
  230. limit, __VA_ARGS__)
  231. # define fd_buf_copy(fd, buf, limit, ...)\
  232. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  233. buf, BUFFER_WRITE_BUF, NULL, \
  234. limit, __VA_ARGS__)
  235. # define fd_vbuf_copy(fd, buf, limit, ...)\
  236. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  237. buf, BUFFER_WRITE_VBUF, NULL, \
  238. limit, __VA_ARGS__)
  239. # define fd_null_copy(fd, limit, ...) \
  240. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  241. if(errno != ESPIPE) ohshite(__VA_ARGS__); \
  242. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  243. NULL, BUFFER_WRITE_NULL, NULL, \
  244. limit, __VA_ARGS__);\
  245. }
  246. # define stream_null_copy(file, limit, ...) \
  247. if (fseek(file, limit, SEEK_CUR) == -1) { \
  248. if(errno != EBADF) ohshite(__VA_ARGS__); \
  249. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  250. NULL, BUFFER_WRITE_NULL, NULL, \
  251. limit, __VA_ARGS__);\
  252. }
  253. # define stream_fd_copy(file, fd, limit, ...)\
  254. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  255. fd, BUFFER_WRITE_FD, NULL, \
  256. limit, __VA_ARGS__)
  257. #else /* HAVE_C99 */
  258. # define fd_md5(fd, hash, limit, desc...)\
  259. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  260. hash, BUFFER_WRITE_MD5, NULL, \
  261. limit, desc)
  262. # define stream_md5(file, hash, limit, desc...)\
  263. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  264. hash, BUFFER_WRITE_MD5, NULL, \
  265. limit, desc)
  266. # define fd_fd_copy(fd1, fd2, limit, desc...)\
  267. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  268. fd2, BUFFER_WRITE_FD, NULL, \
  269. limit, desc)
  270. # define fd_buf_copy(fd, buf, limit, desc...)\
  271. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  272. buf, BUFFER_WRITE_BUF, NULL, \
  273. limit, desc)
  274. # define fd_vbuf_copy(fd, buf, limit, desc...)\
  275. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  276. buf, BUFFER_WRITE_VBUF, NULL, \
  277. limit, desc)
  278. # define fd_null_copy(fd, limit, desc...) \
  279. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  280. if(errno != ESPIPE) ohshite(desc); \
  281. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  282. NULL, BUFFER_WRITE_NULL, NULL, \
  283. limit, desc);\
  284. }
  285. # define stream_null_copy(file, limit, desc...) \
  286. if (fseek(file, limit, SEEK_CUR) == -1) { \
  287. if(errno != EBADF) ohshite(desc); \
  288. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  289. NULL, BUFFER_WRITE_NULL, NULL, \
  290. limit, desc);\
  291. }
  292. # define stream_fd_copy(file, fd, limit, desc...)\
  293. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  294. fd, BUFFER_WRITE_FD, NULL, \
  295. limit, desc)
  296. #endif /* HAVE_C99 */
  297. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  298. int i, int typeOut, void *procOut,
  299. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  300. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  301. void *p2, int typeOut, void *procOut,
  302. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  303. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  304. void *p, int typeOut, void *procOut,
  305. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  306. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  307. int i2, int typeOut, void *procOut,
  308. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  309. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  310. buffer_arg argOut, int typeOut, void *procOut,
  311. off_t limit, const char *desc);
  312. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  313. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  314. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  315. /*** from utils.c ***/
  316. int cisdigit(int c);
  317. int cisalpha(int c);
  318. int cisspace(int c);
  319. int fgets_checked(char *buf, size_t bufsz, FILE *f, const char *fn);
  320. int fgets_must(char *buf, size_t bufsz, FILE *f, const char *fn);
  321. /*** from compression.c ***/
  322. enum compress_type {
  323. compress_type_cat,
  324. compress_type_gzip,
  325. compress_type_bzip2,
  326. compress_type_lzma,
  327. };
  328. void decompress_cat(enum compress_type type, int fd_in, int fd_out,
  329. char *desc, ...) NONRETURNING PRINTFFORMAT(4, 5);
  330. void compress_cat(enum compress_type type, int fd_in, int fd_out,
  331. const char *compression, char *desc, ...)
  332. NONRETURNING PRINTFFORMAT(5, 6);
  333. /* Set BUILDOLDPKGFORMAT to 1 to build old-format archives by default.
  334. * */
  335. #ifndef BUILDOLDPKGFORMAT
  336. #define BUILDOLDPKGFORMAT 0
  337. #endif
  338. DPKG_END_DECLS
  339. #endif /* DPKG_H */