dpkg.h 12 KB

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