configure.c 21 KB

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