enquiry.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /*
  2. * dpkg - main program for package management
  3. * enquiry.c - status enquiry and listing options
  4. *
  5. * Copyright (C) 1995,1996 Ian Jackson <ijackson@gnu.ai.mit.edu>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /* fixme: per-package audit */
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <fnmatch.h>
  26. #include <assert.h>
  27. #include <unistd.h>
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/ioctl.h>
  31. #include <fcntl.h>
  32. #include <config.h>
  33. #include <dpkg.h>
  34. #include <dpkg-db.h>
  35. #include <myopt.h>
  36. #include "filesdb.h"
  37. #include "main.h"
  38. int pkglistqsortcmp(const void *a, const void *b) {
  39. struct pkginfo *pa= *(struct pkginfo**)a;
  40. struct pkginfo *pb= *(struct pkginfo**)b;
  41. return strcmp(pa->name,pb->name);
  42. }
  43. static void limiteddescription(struct pkginfo *pkg, int maxl,
  44. const char **pdesc_r, int *l_r) {
  45. const char *pdesc, *p;
  46. int l;
  47. pdesc= pkg->installed.valid ? pkg->installed.description : 0;
  48. if (!pdesc) pdesc= _("(no description available)");
  49. p= strchr(pdesc,'\n');
  50. if (!p) p= pdesc+strlen(pdesc);
  51. l= (p - pdesc > maxl) ? maxl : (int)(p - pdesc);
  52. *pdesc_r=pdesc; *l_r=l;
  53. }
  54. static int getttywidth() {
  55. int fd;
  56. int res;
  57. struct winsize ws;
  58. if ((fd=open("/dev/tty",O_RDONLY))!=-1) {
  59. if (ioctl(fd, TIOCGWINSZ, &ws)==-1)
  60. ws.ws_col=80;
  61. close(fd);
  62. }
  63. return ws.ws_col;
  64. }
  65. static void list1package(struct pkginfo *pkg, int *head) {
  66. int l,w;
  67. int nw,vw,dw;
  68. const char *pdesc;
  69. char format[80];
  70. w=getttywidth()-80; /* get spare width */
  71. if (w<0) w=0; /* lets not try to deal with terminals that are too small */
  72. w>>=2; /* halve that so we can add that to the both the name and description */
  73. nw=(14+w); /* name width */
  74. vw=(14+w); /* version width */
  75. dw=(44+(2*w)); /* description width */
  76. sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw);
  77. if (!*head) {
  78. fputs(_("\
  79. Desired=Unknown/Install/Remove/Purge\n\
  80. | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed\n\
  81. |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)\n"), stdout);
  82. printf(format,'|','|','/', _("Name"), _("Version"), 40, _("Description"));
  83. printf("+++-"); /* status */
  84. for (l=0;l<nw;l++) printf("="); printf("-"); /* packagename */
  85. for (l=0;l<vw;l++) printf("="); printf("-"); /* version */
  86. for (l=0;l<dw;l++) printf("="); /* description */
  87. printf("\n");
  88. *head= 1;
  89. }
  90. if (!pkg->installed.valid) blankpackageperfile(&pkg->installed);
  91. limiteddescription(pkg,dw,&pdesc,&l);
  92. printf(format,
  93. "uihrp"[pkg->want],
  94. "nUFiHc"[pkg->status],
  95. " R?#"[pkg->eflag],
  96. pkg->name,
  97. versiondescribe(&pkg->installed.version,vdew_never),
  98. l, pdesc);
  99. }
  100. void listpackages(const char *const *argv) {
  101. struct pkgiterator *it;
  102. struct pkginfo *pkg;
  103. struct pkginfo **pkgl;
  104. const char *thisarg;
  105. int np, i, head, found;
  106. modstatdb_init(admindir,msdbrw_readonly);
  107. np= countpackages();
  108. pkgl= m_malloc(sizeof(struct pkginfo*)*np);
  109. it= iterpkgstart(); i=0;
  110. while ((pkg= iterpkgnext(it))) {
  111. assert(i<np);
  112. pkgl[i++]= pkg;
  113. }
  114. iterpkgend(it);
  115. assert(i==np);
  116. qsort(pkgl,np,sizeof(struct pkginfo*),pkglistqsortcmp);
  117. head=0;
  118. if (!*argv) {
  119. for (i=0; i<np; i++) {
  120. pkg= pkgl[i];
  121. if (pkg->status == stat_notinstalled) continue;
  122. list1package(pkg,&head);
  123. }
  124. } else {
  125. while ((thisarg= *argv++)) {
  126. found= 0;
  127. for (i=0; i<np; i++) {
  128. pkg= pkgl[i];
  129. if (fnmatch(thisarg,pkg->name,0)) continue;
  130. list1package(pkg,&head); found++;
  131. }
  132. if (!found)
  133. fprintf(stderr,_("No packages found matching %s.\n"),thisarg);
  134. }
  135. }
  136. if (ferror(stdout)) werr("stdout");
  137. if (ferror(stderr)) werr("stderr");
  138. }
  139. struct badstatinfo {
  140. int (*yesno)(struct pkginfo*, const struct badstatinfo *bsi);
  141. int val;
  142. const char *explanation;
  143. };
  144. static int bsyn_reinstreq(struct pkginfo *pkg, const struct badstatinfo *bsi) {
  145. return pkg->eflag &= eflagf_reinstreq;
  146. }
  147. static int bsyn_status(struct pkginfo *pkg, const struct badstatinfo *bsi) {
  148. if (pkg->eflag &= eflagf_reinstreq) return 0;
  149. return pkg->status == bsi->val;
  150. }
  151. static const struct badstatinfo badstatinfos[]= {
  152. {
  153. bsyn_reinstreq, 0,
  154. N_("The following packages are in a mess due to serious problems during\n"
  155. "installation. They must be reinstalled for them (and any packages\n"
  156. "that depend on them) to function properly:\n")
  157. }, {
  158. bsyn_status, stat_unpacked,
  159. N_("The following packages have been unpacked but not yet configured.\n"
  160. "They must be configured using dpkg --configure or the configure\n"
  161. "menu option in dselect for them to work:\n")
  162. }, {
  163. bsyn_status, stat_halfconfigured,
  164. N_("The following packages are only half configured, probably due to problems\n"
  165. "configuring them the first time. The configuration should be retried using\n"
  166. "dpkg --configure <package> or the configure menu option in " DSELECT ":\n")
  167. }, {
  168. bsyn_status, stat_halfinstalled,
  169. N_("The following packages are only half installed, due to problems during\n"
  170. "installation. The installation can probably be completed by retrying it;\n"
  171. "the packages can be removed using dselect or dpkg --remove:\n")
  172. }, {
  173. 0
  174. }
  175. };
  176. static void describebriefly(struct pkginfo *pkg) {
  177. int maxl, l;
  178. const char *pdesc;
  179. maxl= 57;
  180. l= strlen(pkg->name);
  181. if (l>20) maxl -= (l-20);
  182. limiteddescription(pkg,maxl,&pdesc,&l);
  183. printf(" %-20s %.*s\n",pkg->name,l,pdesc);
  184. }
  185. void audit(const char *const *argv) {
  186. struct pkgiterator *it;
  187. struct pkginfo *pkg;
  188. const struct badstatinfo *bsi;
  189. int head;
  190. if (*argv) badusage(_("--audit does not take any arguments"));
  191. modstatdb_init(admindir,msdbrw_readonly);
  192. for (bsi= badstatinfos; bsi->yesno; bsi++) {
  193. head= 0;
  194. it= iterpkgstart();
  195. while ((pkg= iterpkgnext(it))) {
  196. if (!bsi->yesno(pkg,bsi)) continue;
  197. if (!head) {
  198. fputs(gettext(bsi->explanation),stdout);
  199. head= 1;
  200. }
  201. describebriefly(pkg);
  202. }
  203. iterpkgend(it);
  204. if (head) putchar('\n');
  205. }
  206. if (ferror(stderr)) werr("stderr");
  207. }
  208. struct sectionentry {
  209. struct sectionentry *next;
  210. const char *name;
  211. int count;
  212. };
  213. static int yettobeunpacked(struct pkginfo *pkg, const char **thissect) {
  214. if (pkg->want != want_install) return 0;
  215. switch (pkg->status) {
  216. case stat_unpacked: case stat_installed: case stat_halfconfigured:
  217. return 0;
  218. case stat_notinstalled: case stat_halfinstalled: case stat_configfiles:
  219. if (thissect)
  220. *thissect= pkg->section && *pkg->section ? pkg->section : _("<unknown>");
  221. return 1;
  222. default:
  223. internerr("unknown status checking for unpackedness");
  224. }
  225. }
  226. void unpackchk(const char *const *argv) {
  227. int totalcount, sects;
  228. struct sectionentry *sectionentries, *se, **sep;
  229. struct pkgiterator *it;
  230. struct pkginfo *pkg;
  231. const char *thissect;
  232. char buf[20];
  233. int width;
  234. if (*argv) badusage(_("--yet-to-unpack does not take any arguments"));
  235. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  236. totalcount= 0;
  237. sectionentries= 0;
  238. sects= 0;
  239. it= iterpkgstart();
  240. while ((pkg= iterpkgnext(it))) {
  241. if (!yettobeunpacked(pkg, &thissect)) continue;
  242. for (se= sectionentries; se && strcasecmp(thissect,se->name); se= se->next);
  243. if (!se) {
  244. se= nfmalloc(sizeof(struct sectionentry));
  245. for (sep= &sectionentries;
  246. *sep && strcasecmp(thissect,(*sep)->name) > 0;
  247. sep= &(*sep)->next);
  248. se->name= thissect;
  249. se->count= 0;
  250. se->next= *sep;
  251. *sep= se;
  252. sects++;
  253. }
  254. se->count++; totalcount++;
  255. }
  256. iterpkgend(it);
  257. if (totalcount == 0) exit(0);
  258. if (totalcount <= 12) {
  259. it= iterpkgstart();
  260. while ((pkg= iterpkgnext(it))) {
  261. if (!yettobeunpacked(pkg,0)) continue;
  262. describebriefly(pkg);
  263. }
  264. iterpkgend(it);
  265. } else if (sects <= 12) {
  266. for (se= sectionentries; se; se= se->next) {
  267. sprintf(buf,"%d",se->count);
  268. printf(_(" %d in %s: "),se->count,se->name);
  269. width= 70-strlen(se->name)-strlen(buf);
  270. while (width > 59) { putchar(' '); width--; }
  271. it= iterpkgstart();
  272. while ((pkg= iterpkgnext(it))) {
  273. if (!yettobeunpacked(pkg,&thissect)) continue;
  274. if (strcasecmp(thissect,se->name)) continue;
  275. width -= strlen(pkg->name); width--;
  276. if (width < 4) { printf(" ..."); break; }
  277. printf(" %s",pkg->name);
  278. }
  279. iterpkgend(it);
  280. putchar('\n');
  281. }
  282. } else {
  283. printf(_(" %d packages, from the following sections:"),totalcount);
  284. width= 0;
  285. for (se= sectionentries; se; se= se->next) {
  286. sprintf(buf,"%d",se->count);
  287. width -= (6 + strlen(se->name) + strlen(buf));
  288. if (width < 0) { putchar('\n'); width= 73 - strlen(se->name) - strlen(buf); }
  289. printf(" %s (%d)",se->name,se->count);
  290. }
  291. putchar('\n');
  292. }
  293. fflush(stdout);
  294. if (ferror(stdout)) werr("stdout");
  295. }
  296. static int searchoutput(struct filenamenode *namenode) {
  297. int found, i;
  298. struct filepackages *packageslump;
  299. if (namenode->divert) {
  300. for (i=0; i<2; i++) {
  301. if (namenode->divert->pkg) printf(_("diversion by %s"),namenode->divert->pkg->name);
  302. else printf(_("local diversion"));
  303. printf(" %s: %s\n", i ? _("to") : _("from"),
  304. i ?
  305. (namenode->divert->useinstead
  306. ? namenode->divert->useinstead->name
  307. : namenode->name)
  308. :
  309. (namenode->divert->camefrom
  310. ? namenode->divert->camefrom->name
  311. : namenode->name));
  312. }
  313. }
  314. found= 0;
  315. for (packageslump= namenode->packages;
  316. packageslump;
  317. packageslump= packageslump->more) {
  318. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  319. if (found) fputs(", ",stdout);
  320. fputs(packageslump->pkgs[i]->name,stdout);
  321. found++;
  322. }
  323. }
  324. if (found) printf(": %s\n",namenode->name);
  325. return found + (namenode->divert ? 1 : 0);
  326. }
  327. void searchfiles(const char *const *argv) {
  328. struct filenamenode *namenode;
  329. struct fileiterator *it;
  330. const char *thisarg;
  331. int found;
  332. static struct varbuf vb;
  333. if (!*argv)
  334. badusage(_("--search needs at least one file name pattern argument"));
  335. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  336. ensure_allinstfiles_available_quiet();
  337. ensure_diversions();
  338. while ((thisarg= *argv++) != 0) {
  339. found= 0;
  340. if (!strchr("*[?/",*thisarg)) {
  341. varbufreset(&vb);
  342. varbufaddc(&vb,'*');
  343. varbufaddstr(&vb,thisarg);
  344. varbufaddc(&vb,'*');
  345. varbufaddc(&vb,0);
  346. thisarg= vb.buf;
  347. }
  348. if (strcspn(thisarg,"*[?\\") == strlen(thisarg)) {
  349. namenode= findnamenode(thisarg, 0);
  350. found += searchoutput(namenode);
  351. } else {
  352. it= iterfilestart();
  353. while ((namenode= iterfilenext(it)) != 0) {
  354. if (fnmatch(thisarg,namenode->name,0)) continue;
  355. found+= searchoutput(namenode);
  356. }
  357. iterfileend(it);
  358. }
  359. if (!found) {
  360. fprintf(stderr,_("dpkg: %s not found.\n"),thisarg);
  361. if (ferror(stderr)) werr("stderr");
  362. } else {
  363. if (ferror(stdout)) werr("stdout");
  364. }
  365. }
  366. }
  367. void enqperpackage(const char *const *argv) {
  368. int failures;
  369. const char *thisarg;
  370. struct fileinlist *file;
  371. struct pkginfo *pkg;
  372. struct filenamenode *namenode;
  373. if (!*argv)
  374. badusage(_("--%s needs at least one package name argument"), cipaction->olong);
  375. failures= 0;
  376. if (cipaction->arg==act_listfiles)
  377. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  378. else
  379. modstatdb_init(admindir,msdbrw_readonly);
  380. while ((thisarg= *argv++) != 0) {
  381. pkg= findpackage(thisarg);
  382. switch (cipaction->arg) {
  383. case act_status:
  384. if (pkg->status == stat_notinstalled &&
  385. pkg->priority == pri_unknown &&
  386. !(pkg->section && *pkg->section) &&
  387. !pkg->files &&
  388. pkg->want == want_unknown &&
  389. !informative(pkg,&pkg->installed)) {
  390. printf(_("Package `%s' is not installed and no info is available.\n"),pkg->name);
  391. failures++;
  392. } else {
  393. writerecord(stdout, "<stdout>", pkg, &pkg->installed);
  394. }
  395. break;
  396. case act_printavail:
  397. if (!informative(pkg,&pkg->available)) {
  398. printf(_("Package `%s' is not available.\n"),pkg->name);
  399. failures++;
  400. } else {
  401. writerecord(stdout, "<stdout>", pkg, &pkg->available);
  402. }
  403. break;
  404. case act_listfiles:
  405. switch (pkg->status) {
  406. case stat_notinstalled:
  407. printf(_("Package `%s' is not installed.\n"),pkg->name);
  408. failures++;
  409. break;
  410. default:
  411. ensure_packagefiles_available(pkg);
  412. ensure_diversions();
  413. file= pkg->clientdata->files;
  414. if (!file) {
  415. printf(_("Package `%s' does not contain any files (!)\n"),pkg->name);
  416. } else {
  417. while (file) {
  418. namenode= file->namenode;
  419. puts(namenode->name);
  420. if (namenode->divert && !namenode->divert->camefrom) {
  421. if (!namenode->divert->pkg) printf(_("locally diverted"));
  422. else if (pkg == namenode->divert->pkg) printf(_("package diverts others"));
  423. else printf(_("diverted by %s"),namenode->divert->pkg->name);
  424. printf(" to: %s\n",namenode->divert->useinstead->name);
  425. }
  426. file= file->next;
  427. }
  428. }
  429. break;
  430. }
  431. break;
  432. default:
  433. internerr("unknown action");
  434. }
  435. putchar('\n');
  436. if (ferror(stdout)) werr("stdout");
  437. }
  438. if (failures) {
  439. puts(_("Use dpkg --info (= dpkg-deb --info) to examine archive files,\n"
  440. "and dpkg --contents (= dpkg-deb --contents) to list their contents."));
  441. if (ferror(stdout)) werr("stdout");
  442. }
  443. }
  444. static void assertversion(const char *const *argv,
  445. struct versionrevision *verrev_buf,
  446. const char *reqversion) {
  447. struct pkginfo *pkg;
  448. if (*argv) badusage(_("--assert-* does not take any arguments"));
  449. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  450. if (verrev_buf->epoch == ~0UL) {
  451. verrev_buf->epoch= 0;
  452. verrev_buf->version= nfstrsave(reqversion);
  453. verrev_buf->revision= 0;
  454. }
  455. pkg= findpackage("dpkg");
  456. switch (pkg->status) {
  457. case stat_installed:
  458. break;
  459. case stat_unpacked: case stat_halfconfigured: case stat_halfinstalled:
  460. if (versionsatisfied3(&pkg->configversion,verrev_buf,dvr_laterequal))
  461. break;
  462. printf(_("Version of dpkg with working epoch support not yet configured.\n"
  463. " Please use `dpkg --configure dpkg', and then try again.\n"));
  464. exit(1);
  465. default:
  466. printf(_("dpkg not recorded as installed, cannot check for epoch support !\n"));
  467. exit(1);
  468. }
  469. }
  470. void assertpredep(const char *const *argv) {
  471. static struct versionrevision predepversion = {~0UL,0,0};
  472. assertversion(argv,&predepversion,"1.1.0");
  473. }
  474. void assertepoch(const char *const *argv) {
  475. static struct versionrevision epochversion = {~0UL,0,0};
  476. assertversion(argv,&epochversion,"1.4.0.7");
  477. }
  478. void assertlongfilenames(const char *const *argv) {
  479. static struct versionrevision epochversion = {~0UL,0,0};
  480. assertversion(argv,&epochversion,"1.4.1.17");
  481. }
  482. void assertmulticonrep(const char *const *argv) {
  483. static struct versionrevision epochversion = {~0UL,0,0};
  484. assertversion(argv,&epochversion,"1.4.1.19");
  485. }
  486. void predeppackage(const char *const *argv) {
  487. /* Print a single package which:
  488. * (a) is the target of one or more relevant predependencies.
  489. * (b) has itself no unsatisfied pre-dependencies.
  490. * If such a package is present output is the Packages file entry,
  491. * which can be massaged as appropriate.
  492. * Exit status:
  493. * 0 = a package printed, OK
  494. * 1 = no suitable package available
  495. * 2 = error
  496. */
  497. static struct varbuf vb;
  498. struct pkgiterator *it;
  499. struct pkginfo *pkg= 0, *startpkg, *trypkg;
  500. struct dependency *dep;
  501. struct deppossi *possi, *provider;
  502. if (*argv) badusage(_("--predep-package does not take any argument"));
  503. modstatdb_init(admindir,msdbrw_readonly);
  504. clear_istobes(); /* We use clientdata->istobe to detect loops */
  505. for (it=iterpkgstart(), dep=0;
  506. !dep && (pkg=iterpkgnext(it));
  507. ) {
  508. if (pkg->want != want_install) continue; /* Ignore packages user doesn't want */
  509. if (!pkg->files) continue; /* Ignore packages not available */
  510. pkg->clientdata->istobe= itb_preinstall;
  511. for (dep= pkg->available.depends; dep; dep= dep->next) {
  512. if (dep->type != dep_predepends) continue;
  513. if (depisok(dep,&vb,0,1)) continue;
  514. break; /* This will leave dep non-NULL, and so exit the loop. */
  515. }
  516. pkg->clientdata->istobe= itb_normal;
  517. /* If dep is NULL we go and get the next package. */
  518. }
  519. if (!dep) exit(1); /* Not found */
  520. assert(pkg);
  521. startpkg= pkg;
  522. pkg->clientdata->istobe= itb_preinstall;
  523. /* OK, we have found an unsatisfied predependency.
  524. * Now go and find the first thing we need to install, as a first step
  525. * towards satisfying it.
  526. */
  527. do {
  528. /* We search for a package which would satisfy dep, and put it in pkg */
  529. for (possi=dep->list, pkg=0;
  530. !pkg && possi;
  531. possi=possi->next) {
  532. trypkg= possi->ed;
  533. if (!trypkg->available.valid) continue;
  534. if (trypkg->files && versionsatisfied(&trypkg->available,possi)) {
  535. if (trypkg->clientdata->istobe == itb_normal) { pkg= trypkg; break; }
  536. }
  537. if (possi->verrel != dvr_none) continue;
  538. for (provider=possi->ed->available.depended;
  539. !pkg && provider;
  540. provider=provider->next) {
  541. if (provider->up->type != dep_provides) continue;
  542. trypkg= provider->up->up;
  543. if (!trypkg->available.valid || !trypkg->files) continue;
  544. if (trypkg->clientdata->istobe == itb_normal) { pkg= trypkg; break; }
  545. }
  546. }
  547. if (!pkg) {
  548. varbufreset(&vb);
  549. describedepcon(&vb,dep);
  550. varbufaddc(&vb,0);
  551. fprintf(stderr, _("dpkg: cannot see how to satisfy pre-dependency:\n %s\n"),vb.buf);
  552. ohshit(_("cannot satisfy pre-dependencies for %.250s (wanted due to %.250s)"),
  553. dep->up->name,startpkg->name);
  554. }
  555. pkg->clientdata->istobe= itb_preinstall;
  556. for (dep= pkg->available.depends; dep; dep= dep->next) {
  557. if (dep->type != dep_predepends) continue;
  558. if (depisok(dep,&vb,0,1)) continue;
  559. break; /* This will leave dep non-NULL, and so exit the loop. */
  560. }
  561. } while (dep);
  562. /* OK, we've found it - pkg has no unsatisfied pre-dependencies ! */
  563. writerecord(stdout,"<stdout>",pkg,&pkg->available);
  564. if (fflush(stdout)) werr("stdout");
  565. }
  566. static void badlgccfn(const char *compiler, const char *output, const char *why)
  567. NONRETURNING;
  568. static void badlgccfn(const char *compiler, const char *output, const char *why) {
  569. fprintf(stderr,
  570. _("dpkg: unexpected output from `%s --print-libgcc-file-name':\n"
  571. " `%s'\n"),
  572. compiler,output);
  573. ohshit(_("compiler libgcc filename not understood: %.250s"),why);
  574. }
  575. void printinstarch(const char *const *argv) {
  576. if (*argv) badusage(_("--print-installation-architecture does not take any argument"));
  577. if (printf("%s\n",architecture) == EOF) werr("stdout");
  578. if (fflush(stdout)) werr("stdout");
  579. }
  580. void printarch(const char *const *argv) {
  581. static const struct { const char *from, *to, *gnu; } archtable[]= {
  582. #include "archtable.h"
  583. { 0,0,0 }
  584. }, *archp;
  585. const char *ccompiler, *arch;
  586. int p1[2], c;
  587. pid_t c1;
  588. FILE *ccpipe;
  589. struct varbuf vb;
  590. ptrdiff_t ll;
  591. char *p, *q;
  592. if (*argv) badusage(_("--print-architecture does not take any argument"));
  593. ccompiler= getenv("CC");
  594. if (!ccompiler) ccompiler= "gcc";
  595. varbufinit(&vb);
  596. m_pipe(p1);
  597. ccpipe= fdopen(p1[0],"r"); if (!ccpipe) ohshite(_("failed to fdopen CC pipe"));
  598. if (!(c1= m_fork())) {
  599. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  600. execlp(ccompiler,ccompiler,"--print-libgcc-file-name",(char*)0);
  601. /* if we have a problem excuting the C compiler, we don't
  602. * want to fail. If there is a problem with the compiler,
  603. * like not being installed, or CC being set incorrectly,
  604. * then important problems will show up elsewhere, not in
  605. * dpkg. If a C compiler is not important to the reason we
  606. * are being called, then we should just give them the built
  607. * in arch.
  608. */
  609. if (printf("/usr/lib/gcc-lib/%s-none/0.0.0/libgcc.a\n",architecture) == EOF)
  610. werr("stdout");
  611. if (fflush(stdout)) werr("stdout");
  612. exit(0);
  613. }
  614. close(p1[1]);
  615. while ((c= getc(ccpipe)) != EOF) varbufaddc(&vb,c);
  616. if (ferror(ccpipe)) ohshite(_("error reading from CC pipe"));
  617. waitsubproc(c1,"gcc --print-libgcc-file-name",0);
  618. if (!vb.used) badlgccfn(ccompiler,"",_("empty output"));
  619. varbufaddc(&vb,0);
  620. if (vb.buf[vb.used-2] != '\n') badlgccfn(ccompiler,vb.buf,_("no newline"));
  621. vb.used-= 2; varbufaddc(&vb,0);
  622. p= strstr(vb.buf,"/gcc-lib/");
  623. if (!p) badlgccfn(ccompiler,vb.buf,_("no gcc-lib component"));
  624. p+= 9;
  625. q= strchr(p,'-'); if (!q) badlgccfn(ccompiler,vb.buf,_("no hyphen after gcc-lib"));
  626. ll= q-p;
  627. for (archp=archtable;
  628. archp->from && !(strlen(archp->from) == ll && !strncmp(archp->from,p,ll));
  629. archp++);
  630. switch (cipaction->arg) {
  631. case act_printarch: arch= archp->to; break;
  632. case act_printgnuarch: arch= archp->gnu; break;
  633. default: internerr("unknown action in printarch");
  634. }
  635. if (!arch) {
  636. *q= 0; arch= p;
  637. fprintf(stderr, _("dpkg: warning, architecture `%s' not in remapping table\n"),arch);
  638. }
  639. if (printf("%s\n",arch) == EOF) werr("stdout");
  640. if (fflush(stdout)) werr("stdout");
  641. }
  642. void cmpversions(const char *const *argv) {
  643. struct relationinfo {
  644. const char *string;
  645. /* These values are exit status codes, so 0=true, 1=false */
  646. int if_lesser, if_equal, if_greater;
  647. int if_none_a, if_none_both, if_none_b;
  648. };
  649. static const struct relationinfo relationinfos[]= {
  650. /* < = > !a!2!b */
  651. { "le", 0,0,1, 0,0,1 },
  652. { "lt", 0,1,1, 0,1,1 },
  653. { "eq", 1,0,1, 1,0,1 },
  654. { "ne", 0,1,0, 0,1,0 },
  655. { "ge", 1,0,0, 1,0,0 },
  656. { "gt", 1,1,0, 1,1,0 },
  657. { "le-nl", 0,0,1, 1,0,0 }, /* Here none */
  658. { "lt-nl", 0,1,1, 1,1,0 }, /* is counted */
  659. { "ge-nl", 1,0,0, 0,0,1 }, /* than any version.*/
  660. { "gt-nl", 1,1,0, 0,1,1 }, /* */
  661. { "<", 0,0,1, 0,0,1 }, /* For compatibility*/
  662. { "<=", 0,0,1, 0,0,1 }, /* with dpkg */
  663. { "<<", 0,1,1, 0,1,1 }, /* control file */
  664. { "=", 1,0,1, 1,0,1 }, /* syntax */
  665. { ">", 1,0,0, 1,0,0 }, /* */
  666. { ">=", 1,0,0, 1,0,0 },
  667. { ">>", 1,1,0, 1,1,0 },
  668. { 0 }
  669. };
  670. const struct relationinfo *rip;
  671. const char *emsg;
  672. struct versionrevision a, b;
  673. int r;
  674. if (!argv[0] || !argv[1] || !argv[2] || argv[3])
  675. badusage(_("--cmpversions takes three arguments:"
  676. " <version> <relation> <version>"));
  677. for (rip=relationinfos; rip->string && strcmp(rip->string,argv[1]); rip++);
  678. if (!rip->string) badusage(_("--cmpversions bad relation"));
  679. if (*argv[0] && strcmp(argv[0],"<unknown>")) {
  680. emsg= parseversion(&a,argv[0]);
  681. if (emsg) {
  682. if (printf(_("version a has bad syntax: %s\n"),emsg) == EOF) werr("stdout");
  683. if (fflush(stdout)) werr("stdout");
  684. exit(1);
  685. }
  686. } else {
  687. blankversion(&a);
  688. }
  689. if (*argv[2] && strcmp(argv[2],"<unknown>")) {
  690. emsg= parseversion(&b,argv[2]);
  691. if (emsg) {
  692. if (printf(_("version b has bad syntax: %s\n"),emsg) == EOF) werr("stdout");
  693. if (fflush(stdout)) werr("stdout");
  694. exit(1);
  695. }
  696. } else {
  697. blankversion(&b);
  698. }
  699. if (!informativeversion(&a)) {
  700. exit(informativeversion(&b) ? rip->if_none_a : rip->if_none_both);
  701. } else if (!informativeversion(&b)) {
  702. exit(rip->if_none_b);
  703. }
  704. r= versioncompare(&a,&b);
  705. debug(dbg_general,"cmpversions a=`%s' b=`%s' r=%d",
  706. versiondescribe(&a,vdew_always),
  707. versiondescribe(&b,vdew_always),
  708. r);
  709. if (r>0) exit(rip->if_greater);
  710. else if (r<0) exit(rip->if_lesser);
  711. else exit(rip->if_equal);
  712. }