configure.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * dpkg - main program for package management
  3. * configure.c - configure packages
  4. *
  5. * Copyright 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright 1999,2002 Wichert Akkerman <wichert@deephackmode.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
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * 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
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <errno.h>
  23. #include <signal.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <fcntl.h>
  29. #include <sys/stat.h>
  30. #include <sys/types.h>
  31. #include <dirent.h>
  32. #include <ctype.h>
  33. #include <unistd.h>
  34. #include <string.h>
  35. #include <assert.h>
  36. #include <sys/wait.h>
  37. #include <config.h>
  38. #include <dpkg.h>
  39. #include <dpkg-db.h>
  40. #include "filesdb.h"
  41. #include "main.h"
  42. int conffoptcells[2][2]= { CONFFOPTCELLS };
  43. static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn);
  44. static void copyfileperm(const char* source, const char* target);
  45. static void showdiff(const char* old, const char* new);
  46. static void suspend(void);
  47. static enum conffopt promptconfaction(const char* cfgfile, const char* realold,
  48. const char* realnew, int useredited, int distedited,
  49. enum conffopt what);
  50. void deferred_configure(struct pkginfo *pkg) {
  51. /* The algorithm for deciding what to configure first is as follows:
  52. * Loop through all packages doing a `try 1' until we've been round
  53. * and nothing has been done, then do `try 2' and `try 3' likewise.
  54. * The incrementing of `dependtry' is done by process_queue().
  55. * Try 1:
  56. * Are all dependencies of this package done ? If so, do it.
  57. * Are any of the dependencies missing or the wrong version ?
  58. * If so, abort (unless --force-depends, in which case defer)
  59. * Will we need to configure a package we weren't given as an
  60. * argument ? If so, abort - except if --force-configure-any,
  61. * in which case we add the package to the argument list.
  62. * If none of the above, defer the package.
  63. * Try 2:
  64. * Find a cycle and break it (see above).
  65. * Do as for try 1.
  66. * Try 3 (only if --force-depends-version).
  67. * Same as for try 2, but don't mind version number in dependencies.
  68. * Try 4 (only if --force-depends).
  69. * Do anyway.
  70. */
  71. struct varbuf aemsgs, cdr, cdr2;
  72. char *cdr2rest;
  73. int ok, r, useredited, distedited;
  74. struct conffile *conff;
  75. char *currenthash= 0, *newdisthash= 0;
  76. struct stat stab;
  77. enum conffopt what;
  78. if (pkg->status == stat_notinstalled)
  79. ohshit(_("no package named `%s' is installed, cannot configure"),pkg->name);
  80. if (pkg->status == stat_installed)
  81. ohshit(_("package %.250s is already installed and configured"), pkg->name);
  82. if (pkg->status != stat_unpacked && pkg->status != stat_halfconfigured)
  83. ohshit(_("package %.250s is not ready for configuration\n"
  84. " cannot configure (current status `%.250s')"),
  85. pkg->name, statusinfos[pkg->status].name);
  86. if (dependtry > 1)
  87. if (findbreakcycle(pkg,0))
  88. sincenothing= 0;
  89. varbufinit(&aemsgs);
  90. ok= dependencies_ok(pkg,0,&aemsgs);
  91. if (ok == 1) {
  92. varbuffree(&aemsgs);
  93. pkg->clientdata->istobe= itb_installnew;
  94. add_to_queue(pkg);
  95. return;
  96. } else if (ok == 0) {
  97. sincenothing= 0;
  98. varbufaddc(&aemsgs,0);
  99. fprintf(stderr,
  100. _("dpkg: dependency problems prevent configuration of %s:\n%s"),
  101. pkg->name, aemsgs.buf);
  102. varbuffree(&aemsgs);
  103. ohshit(_("dependency problems - leaving unconfigured"));
  104. } else if (aemsgs.used) {
  105. varbufaddc(&aemsgs,0);
  106. fprintf(stderr,
  107. _("dpkg: %s: dependency problems, but configuring anyway as you request:\n%s"),
  108. pkg->name, aemsgs.buf);
  109. }
  110. varbuffree(&aemsgs);
  111. sincenothing= 0;
  112. if (pkg->eflag & eflagf_reinstreq)
  113. forcibleerr(fc_removereinstreq,
  114. _("Package is in a very bad inconsistent state - you should\n"
  115. " reinstall it before attempting configuration."));
  116. printf(_("Setting up %s (%s) ...\n"),pkg->name,
  117. versiondescribe(&pkg->installed.version,vdew_never));
  118. if (f_noact) {
  119. pkg->status= stat_installed;
  120. pkg->clientdata->istobe= itb_normal;
  121. return;
  122. }
  123. if (pkg->status == stat_unpacked) {
  124. debug(dbg_general,"deferred_configure updating conffiles");
  125. /* This will not do at all the right thing with overridden conffiles
  126. * or conffiles that are the `target' of an override; all the references
  127. * here would be to the `contested' filename, and in any case there'd
  128. * only be one hash for both `versions' of the conffile.
  129. *
  130. * Overriding conffiles is a silly thing to do anyway :-).
  131. */
  132. modstatdb_note(pkg);
  133. /* On entry, the `new' version of each conffile has been
  134. * unpacked as *.dpkg-new, and the `installed' version is
  135. * as-yet untouched in `*'. The hash of the `old distributed'
  136. * version is in the conffiles data for the package.
  137. * If `*.dpkg-new' no longer exists we assume that we've already
  138. * processed this one.
  139. */
  140. varbufinit(&cdr);
  141. varbufinit(&cdr2);
  142. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  143. r= conffderef(pkg, &cdr, conff->name);
  144. if (r == -1) {
  145. conff->hash= nfstrsave("-");
  146. continue;
  147. }
  148. md5hash(pkg,&currenthash,cdr.buf);
  149. varbufreset(&cdr2);
  150. varbufaddstr(&cdr2,cdr.buf);
  151. cdr2.used+=50; varbufaddc(&cdr2,0); cdr2rest= cdr2.buf+strlen(cdr.buf);
  152. /* From now on we can just strcpy(cdr2rest,extension); */
  153. strcpy(cdr2rest,DPKGNEWEXT);
  154. /* If the .dpkg-new file is no longer there, ignore this one. */
  155. if (lstat(cdr2.buf,&stab)) {
  156. if (errno == ENOENT) continue;
  157. ohshite(_("unable to stat new dist conffile `%.250s'"),cdr2.buf);
  158. }
  159. md5hash(pkg,&newdisthash,cdr2.buf);
  160. /* Copy the permissions from the installed version to the new
  161. * distributed version.
  162. */
  163. if (!stat(cdr.buf,&stab))
  164. copyfileperm(cdr.buf, cdr2.buf);
  165. else if (errno != ENOENT)
  166. ohshite(_("unable to stat current installed conffile `%.250s'"),cdr.buf);
  167. /* Select what the do */
  168. if (!strcmp(currenthash,newdisthash)) {
  169. /* They're both the same so there's no point asking silly questions. */
  170. useredited= -1;
  171. distedited= -1;
  172. what= cfo_identical;
  173. } else if (!strcmp(currenthash,NONEXISTENTFLAG) && fc_conff_miss) {
  174. fprintf(stderr, _("\nConfiguration file `%s', does not exist on system.\n"
  175. "Installing new config file as you request.\n"), conff->name);
  176. what= cfo_newconff;
  177. useredited= -1;
  178. distedited= -1;
  179. } else if (!strcmp(conff->hash,NEWCONFFILEFLAG)) {
  180. if (!strcmp(currenthash,NONEXISTENTFLAG)) {
  181. what= cfo_newconff;
  182. useredited= -1;
  183. distedited= -1;
  184. } else {
  185. useredited= 1;
  186. distedited= 1;
  187. what= conffoptcells[useredited][distedited] | cfof_isnew;
  188. }
  189. } else {
  190. useredited= strcmp(conff->hash,currenthash) != 0;
  191. distedited= strcmp(conff->hash,newdisthash) != 0;
  192. what= conffoptcells[useredited][distedited];
  193. }
  194. debug(dbg_conff,
  195. "deferred_configure `%s' (= `%s') useredited=%d distedited=%d what=%o",
  196. conff->name, cdr.buf, useredited, distedited, what);
  197. what=promptconfaction(conff->name, cdr.buf, cdr2.buf, useredited, distedited, what);
  198. switch (what & ~cfof_isnew) {
  199. case cfo_keep | cfof_backup:
  200. strcpy(cdr2rest,DPKGOLDEXT);
  201. if (unlink(cdr2.buf) && errno != ENOENT)
  202. fprintf(stderr,
  203. _("dpkg: %s: warning - failed to remove old backup `%.250s': %s\n"),
  204. pkg->name, cdr2.buf, strerror(errno));
  205. cdr.used--;
  206. varbufaddstr(&cdr,DPKGDISTEXT);
  207. varbufaddc(&cdr,0);
  208. strcpy(cdr2rest,DPKGNEWEXT);
  209. if (rename(cdr2.buf,cdr.buf))
  210. fprintf(stderr,
  211. _("dpkg: %s: warning - failed to rename `%.250s' to `%.250s': %s\n"),
  212. pkg->name, cdr2.buf, cdr.buf, strerror(errno));
  213. break;
  214. case cfo_keep:
  215. strcpy(cdr2rest,DPKGNEWEXT);
  216. if (unlink(cdr2.buf))
  217. fprintf(stderr,
  218. _("dpkg: %s: warning - failed to remove `%.250s': %s\n"),
  219. pkg->name, cdr2.buf, strerror(errno));
  220. break;
  221. case cfo_install | cfof_backup:
  222. strcpy(cdr2rest,DPKGDISTEXT);
  223. if (unlink(cdr2.buf) && errno != ENOENT)
  224. fprintf(stderr,
  225. _("dpkg: %s: warning - failed to remove old distrib version `%.250s': %s\n"),
  226. pkg->name, cdr2.buf, strerror(errno));
  227. strcpy(cdr2rest,DPKGOLDEXT);
  228. if (unlink(cdr2.buf) && errno != ENOENT)
  229. fprintf(stderr,
  230. _("dpkg: %s: warning - failed to remove `%.250s' (before overwrite): %s\n"),
  231. pkg->name, cdr2.buf, strerror(errno));
  232. if (link(cdr.buf,cdr2.buf))
  233. fprintf(stderr,
  234. _("dpkg: %s: warning - failed to link `%.250s' to `%.250s': %s\n"),
  235. pkg->name, cdr.buf, cdr2.buf, strerror(errno));
  236. /* fall through */
  237. case cfo_install:
  238. printf(_("Installing new version of config file %s ...\n"),conff->name);
  239. case cfo_newconff:
  240. strcpy(cdr2rest,DPKGNEWEXT);
  241. if (rename(cdr2.buf,cdr.buf))
  242. ohshite(_("unable to install `%.250s' as `%.250s'"),cdr2.buf,cdr.buf);
  243. break;
  244. default:
  245. internerr("unknown what");
  246. }
  247. conff->hash= nfstrsave(newdisthash);
  248. modstatdb_note(pkg);
  249. free(newdisthash);
  250. free(currenthash);
  251. } /* for (conff= ... */
  252. varbuffree(&cdr);
  253. varbuffree(&cdr2);
  254. pkg->status= stat_halfconfigured;
  255. }
  256. assert(pkg->status == stat_halfconfigured);
  257. modstatdb_note(pkg);
  258. if (maintainer_script_installed(pkg, POSTINSTFILE, "post-installation",
  259. "configure",
  260. informativeversion(&pkg->configversion)
  261. ? versiondescribe(&pkg->configversion,
  262. vdew_nonambig)
  263. : "",
  264. (char*)0))
  265. putchar('\n');
  266. pkg->status= stat_installed;
  267. pkg->eflag= eflagv_ok;
  268. modstatdb_note(pkg);
  269. }
  270. /* Dereference a file by following all possibly used symlinks.
  271. * Returns 0 if everything went ok, -1 otherwise.
  272. */
  273. int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in) {
  274. static char* linkreadbuf = 0;
  275. static int linkreadbufsize = 0;
  276. struct stat stab;
  277. int r, need;
  278. int loopprotect;
  279. varbufreset(result);
  280. varbufaddstr(result,instdir);
  281. if (*in != '/') varbufaddc(result,'/');
  282. varbufaddstr(result,in);
  283. varbufaddc(result,0);
  284. loopprotect= 0;
  285. for (;;) {
  286. debug(dbg_conffdetail,"conffderef in=`%s' current working=`%s'", in, result->buf);
  287. if (lstat(result->buf,&stab)) {
  288. if (errno != ENOENT)
  289. fprintf(stderr, _("dpkg: %s: warning - unable to stat config file `%s'\n"
  290. " (= `%s'): %s\n"),
  291. pkg->name, in, result->buf, strerror(errno));
  292. debug(dbg_conffdetail,"conffderef nonexistent");
  293. return 0;
  294. } else if (S_ISREG(stab.st_mode)) {
  295. debug(dbg_conff,"conffderef in=`%s' result=`%s'", in, result->buf);
  296. return 0;
  297. } else if (S_ISLNK(stab.st_mode)) {
  298. debug(dbg_conffdetail,"conffderef symlink loopprotect=%d",loopprotect);
  299. if (loopprotect++ >= 25) {
  300. fprintf(stderr, _("dpkg: %s: warning - config file `%s' is a circular link\n"
  301. " (= `%s')\n"), pkg->name, in, result->buf);
  302. return -1;
  303. }
  304. need= 255;
  305. for (;;) {
  306. if (need > linkreadbufsize) {
  307. linkreadbuf= m_realloc(linkreadbuf,need);
  308. linkreadbufsize= need;
  309. debug(dbg_conffdetail,"conffderef readlink realloc(%d)=%p",need,linkreadbuf);
  310. }
  311. r= readlink(result->buf,linkreadbuf,linkreadbufsize-1);
  312. if (r < 0) {
  313. fprintf(stderr, _("dpkg: %s: warning - unable to readlink conffile `%s'\n"
  314. " (= `%s'): %s\n"),
  315. pkg->name, in, result->buf, strerror(errno));
  316. return -1;
  317. }
  318. debug(dbg_conffdetail,"conffderef readlink gave %d, `%.*s'",
  319. r, r>0 ? r : 0, linkreadbuf);
  320. if (r < linkreadbufsize-1) break;
  321. need= r<<2;
  322. }
  323. linkreadbuf[r]= 0;
  324. if (linkreadbuf[0] == '/') {
  325. varbufreset(result);
  326. varbufaddstr(result,instdir);
  327. debug(dbg_conffdetail,"conffderef readlink absolute");
  328. } else {
  329. for (r=result->used-2; r>0 && result->buf[r] != '/'; r--)
  330. ;
  331. if (r < 0) {
  332. fprintf(stderr,
  333. _("dpkg: %s: warning - conffile `%.250s' resolves to degenerate filename\n"
  334. " (`%s' is a symlink to `%s')\n"),
  335. pkg->name, in, result->buf, linkreadbuf);
  336. return -1;
  337. }
  338. if (result->buf[r] == '/') r++;
  339. result->used= r;
  340. debug(dbg_conffdetail,"conffderef readlink relative to `%.*s'",
  341. (int)result->used, result->buf);
  342. }
  343. varbufaddstr(result,linkreadbuf);
  344. varbufaddc(result,0);
  345. } else {
  346. fprintf(stderr, _("dpkg: %s: warning - conffile `%.250s' is not a plain"
  347. " file or symlink (= `%s')\n"),
  348. pkg->name, in, result->buf);
  349. return -1;
  350. }
  351. }
  352. }
  353. /* Generate a MD5 hash for fn and store it in *hashbuf. Memory is allocated
  354. * by this function and should be freed manually.
  355. */
  356. static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn) {
  357. static int fd;
  358. fd=open(fn,O_RDONLY);
  359. if (fd>=0) {
  360. push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
  361. fd_md5(fd, hashbuf, -1, _("md5hash"));
  362. pop_cleanup(ehflag_normaltidy); /* fd= open(cdr.buf) */
  363. close(fd);
  364. } else if (errno==ENOENT) {
  365. *hashbuf= strdup(NONEXISTENTFLAG);
  366. } else {
  367. fprintf(stderr, _("dpkg: %s: warning - unable to open conffile %s for hash: %s\n"),
  368. pkg->name, fn, strerror(errno));
  369. *hashbuf= strdup("-");
  370. }
  371. }
  372. /* Copy file ownership and permissions from one file to another
  373. */
  374. static void copyfileperm(const char* source, const char* target) {
  375. struct stat stab;
  376. if (stat(source, &stab)==-1) {
  377. if (errno==ENOENT)
  378. return;
  379. ohshite(_("unable to stat current installed conffile `%.250s'"), source);
  380. }
  381. if (chown(target, stab.st_uid, stab.st_gid)==-1)
  382. ohshite(_("unable to change ownership of new dist conffile `%.250s'"), target);
  383. if (chmod(target, (stab.st_mode & 07777))==-1)
  384. ohshite(_("unable to set mode of new dist conffile `%.250s'"), target);
  385. }
  386. /* Show a diff between two files
  387. */
  388. static void showdiff(const char* old, const char* new) {
  389. int pid;
  390. int r;
  391. int status;
  392. if (!(pid=m_fork())) {
  393. /* Child process */
  394. const char* p; /* pager */
  395. const char* s; /* shell */
  396. char cmdbuf[1024]; /* command to run */
  397. p=getenv(PAGERENV);
  398. if (!p || !*p)
  399. p=DEFAULTPAGER;
  400. sprintf(cmdbuf, DIFF " -Nu %.250s %.250s | %.250s", old, new, p);
  401. s=getenv(SHELLENV);
  402. if (!s || !*s)
  403. s=DEFAULTSHELL;
  404. execlp(s,s,"-c", cmdbuf, NULL);
  405. ohshite(_("failed to run %s (%.250s)"), DIFF, cmdbuf);
  406. }
  407. /* Parent process */
  408. while (((r=waitpid(pid,&status,0))==-1) && (errno==EINTR))
  409. ;
  410. if (r!=pid) {
  411. onerr_abort++;
  412. ohshite(_("wait for shell failed"));
  413. }
  414. }
  415. /* Suspend dpkg temporarily
  416. */
  417. static void suspend(void) {
  418. const char* s;
  419. int pid;
  420. s= getenv(NOJOBCTRLSTOPENV);
  421. if (s && *s) {
  422. /* Do not job control to suspend but fork and start a new shell
  423. * instead.
  424. */
  425. int status; /* waitpid status */
  426. int r; /* waitpid result */
  427. fputs(_("Type `exit' when you're done.\n"), stderr);
  428. if (!(pid= m_fork())) {
  429. /* Child process */
  430. s= getenv(SHELLENV);
  431. if (!s || !*s)
  432. s=DEFAULTSHELL;
  433. execlp(s,s,"-i",(char*)0);
  434. ohshite(_("failed to exec shell (%.250s)"),s);
  435. }
  436. /* Parent process */
  437. while (((r=waitpid(pid,&status,0))==-1) && (errno==EINTR))
  438. ;
  439. if (r!=pid) {
  440. onerr_abort++;
  441. ohshite(_("wait for shell failed"));
  442. }
  443. } else {
  444. fputs(_("Don't forget to foreground (`fg') this "
  445. "process when you're done !\n"), stderr);
  446. kill(-getpgid(0),SIGTSTP);
  447. }
  448. }
  449. /* Select what to do with a configuration file.
  450. */
  451. static enum conffopt promptconfaction(const char* cfgfile, const char* realold,
  452. const char* realnew, int useredited, int distedited,
  453. enum conffopt what) {
  454. const char *s;
  455. int c, cc;
  456. if (!(what&cfof_prompt))
  457. return what;
  458. do {
  459. fprintf(stderr, _("\nConfiguration file `%s'"), cfgfile);
  460. if (strcmp(cfgfile, realold))
  461. fprintf(stderr,_(" (actually `%s')"), realold);
  462. if (what & cfof_isnew) {
  463. fprintf(stderr,
  464. _("\n"
  465. " ==> File on system created by you or by a script.\n"
  466. " ==> File also in package provided by package maintainer.\n"));
  467. } else {
  468. fprintf(stderr, useredited ?
  469. _("\n ==> Modified (by you or by a script) since installation.\n") :
  470. _("\n Not modified since installation.\n"));
  471. fprintf(stderr, distedited ?
  472. _(" ==> Package distributor has shipped an updated version.\n") :
  473. _(" Version in package is the same as at last installation.\n"));
  474. }
  475. /* No --force-confdef but a forcible situtation */
  476. /* TODO: check if this condition can not be simplified to just !fc_conff_def */
  477. if (!(fc_conff_def && (what&(cfof_install|cfof_keep)))) {
  478. if (fc_conff_new) {
  479. fprintf(stderr, _(" ==> Using new file as you requested.\n"));
  480. cc = 'y';
  481. break;
  482. } else if (fc_conff_old) {
  483. fprintf(stderr, _(" ==> Using current old file as you requested.\n"));
  484. cc = 'n';
  485. break;
  486. }
  487. }
  488. /* Force the default action (if there is one */
  489. if (fc_conff_def) {
  490. if (what&cfof_keep) {
  491. fprintf(stderr, _(" ==> Keeping old config file as default.\n"));
  492. cc = 'n';
  493. break;
  494. } else if (what&cfof_install) {
  495. fprintf(stderr, _(" ==> Using new config file as default.\n"));
  496. cc = 'y';
  497. break;
  498. }
  499. }
  500. fprintf(stderr,
  501. _(" What would you like to do about it ? Your options are:\n"
  502. " Y or I : install the package maintainer's version\n"
  503. " N or O : keep your currently-installed version\n"
  504. " D : show the differences between the versions\n"
  505. " Z : background this process to examine the situation\n"));
  506. if (what & cfof_keep)
  507. fprintf(stderr, _(" The default action is to keep your current version.\n"));
  508. else if (what & cfof_install)
  509. fprintf(stderr, _(" The default action is to install the new version.\n"));
  510. s= strrchr(cfgfile,'/');
  511. if (!s || !*++s) s= cfgfile;
  512. fprintf(stderr, "*** %s (Y/I/N/O/D/Z) %s ? ",
  513. s,
  514. (what & cfof_keep) ? _("[default=N]") :
  515. (what & cfof_install) ? _("[default=Y]") : _("[no default]"));
  516. if (ferror(stderr))
  517. ohshite(_("error writing to stderr, discovered before conffile prompt"));
  518. cc= 0;
  519. while ((c= getchar()) != EOF && c != '\n')
  520. if (!isspace(c) && !cc) cc= tolower(c);
  521. if (c == EOF) {
  522. if (ferror(stdin)) ohshite(_("read error on stdin at conffile prompt"));
  523. ohshit(_("EOF on stdin at conffile prompt"));
  524. }
  525. if (!cc) {
  526. if (what & cfof_keep) { cc= 'n'; break; }
  527. else if (what & cfof_install) { cc= 'y'; break; }
  528. }
  529. /* fixme: say something if silently not install */
  530. if (cc == 'd')
  531. showdiff(realold, realnew);
  532. if (cc == 'z')
  533. suspend();
  534. } while (!strchr("yino",cc));
  535. switch (cc) {
  536. case 'i':
  537. case 'y':
  538. what=cfof_install|cfof_backup;
  539. break;
  540. case 'n':
  541. case 'o':
  542. what=cfof_keep|cfof_backup;
  543. break;
  544. default:
  545. internerr("unknown response");
  546. }
  547. return what;
  548. }