configure.c 19 KB

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