configure.c 20 KB

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