main.h 9.4 KB

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