configure.c 20 KB

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