dpkg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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/macros.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 MAINTSCRIPTARCHENVVAR "DPKG_MAINTSCRIPT_ARCH"
  79. #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
  80. #define NOJOBCTRLSTOPENV "DPKG_NO_TSTP"
  81. #define SHELLENV "SHELL"
  82. #define DEFAULTSHELL "sh"
  83. #define PAGERENV "PAGER"
  84. #define DEFAULTPAGER "pager"
  85. #define PKGSCRIPTMAXARGS 10
  86. #define MD5HASHLEN 32
  87. #define MAXTRIGDIRECTIVE 256
  88. #define ARCHIVE_FILENAME_PATTERN "*.deb"
  89. #define BACKEND "dpkg-deb"
  90. #define DPKGQUERY "dpkg-query"
  91. #define SPLITTER "dpkg-split"
  92. #define DPKG "dpkg"
  93. #define DEBSIGVERIFY "/usr/bin/debsig-verify"
  94. #define TAR "tar"
  95. #define GZIP "gzip"
  96. #define BZIP2 "bzip2"
  97. #define LZMA "lzma"
  98. #define RM "rm"
  99. #define FIND "find"
  100. #define DIFF "diff"
  101. #define FIND_EXPRSTARTCHARS "-(),!"
  102. #define TARBLKSZ 512
  103. extern const char thisname[]; /* defined separately in each program */
  104. /*** from startup.c ***/
  105. #define standard_startup(ejbuf) do {\
  106. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  107. error_unwind(ehflag_bombout); exit(2);\
  108. }\
  109. push_error_handler(ejbuf, print_error_fatal, NULL); \
  110. umask(022); /* Make sure all our status databases are readable. */\
  111. } while (0)
  112. #define standard_shutdown() do { \
  113. set_error_display(NULL, NULL); \
  114. error_unwind(ehflag_normaltidy);\
  115. } while (0)
  116. /*** from ehandle.c ***/
  117. extern volatile int onerr_abort;
  118. typedef void error_printer(const char *emsg, const char *contextstring);
  119. void push_error_handler(jmp_buf *jbufp, error_printer *printerror,
  120. const char *contextstring);
  121. void set_error_display(error_printer *printerror, const char *contextstring);
  122. void print_error_fatal(const char *emsg, const char *contextstring);
  123. void error_unwind(int flagset);
  124. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  125. void (*f2)(int argc, void **argv), int flagmask2,
  126. unsigned int nargs, ...);
  127. void push_checkpoint(int mask, int value);
  128. void pop_cleanup(int flagset);
  129. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  130. void do_internerr(const char *file, int line, const char *fmt, ...) DPKG_ATTR_NORET;
  131. #if HAVE_C99
  132. #define internerr(...) do_internerr(__FILE__, __LINE__, __VA_ARGS__)
  133. #else
  134. #define internerr(args...) do_internerr(__FILE__, __LINE__, args)
  135. #endif
  136. void ohshit(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1);
  137. void ohshitv(const char *fmt, va_list al) DPKG_ATTR_NORET;
  138. void ohshite(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1);
  139. void werr(const char *what) DPKG_ATTR_NORET;
  140. void warning(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
  141. /*** log.c ***/
  142. extern const char *log_file;
  143. void log_message(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
  144. /* FIXME: pipef and status_pipes should not be publicly exposed. */
  145. struct pipef {
  146. int fd;
  147. struct pipef *next;
  148. };
  149. extern struct pipef *status_pipes;
  150. void statusfd_send(const char *fmt, ...);
  151. /*** cleanup.c ***/
  152. void cu_closefile(int argc, void **argv);
  153. void cu_closepipe(int argc, void **argv);
  154. void cu_closedir(int argc, void **argv);
  155. void cu_closefd(int argc, void **argv);
  156. /*** lock.c ***/
  157. void lock_file(int *lockfd, const char *filename,
  158. const char *emsg, const char *emsg_eagain);
  159. void unlock_file(void);
  160. /*** from mlib.c ***/
  161. void setcloexec(int fd, const char* fn);
  162. void *m_malloc(size_t);
  163. void *m_realloc(void*, size_t);
  164. char *m_strdup(const char *str);
  165. int m_fork(void);
  166. void m_dup2(int oldfd, int newfd);
  167. void m_pipe(int fds[2]);
  168. #define BUFFER_WRITE_BUF 0
  169. #define BUFFER_WRITE_VBUF 1
  170. #define BUFFER_WRITE_FD 2
  171. #define BUFFER_WRITE_NULL 3
  172. #define BUFFER_WRITE_STREAM 4
  173. #define BUFFER_WRITE_MD5 5
  174. #define BUFFER_READ_FD 0
  175. #define BUFFER_READ_STREAM 1
  176. #define BUFFER_WRITE_SETUP 1 << 16
  177. #define BUFFER_READ_SETUP 1 << 17
  178. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  179. #define BUFFER_READ_SHUTDOWN 1 << 19
  180. typedef struct buffer_data *buffer_data_t;
  181. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  182. typedef union buffer_arg {
  183. void *ptr;
  184. int i;
  185. } buffer_arg;
  186. struct buffer_data {
  187. buffer_proc_t proc;
  188. buffer_arg data;
  189. int type;
  190. };
  191. #if HAVE_C99
  192. # define fd_md5(fd, hash, limit, ...)\
  193. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  194. hash, BUFFER_WRITE_MD5, NULL, \
  195. limit, __VA_ARGS__)
  196. # define stream_md5(file, hash, limit, ...)\
  197. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  198. hash, BUFFER_WRITE_MD5, NULL, \
  199. limit, __VA_ARGS__)
  200. # define fd_fd_copy(fd1, fd2, limit, ...)\
  201. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  202. fd2, BUFFER_WRITE_FD, NULL, \
  203. limit, __VA_ARGS__)
  204. # define fd_buf_copy(fd, buf, limit, ...)\
  205. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  206. buf, BUFFER_WRITE_BUF, NULL, \
  207. limit, __VA_ARGS__)
  208. # define fd_vbuf_copy(fd, buf, limit, ...)\
  209. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  210. buf, BUFFER_WRITE_VBUF, NULL, \
  211. limit, __VA_ARGS__)
  212. # define fd_null_copy(fd, limit, ...) \
  213. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  214. if(errno != ESPIPE) ohshite(__VA_ARGS__); \
  215. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  216. NULL, BUFFER_WRITE_NULL, NULL, \
  217. limit, __VA_ARGS__);\
  218. }
  219. # define stream_null_copy(file, limit, ...) \
  220. if (fseek(file, limit, SEEK_CUR) == -1) { \
  221. if(errno != EBADF) ohshite(__VA_ARGS__); \
  222. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  223. NULL, BUFFER_WRITE_NULL, NULL, \
  224. limit, __VA_ARGS__);\
  225. }
  226. # define stream_fd_copy(file, fd, limit, ...)\
  227. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  228. fd, BUFFER_WRITE_FD, NULL, \
  229. limit, __VA_ARGS__)
  230. #else /* HAVE_C99 */
  231. # define fd_md5(fd, hash, limit, desc...)\
  232. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  233. hash, BUFFER_WRITE_MD5, NULL, \
  234. limit, desc)
  235. # define stream_md5(file, hash, limit, desc...)\
  236. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  237. hash, BUFFER_WRITE_MD5, NULL, \
  238. limit, desc)
  239. # define fd_fd_copy(fd1, fd2, limit, desc...)\
  240. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  241. fd2, BUFFER_WRITE_FD, NULL, \
  242. limit, desc)
  243. # define fd_buf_copy(fd, buf, limit, desc...)\
  244. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  245. buf, BUFFER_WRITE_BUF, NULL, \
  246. limit, desc)
  247. # define fd_vbuf_copy(fd, buf, limit, desc...)\
  248. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  249. buf, BUFFER_WRITE_VBUF, NULL, \
  250. limit, desc)
  251. # define fd_null_copy(fd, limit, desc...) \
  252. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  253. if(errno != ESPIPE) ohshite(desc); \
  254. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  255. NULL, BUFFER_WRITE_NULL, NULL, \
  256. limit, desc);\
  257. }
  258. # define stream_null_copy(file, limit, desc...) \
  259. if (fseek(file, limit, SEEK_CUR) == -1) { \
  260. if(errno != EBADF) ohshite(desc); \
  261. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  262. NULL, BUFFER_WRITE_NULL, NULL, \
  263. limit, desc);\
  264. }
  265. # define stream_fd_copy(file, fd, limit, desc...)\
  266. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  267. fd, BUFFER_WRITE_FD, NULL, \
  268. limit, desc)
  269. #endif /* HAVE_C99 */
  270. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  271. int i, int typeOut, void *procOut,
  272. off_t limit, const char *desc, ...) DPKG_ATTR_PRINTF(8);
  273. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  274. void *p2, int typeOut, void *procOut,
  275. off_t limit, const char *desc, ...) DPKG_ATTR_PRINTF(8);
  276. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  277. void *p, int typeOut, void *procOut,
  278. off_t limit, const char *desc, ...) DPKG_ATTR_PRINTF(8);
  279. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  280. int i2, int typeOut, void *procOut,
  281. off_t limit, const char *desc, ...) DPKG_ATTR_PRINTF(8);
  282. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  283. buffer_arg argOut, int typeOut, void *procOut,
  284. off_t limit, const char *desc);
  285. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  286. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  287. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  288. /*** from utils.c ***/
  289. int cisdigit(int c);
  290. int cisalpha(int c);
  291. int cisspace(int c);
  292. int fgets_checked(char *buf, size_t bufsz, FILE *f, const char *fn);
  293. int fgets_must(char *buf, size_t bufsz, FILE *f, const char *fn);
  294. /*** from compression.c ***/
  295. enum compress_type {
  296. compress_type_cat,
  297. compress_type_gzip,
  298. compress_type_bzip2,
  299. compress_type_lzma,
  300. };
  301. void decompress_cat(enum compress_type type, int fd_in, int fd_out,
  302. char *desc, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(4);
  303. void compress_cat(enum compress_type type, int fd_in, int fd_out,
  304. const char *compression, char *desc, ...)
  305. DPKG_ATTR_NORET DPKG_ATTR_PRINTF(5);
  306. DPKG_END_DECLS
  307. #endif /* DPKG_H */