58
58
struct filenamenode *namenodetouse(struct filenamenode *namenode, struct pkginfo *pkg) {
59
59
struct filenamenode *r;
61
61
if (!namenode->divert) {
66
66
debug(dbg_eachfile,"namenodetouse namenode=`%s' pkg=%s",
67
67
namenode->name,pkg->name);
70
70
(namenode->divert->useinstead && namenode->divert->pkg != pkg)
71
71
? namenode->divert->useinstead : namenode;
73
73
debug(dbg_eachfile,
74
74
"namenodetouse ... useinstead=%s camefrom=%s pkg=%s return %s",
75
75
namenode->divert->useinstead ? namenode->divert->useinstead->name : "<none>",
114
115
path_end = strchr(path, ':');
115
116
path_len = path_end ? (size_t)(path_end - path) : strlen(path);
117
varbufreset(&filename);
118
varbufaddbuf(&filename, path, path_len);
118
varbuf_reset(&filename);
119
varbuf_add_buf(&filename, path, path_len);
120
varbufaddc(&filename, '/');
121
varbufaddstr(&filename, *prog);
122
varbufaddc(&filename, '\0');
121
varbuf_add_char(&filename, '/');
122
varbuf_add_str(&filename, *prog);
123
varbuf_end_str(&filename);
124
125
if (stat(filename.buf, &stab) == 0 && (stab.st_mode & 0111))
136
137
forcibleerr(fc_badpath,
137
P_("%d expected program not found in PATH or not executable.\n"
138
"NB: root's PATH should usually contain "
139
"/usr/local/sbin, /usr/sbin and /sbin.",
140
"%d expected programs not found in PATH or not executable.\n"
141
"NB: root's PATH should usually contain "
142
"/usr/local/sbin, /usr/sbin and /sbin.", warned), warned);
138
P_("%d expected program not found in PATH or not executable.\n%s",
139
"%d expected programs not found in PATH or not executable.\n%s",
141
warned, _("Note: root's PATH should usually contain "
142
"/usr/local/sbin, /usr/sbin and /sbin."));
174
174
return fc_conflicts;
178
* Returns the path to the script inside the chroot.
177
180
static const char *
178
181
preexecscript(struct command *cmd)
180
/* returns the path to the script inside the chroot
181
* FIXME: none of the stuff here will work if admindir isn't inside
182
* instdir as expected.
183
const char *admindir = dpkg_db_get_dir();
184
size_t instdirl = strlen(instdir);
187
if (strncmp(admindir, instdir, instdirl) != 0)
188
ohshit(_("admindir must be inside instdir for dpkg to work properly"));
189
if (setenv("DPKG_ADMINDIR", admindir + instdirl, 1) < 0)
190
ohshite(_("unable to setenv for subprocesses"));
187
192
if (chroot(instdir)) ohshite(_("failed to chroot to `%.250s'"),instdir);
189
194
ohshite(_("failed to chdir to `%.255s'"), "/");
191
if (f_debug & dbg_scripts) {
196
if (debug_has_flag(dbg_scripts)) {
192
197
struct varbuf args = VARBUF_INIT;
193
198
const char **argv = cmd->argv;
195
200
while (*++argv) {
196
varbufaddc(&args, ' ');
197
varbufaddstr(&args, *argv);
201
varbuf_add_char(&args, ' ');
202
varbuf_add_str(&args, *argv);
199
varbufaddc(&args, '\0');
204
varbuf_end_str(&args);
200
205
debug(dbg_scripts, "fork/exec %s (%s )", cmd->filename, args.buf);
201
206
varbuf_destroy(&args);
203
instdirl= strlen(instdir);
205
209
return cmd->filename;
206
210
assert(strlen(cmd->filename) >= instdirl);
207
211
return cmd->filename + instdirl;
211
215
post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status)
235
239
debug(dbg_triggersdetail,
236
240
"post_script_tasks - ensure_diversions; trig_incorporate");
237
trig_incorporate(msdbrw_write, admindir);
241
trig_incorporate(msdbrw_write);
253
do_script(struct pkginfo *pkg, struct pkginfoperfile *pif,
257
do_script(struct pkginfo *pkg, struct pkgbin *pif,
254
258
struct command *cmd, struct stat *stab, int warn)
258
263
setexecute(cmd->filename, stab);
260
265
push_cleanup(cu_post_script_tasks, ehflag_bombout, NULL, 0, 0);
264
if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
265
setenv(MAINTSCRIPTARCHENVVAR, pif->architecture, 1) ||
266
setenv(MAINTSCRIPTNAMEENVVAR, cmd->argv[0], 1) ||
267
setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
267
pid = subproc_fork();
269
if (setenv("DPKG_MAINTSCRIPT_PACKAGE", pkg->name, 1) ||
270
setenv("DPKG_MAINTSCRIPT_ARCH", pif->arch, 1) ||
271
setenv("DPKG_MAINTSCRIPT_NAME", cmd->argv[0], 1) ||
272
setenv("DPKG_RUNNING_VERSION", PACKAGE_VERSION, 1))
268
273
ohshite(_("unable to setenv for maintainer script"));
270
275
cmd->filename = cmd->argv[0] = preexecscript(cmd);
271
276
command_exec(cmd);
273
subproc_signals_setup(cmd->name); /* This does a push_cleanup() */
274
r = subproc_wait_check(c1, cmd->name, warn);
278
subproc_signals_setup(cmd->name); /* This does a push_cleanup(). */
279
r = subproc_wait_check(pid, cmd->name, warn);
275
280
pop_cleanup(ehflag_normaltidy);
277
282
pop_cleanup(ehflag_normaltidy);
443
451
struct pkgiterator *it;
444
452
struct pkginfo *pkg;
447
while ((pkg = iterpkgnext(it)) != NULL) {
454
it = pkg_db_iter_new();
455
while ((pkg = pkg_db_iter_next(it)) != NULL) {
448
456
ensure_package_clientdata(pkg);
449
457
pkg->clientdata->istobe= itb_normal;
450
458
pkg->clientdata->replacingfilesandsaid= 0;
455
void debug(int which, const char *fmt, ...) {
458
if (!(f_debug & which)) return;
459
fprintf(stderr,"D0%05o: ",which);
461
vfprintf(stderr, fmt, args);
460
pkg_db_iter_free(it);
497
494
struct filepackages_iterator *iter;
498
495
struct pkginfo *other_pkg;
500
497
debug(dbg_veryverbose, "isdirectoryinuse `%s' (except %s)", file->name,
501
498
pkg ? pkg->name : "<none>");
517
514
void oldconffsetflags(const struct conffile *searchconff) {
518
515
struct filenamenode *namenode;
520
517
while (searchconff) {
521
518
namenode= findnamenode(searchconff->name, 0); /* XXX */
522
519
namenode->flags |= fnnf_old_conff;
563
560
void ensure_pathname_nonexisting(const char *pathname) {
567
564
u = path_skip_slash_dotslash(pathname);
570
567
debug(dbg_eachfile,"ensure_pathname_nonexisting `%s'",pathname);
571
if (!rmdir(pathname)) return; /* Deleted it OK, it was a directory. */
568
if (!rmdir(pathname))
569
return; /* Deleted it OK, it was a directory. */
572
570
if (errno == ENOENT || errno == ELOOP) return;
573
571
if (errno == ENOTDIR) {
574
/* Either it's a file, or one of the path components is. If one
575
* of the path components is this will fail again ...
572
/* Either it's a file, or one of the path components is. If one
573
* of the path components is this will fail again ... */
577
574
if (secure_unlink(pathname) == 0)
578
return; /* OK, it was */
575
return; /* OK, it was. */
579
576
if (errno == ENOTDIR) return;
581
if (errno != ENOTEMPTY && errno != EEXIST) { /* Huh ? */
578
if (errno != ENOTEMPTY && errno != EEXIST) { /* Huh? */
582
579
ohshite(_("unable to securely remove '%.255s'"), pathname);
581
pid = subproc_fork();
586
583
execlp(RM, "rm", "-rf", "--", pathname, NULL);
587
ohshite(_("failed to exec rm for cleanup"));
584
ohshite(_("unable to execute %s (%s)"), _("rm command for cleanup"), RM);
589
586
debug(dbg_eachfile,"ensure_pathname_nonexisting running rm -rf");
590
subproc_wait_check(c1, "rm cleanup", 0);
587
subproc_wait_check(pid, "rm cleanup", 0);
593
590
void log_action(const char *action, struct pkginfo *pkg) {