junk 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. if (!strcmp(newpig.name,"dpkg"))
  2. fprintf(stderr,"flags %o recordavailable %o config %s|%s ver %s|%s stat %d\n",
  3. flags,pdb_recordavailable,newpig.configversion,newpig.configrevision,
  4. newpifp->version,newpifp->revision,newpig.status);
  5. if (pkg->want != want_install && f_alsoselect) {
  6. printf("Selecting previously deselected package %s.\n",pkg->name);
  7. pkg->want= want_install;
  8. } else if (pkg->want == want_unknown && pkg->priority <= pri_standard &&
  9. fc_autoselect) {
  10. printf("Package %s is %s, selecting it by default.\n",pkg->name,
  11. priorityinfos[pkg->priority].name);
  12. pkg->want= want_install;
  13. } else if (pkg->want != want_install) {
  14. printf("Skipping deselected package %s.\n",pkg->name);
  15. pop_cleanup(ehflag_normaltidy);
  16. return;
  17. }
  18. int terminate_catchsignallist[]= { SIGINT, SIGTERM, 0 };
  19. int noterminal_catchsignallist[]= { SIGHUP, SIGPIPE, 0 };
  20. volatile int quitting= 0;
  21. static void terminate_sighandler(void) {
  22. void terminate_catchsignals(void) {
  23. int i;
  24. struct sigaction catchsig;
  25. catchsig.sa_handler= terminate_signalhandler;
  26. sigemptyset(&catchsig.sa_mask);
  27. for (i=0; terminate_catchsignallist[i]; i++)
  28. sigaddset(&catchsig.sa_mask,terminate_catchsignallist[i]);
  29. for (i=0; noterminal_catchsignallist[i]; i++)
  30. sigaddset(&catchsig.sa_mask,noterminal_catchsignallist[i]);
  31. catchsig.sa_flags= 0;
  32. for (i=0; terminate_catchsignallist[i]; i++)
  33. if (sigaction(terminate_catchsignallist[i],&catchsig,0))
  34. ohshite("unable to set up signal handler for %s",
  35. strsignal(terminate_catchsignallist[i]));
  36. catchsig.sa_handler= noterminal_signalhandler;
  37. for (i=0; noterminal_catchsignallist[i]; i++)
  38. if (sigaction(noterminal_catchsignallist[i],&catchsig,0))
  39. ohshite("unable to set up signal handler for %s",
  40. strsignal(noterminal_catchsignallist[i]));
  41. }
  42. #!/bin/sh -
  43. set -e
  44. cd /var/lib/dpkg
  45. # This won't check for unpacked packages if we're upgrading
  46. # from a *really* old dpkg, but they probably didn't do
  47. # conffiles right anyway.
  48. perl -000 -ne 'print $1 if m/^Package:\s+(\S+\n)/im &&
  49. $1 ne "dpkg\n" &&
  50. m/^Status:.*unpacked/im' \
  51. /var/lib/dpkg/status >/tmp/bp.$$
  52. if test -s /tmp/bp.$$
  53. then
  54. echo '
  55. WARNING -- SOME PACKAGES IN "UNPACKED" STATE
  56. Due to a change in the filenames used for installed vs. newly-distributed
  57. configuration files it is NOT SAFE to upgrade to this version of dpkg
  58. from
  59. undef %hash; @configfr= @configf= ();
  60. for $_ (split(/\n/,$st_pk2v{$package,'conffiles'})) {
  61. s/^ //; next unless length($_);
  62. if (!m/^(\S+) (-|newconffile|nonexistent|[0-9a-f]{32})$/) {
  63. &warn("$arg: ignoring bad stuff in old conffiles field \`$_'");
  64. next;
  65. }
  66. unshift(@configfr,$1); push(@configf,$1);
  67. $hash{$1}= $2;
  68. }
  69. undef %oldhash; @configf=();
  70. for $_ (split(/\n/,$st_pk2v{$package,'conffiles'})) {
  71. s/^ //; next unless length($_);
  72. if (!m/^(\S+) (-|newconffile|nonexistent|[0-9a-f]{32})$/) {
  73. &warn("$arg: ignoring bad stuff in old conffiles field \`$_'");
  74. next;
  75. }
  76. $oldhash{$1}= $2; push(@configf,$1);
  77. &debug("old hash of $1 is $2");
  78. }
  79. undef %newhash;
  80. fextract= fdopen(p1[0],"r");
  81. varbufinit(&thisname);
  82. while ((c= fgetc(fextract)) != EOF) {
  83. if (c != '\n') {
  84. varbufaddc(&thisdirname,c);
  85. continue;
  86. }
  87. varbufaddc(&thisdirname,0);
  88. /* Right, this next part gets done for each file (or directory) in the
  89. * archive of the new version of the package:
  90. */
  91. thisfile= filedatarecord(&filedata,thisname.buf);
  92. thisfile->nstat= ifdnew_inarchive;
  93. varbufreset(&thisname);
  94. }
  95. if (ferror(fextract)) ohshite("failed read from " BACKEND " extract pipe");
  96. if (thisname.used) ohshit("partial filename in output from " BACKEND " extract");
  97. if (fclose(fextract)) ohshite("failed to close" BACKEND " extract pipe");
  98. waitsubproc(c1,BACKEND " extract archive",0);
  99. /* Save new file list, new conffiles &c */
  100. if (chdir(instdir)) ohshite("unable to change to installation root directory"
  101. " for archive extract `%.250s'",instdir);
  102. execlp(BACKEND, BACKEND,"--control",filename,cidir,(char*)0);
  103. ohshite("failed to exec " BACKEND " to extract control information");
  104. /*** continue here ***/
  105. void remove_with_backup(pkginfo *pkg, struct installingfiledata **ifdlisthead) {
  106. if (f_noact) {
  107. printf("(would back up files in `%s', renaming each * to *" DPKGTEMPEXT ")\n",
  108. pkg->name);
  109. return;
  110. }
  111. filesinpackagerev(pkg, &filelist);
  112. for (barefile= filelist; barefile; barefile= barefile->next) {
  113. thisfile= filedatarecord(ifdlisthead,barefile->name);
  114. initostat(thisfile);
  115. if (thisfile->ncoff) continue;
  116. switch (thisfile->ostat) {
  117. case ifdold_directory:
  118. push_cleanup(, co_olddirectory, ...);
  119. break;
  120. case ifdold_none:
  121. break;
  122. case ifdold_file:
  123. l= strlen(barefile->name);
  124. toremove= m_malloc(instdirlen + l + 1);
  125. strcpy(toremove,instdir); strcpy(toremove+instdirlen,barefile->name);
  126. tempname= m_malloc(instdirlen + l + sizeof(DPKGTEMPEXT) + 1);
  127. strcpy(tempname,toremove); strcpy(tempname+instdirlen+l,DPKGTEMPEXT);
  128. ename= toremove + instdirlen;
  129. tename= tempname + instdirlen;
  130. if (rename(toremove.buf, tempname.buf))
  131. ohshite("unable to back up file-to-be-removed `%.250s'", tename);
  132. push_cleanup(cu_backupfile, co_backupfile,
  133. ..., toremove,tempname);
  134. break;
  135. default:
  136. abort();
  137. }
  138. }
  139. }
  140. case ifdold_directory:
  141. for (inwhich= findfile(toremove); inwhich; inwhich= inwhich->more)
  142. for (pkgsp= inwhich->pkgs; *pkgsp; pkgsp++)
  143. switch ((*pkgsp)->clientdata->istobe) {
  144. case itb_normal:
  145. goto exit_both_loops_and_the_switch_at_once;
  146. case itb_remove:
  147. case itb_installnew:
  148. /* We're removing or replacing this package, so that doesn't count.
  149. * For packages that we replace the caller will remove the directories
  150. * in the new version from the list of those to delete.
  151. */
  152. break;
  153. default:
  154. abort();
  155. }
  156. exit_both_loops_and_the_switch_at_once:
  157. if (!inwhich) { /* Find it anywhere else ? */
  158. struct fileinlist newdir;
  159. newdir= m_malloc(sizeof(struct fileinlist));
  160. newdir->name= m_malloc(strlen(ename));
  161. strcpy((*addirs)->name,ename);
  162. newdir->next= 0;
  163. *adddirs= newdir;
  164. adddirs= &newdir->next;
  165. }
  166. free(tempname); free(toremove);
  167. continue;
  168. }
  169. l= strlen(pkg->name);
  170. infdir= m_malloc(admindirlen + sizeof(INFODIR) + l + 50);
  171. strcpy(infdir,admindir);
  172. strcpy(infdir+admindirlen,"/" INFODIR);
  173. strcpy(infdir+admindirlen+sizeof(INFODIR), pkg->name);
  174. infdir[admindirlen+sizeof(INFODIR)+l-1]= '.';
  175. infdirrest= infdir + admindirlen+sizeof(INFODIR)+l;
  176. strcpy(infdirrest, LISTFILE);
  177. strcpy(infdirrest+sizeof(LISTFILE)-1,".new");
  178. for (thisfile= filelist; thisfile; thisfile= thisfile->next) {
  179. for (thisconff= conflictor->installed.conffiles;
  180. thisconff && strcmp(thisconff->name,thisfile->name);
  181. thisconff= thisconff->next);
  182. if (thisconff) continue;
  183. varbufreset(&toremove);
  184. varbufaddstr(&toremove, instdir);
  185. varbufaddstr(&toremove, "/");
  186. ename= toremove.buf + toremove.used;
  187. varbufaddstr(&toremove, thisfile->name);
  188. varbufaddc(&toremove, 0);
  189. if (unlink(toremove.buf)) {
  190. if (errno == EISDIR) {
  191. if (rmdir(toremove.buf) && errno != ENOTEMPTY)
  192. ohshite("%.250s: cannot remove directory `%.250s'",
  193. conflictor->name, ename);
  194. } else if (errno != ENOENT) {
  195. ohshite("%.250s: cannot remove `%.250s'", conflictor->name, ename);
  196. }
  197. }
  198. varbufaddstr(&toremove, DPKGTEMPEXT);
  199. varbufaddc(&toremove, 0);
  200. if (unlink(toremove.buf) && errno != ENOENT)
  201. ohshite("%.250s: cannot remove old backup file `%.250s'",
  202. conflictor->name, ename);
  203. }
  204. if (versionsatisfied(possi, &possi->ed.installed, &whynot)) present=1;
  205. *const relatestrings[]= { "may be more useful with", "recommends",
  206. "requires", "conflicts with", "provides" },
  207. if (possi
  208. varbufaddstr(&why, dep->up->name);
  209. return 1;
  210. }
  211. }
  212. varbufaddstr(&why, dep->up->name);
  213. return 1;
  214. }
  215. ||
  216. dep->up
  217. questionstatus=
  218. questionstatus= dep->up->clientdata->istobe ==
  219. if (up->
  220. ,
  221. if (questionstatus->status == stat_notinstalled ||
  222. questionstatus->status == stat_configfiles) return 0;
  223. switch (dep->type) {
  224. case dep_conflicts: reln= " conflicts with "; break;
  225. case dep_depends: reln= " depends on "; break;
  226. default: return 1;
  227. }
  228. varbufaddstr(whynot, dep->up->name);
  229. varbufaddstr(whynot, reln);
  230. reln= " ";
  231. for (possi= dep->list; possi; possi= possi->next) {
  232. varbufaddstr(whynot, reln);
  233. varbufaddstr(whynot, possi->ed->name);
  234. switch (possi->verrel) {
  235. case dvr_none: reln= 0; break;
  236. case dvr_later: reln= " (>"; break;
  237. case dvr_earlier: reln= " (<"; break;
  238. case dvr_exact: reln= " (="; break;
  239. default: abort();
  240. }
  241. if (reln) {
  242. varbufaddstr(whynot, reln);
  243. varbufaddstr(whynot, possi->version);
  244. if (possi->revision && *possi->revision) {
  245. varbufaddc(whynot,'-');
  246. varbufaddstr(whynot,possi->revision);
  247. }
  248. varbufaddc(whynot,')');
  249. }
  250. reln= " or ";
  251. } }
  252. }
  253. if (!*linebuf) {
  254. /* If the package wasn't installed at all, and we haven't said
  255. * yet why this isn't satisfied, we should say so now.
  256. */
  257. sprintf(linebuf, " %.250s is not installed.\n", possi->ed->name);
  258. varbufaddstr(whynot, linebuf);
  259. }
  260. }
  261. }
  262. /* OK so far - now check for Providers. */
  263. /* Don't say anything about this yet - it might be a virtual package.
  264. * Later on, if nothing has put anything in linebuf, we know that it
  265. * isn't and issue a diagnostic then.
  266. */
  267. *linebuf= 0;
  268. break;
  269. default:
  270. sprintf(linebuf, " %.250s is %s.\n",
  271. possi->ed->name, );
  272. break;
  273. }
  274. break;
  275. default:
  276. abort();
  277. }
  278. if (possi->ed->clientdata->istobe == itb_install) continue;
  279. default:
  280. break;
  281. /* fixme: what about things provided by the package(s)
  282. * which we are about to install ? For these we
  283. * have to use ->available.depended.
  284. */
  285. varbufaddc(whynot, ' ');
  286. varbufaddstr(whynot, provider->up->up->name);
  287. varbufaddstr(whynot, " provides ");
  288. varbufaddstr(whynot, possi->ed->name);
  289. }
  290. }
  291. sprintf(linebuf, " No package %.250s
  292. provider->up->up->status == stat_configfiles) {
  293. varbufaddstr(whynot, " but is not present.\n");
  294. } else {
  295. varbufaddstr(whynot, " and is present.\n");
  296. present=1;
  297. }
  298. break;
  299. case itb_install:
  300. varbufaddstr(whynot, " and is to be installed.\n");
  301. present=1;
  302. break;
  303. var
  304. varbufaddc(whynot, ' ');
  305. varbufaddstr(whynot, possi->ed->name);
  306. varbufaddstr(whynot, " is to be removed.\n");
  307. break;
  308. case itb_normal:
  309. varbufaddstr(whynot, possi->ed->name);
  310. varbufaddstr(whynot, " is ");
  311. if (dep->up->status == stat_installed) {
  312. if (versionsatisfied(possi, &possi->ed.installed, whynot)) return 1;
  313. varbufaddstr(&why, " version");
  314. varbufaddstr(&why, "
  315. varbufaddstr(&why, " is not present.\n");
  316. } else {
  317. varbufaddstr(whynot, statusstrings[dep->ed->status]);
  318. varbufaddstr(whynot, possi->ed->name);
  319. varbufaddstr(whynot, " is present");
  320. }
  321. break;
  322. case itb_installnew:
  323. varbufaddstr(whynot, possi->ed->name);
  324. varbufaddstr(whynot, " is to be installed");
  325. if (versionsatisfied(possi, &possi->ed.available, whynot)) present=1;
  326. default:
  327. abort();
  328. }
  329. }
  330. if (dep->type == dep_conflicts ? present : !present) return 0;
  331. varbufreset(whynot); return 1;
  332. }