main.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * dpkg - main program for package management
  3. * main.h - external definitions for this program
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2006, 2008-2015 Guillem Jover <guillem@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 published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but 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 License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef MAIN_H
  22. #define MAIN_H
  23. #include <dpkg/debug.h>
  24. #include <dpkg/pkg-list.h>
  25. /* These two are defined in filesdb.h. */
  26. struct fileinlist;
  27. struct filenamenode_queue;
  28. struct filenamenode;
  29. enum pkg_istobe {
  30. /** Package is to be left in a normal state. */
  31. PKG_ISTOBE_NORMAL,
  32. /** Package is to be removed. */
  33. PKG_ISTOBE_REMOVE,
  34. /** Package is to be installed, configured or triggered. */
  35. PKG_ISTOBE_INSTALLNEW,
  36. /** Package is to be deconfigured. */
  37. PKG_ISTOBE_DECONFIGURE,
  38. /** Package is to be checked for Pre-Depends satisfiability. */
  39. PKG_ISTOBE_PREINSTALL,
  40. };
  41. enum pkg_cycle_color {
  42. PKG_CYCLE_WHITE,
  43. PKG_CYCLE_GRAY,
  44. PKG_CYCLE_BLACK,
  45. };
  46. struct perpackagestate {
  47. enum pkg_istobe istobe;
  48. /** Used during cycle detection. */
  49. enum pkg_cycle_color color;
  50. bool enqueued;
  51. /**
  52. * filelistvalid files Meaning
  53. * ------------- ----- -------
  54. * false NULL Not read yet, must do so if want them.
  55. * false !NULL Read, but rewritten and now out of date. If want
  56. * info must throw away old and reread file.
  57. * true !NULL Read, all is OK.
  58. * true NULL Read OK, but, there were no files.
  59. */
  60. bool fileslistvalid;
  61. struct fileinlist *files;
  62. int replacingfilesandsaid;
  63. int cmdline_seen;
  64. off_t listfile_phys_offs;
  65. /** Non-NULL iff in trigproc.c:deferred. */
  66. struct pkg_list *trigprocdeferred;
  67. };
  68. enum action {
  69. act_unset,
  70. act_unpack,
  71. act_configure,
  72. act_install,
  73. act_triggers,
  74. act_remove,
  75. act_purge,
  76. act_verify,
  77. act_commandfd,
  78. act_status,
  79. act_listpackages,
  80. act_listfiles,
  81. act_searchfiles,
  82. act_controlpath,
  83. act_controllist,
  84. act_controlshow,
  85. act_cmpversions,
  86. act_arch_add,
  87. act_arch_remove,
  88. act_printarch,
  89. act_printinstarch,
  90. act_printforeignarches,
  91. act_assertpredep,
  92. act_assertepoch,
  93. act_assertlongfilenames,
  94. act_assertmulticonrep,
  95. act_assertmultiarch,
  96. act_assertverprovides,
  97. act_audit,
  98. act_unpackchk,
  99. act_predeppackage,
  100. act_getselections,
  101. act_setselections,
  102. act_clearselections,
  103. act_avail,
  104. act_printavail,
  105. act_avclear,
  106. act_avreplace,
  107. act_avmerge,
  108. act_forgetold,
  109. };
  110. extern const char *const statusstrings[];
  111. extern int f_pending, f_recursive, f_alsoselect, f_skipsame, f_noact;
  112. extern int f_autodeconf, f_nodebsig;
  113. extern int f_triggers;
  114. extern int fc_downgrade, fc_configureany, fc_hold, fc_removereinstreq, fc_overwrite;
  115. extern int fc_removeessential, fc_conflicts, fc_depends, fc_dependsversion;
  116. extern int fc_breaks, fc_badpath, fc_overwritediverted, fc_architecture;
  117. extern int fc_nonroot, fc_overwritedir, fc_conff_new, fc_conff_miss;
  118. extern int fc_conff_old, fc_conff_def;
  119. extern int fc_conff_ask;
  120. extern int fc_badverify;
  121. extern int fc_badversion;
  122. extern int fc_unsafe_io;
  123. extern bool abort_processing;
  124. extern int errabort;
  125. extern const char *instdir;
  126. extern struct pkg_list *ignoredependss;
  127. struct invoke_hook {
  128. struct invoke_hook *next;
  129. const char *command;
  130. };
  131. /* from archives.c */
  132. int archivefiles(const char *const *argv);
  133. void process_archive(const char *filename);
  134. bool wanttoinstall(struct pkginfo *pkg);
  135. struct fileinlist *
  136. filenamenode_queue_push(struct filenamenode_queue *queue,
  137. struct filenamenode *namenode);
  138. /* from update.c */
  139. int forgetold(const char *const *argv);
  140. int updateavailable(const char *const *argv);
  141. /* from enquiry.c */
  142. int audit(const char *const *argv);
  143. int unpackchk(const char *const *argv);
  144. int assertepoch(const char *const *argv);
  145. int assertpredep(const char *const *argv);
  146. int assertlongfilenames(const char *const *argv);
  147. int assertmulticonrep(const char *const *argv);
  148. int assertmultiarch(const char *const *argv);
  149. int assertverprovides(const char *const *argv);
  150. int predeppackage(const char *const *argv);
  151. int printarch(const char *const *argv);
  152. int printinstarch(const char *const *argv);
  153. int print_foreign_arches(const char *const *argv);
  154. int cmpversions(const char *const *argv);
  155. /* from verify.c */
  156. bool verify_set_output(const char *name);
  157. int verify(const char *const *argv);
  158. /* from select.c */
  159. int getselections(const char *const *argv);
  160. int setselections(const char *const *argv);
  161. int clearselections(const char *const *argv);
  162. /* from packages.c, remove.c and configure.c */
  163. void md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn);
  164. void enqueue_package(struct pkginfo *pkg);
  165. void enqueue_package_mark_seen(struct pkginfo *pkg);
  166. void process_queue(void);
  167. int packages(const char *const *argv);
  168. void removal_bulk(struct pkginfo *pkg);
  169. int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in);
  170. enum dep_check {
  171. DEP_CHECK_HALT = 0,
  172. DEP_CHECK_DEFER = 1,
  173. DEP_CHECK_OK = 2,
  174. };
  175. enum dep_check dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
  176. struct varbuf *aemsgs);
  177. enum dep_check breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs);
  178. void deferred_remove(struct pkginfo *pkg);
  179. void deferred_configure(struct pkginfo *pkg);
  180. extern int sincenothing, dependtry;
  181. /* from cleanup.c (most of these are declared in archives.h) */
  182. void cu_prermremove(int argc, void **argv);
  183. /* from errors.c */
  184. void print_error_perpackage(const char *emsg, const void *data);
  185. void print_error_perarchive(const char *emsg, const void *data);
  186. void forcibleerr(int forceflag, const char *format, ...) DPKG_ATTR_PRINTF(2);
  187. int reportbroken_retexitstatus(int ret);
  188. bool skip_due_to_hold(struct pkginfo *pkg);
  189. /* from help.c */
  190. struct stat;
  191. bool ignore_depends(struct pkginfo *pkg);
  192. bool force_breaks(struct deppossi *possi);
  193. bool force_depends(struct deppossi *possi);
  194. bool force_conflicts(struct deppossi *possi);
  195. void conffile_mark_obsolete(struct pkginfo *pkg, struct filenamenode *namenode);
  196. void pkg_conffiles_mark_old(struct pkginfo *pkg);
  197. void checkpath(void);
  198. struct filenamenode *namenodetouse(struct filenamenode *namenode,
  199. struct pkginfo *pkg, struct pkgbin *pkgbin);
  200. int maintscript_installed(struct pkginfo *pkg, const char *scriptname,
  201. const char *desc, ...) DPKG_ATTR_SENTINEL;
  202. int maintscript_new(struct pkginfo *pkg,
  203. const char *scriptname, const char *desc,
  204. const char *cidir, char *cidirrest, ...)
  205. DPKG_ATTR_SENTINEL;
  206. int maintscript_fallback(struct pkginfo *pkg,
  207. const char *scriptname, const char *desc,
  208. const char *cidir, char *cidirrest,
  209. const char *ifok, const char *iffallback);
  210. /* Callers wanting to run the postinst use these two as they want to postpone
  211. * trigger incorporation until after updating the package status. The effect
  212. * is that a package can trigger itself. */
  213. int maintscript_postinst(struct pkginfo *pkg, ...) DPKG_ATTR_SENTINEL;
  214. void post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status);
  215. void clear_istobes(void);
  216. bool dir_is_used_by_others(struct filenamenode *namenode, struct pkginfo *pkg);
  217. bool dir_is_used_by_pkg(struct filenamenode *namenode, struct pkginfo *pkg,
  218. struct fileinlist *list);
  219. bool dir_has_conffiles(struct filenamenode *namenode, struct pkginfo *pkg);
  220. void log_action(const char *action, struct pkginfo *pkg, struct pkgbin *pkgbin);
  221. /* From selinux.c */
  222. void dpkg_selabel_load(void);
  223. void dpkg_selabel_set_context(const char *matchpath, const char *path, mode_t mode);
  224. void dpkg_selabel_close(void);
  225. /* from trigproc.c */
  226. enum trigproc_type {
  227. /** Opportunistic trigger processing. */
  228. TRIGPROC_TRY,
  229. /** Required trigger processing. */
  230. TRIGPROC_REQUIRED,
  231. };
  232. void trigproc_install_hooks(void);
  233. void trigproc_populate_deferred(void);
  234. void trigproc_run_deferred(void);
  235. void trigproc_reset_cycle(void);
  236. void trigproc(struct pkginfo *pkg, enum trigproc_type type);
  237. void trig_activate_packageprocessing(struct pkginfo *pkg);
  238. /* from depcon.c */
  239. enum which_pkgbin {
  240. wpb_installed,
  241. wpb_available,
  242. wpb_by_istobe,
  243. };
  244. struct deppossi_pkg_iterator;
  245. struct deppossi_pkg_iterator *
  246. deppossi_pkg_iter_new(struct deppossi *possi, enum which_pkgbin wpb);
  247. struct pkginfo *
  248. deppossi_pkg_iter_next(struct deppossi_pkg_iterator *iter);
  249. void
  250. deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter);
  251. bool depisok(struct dependency *dep, struct varbuf *whynot,
  252. struct pkginfo **fixbyrm, struct pkginfo **fixbytrigaw,
  253. bool allowunconfigd);
  254. struct cyclesofarlink;
  255. bool findbreakcycle(struct pkginfo *pkg);
  256. void describedepcon(struct varbuf *addto, struct dependency *dep);
  257. #endif /* MAIN_H */