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