controllib.pl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use English;
  5. use POSIX qw(:errno_h);
  6. our $dpkglibdir;
  7. our $pkgdatadir;
  8. push(@INC,$dpkglibdir);
  9. require 'dpkg-gettext.pl';
  10. textdomain("dpkg-dev");
  11. our $sourcepackage; # - name of sourcepackage
  12. our %f; # - fields ???
  13. our %fi; # - map of fields values. keys are of the form "S# key"
  14. # where S is source (L is changelog, C is control)
  15. # and # is an index
  16. our %fieldimps;
  17. our %p2i; # - map from datafile+packagename to index in controlfile
  18. # (used if multiple packages can be listed). Key is
  19. # "S key" where S is the source and key is the packagename
  20. my $maxsubsts = 50;
  21. our %substvar; # - map with substitution variables
  22. my $parsechangelog = 'dpkg-parsechangelog';
  23. our @pkg_dep_fields = qw(Pre-Depends Depends Recommends Suggests Enhances
  24. Conflicts Replaces Provides);
  25. our @src_dep_fields = qw(Build-Depends Build-Depends-Indep
  26. Build-Conflicts Build-Conflicts-Indep);
  27. our $warnable_error = 1;
  28. our $quiet_warnings = 0;
  29. our $version;
  30. our $progname = $0;
  31. $progname = $& if $progname =~ m,[^/]+$,;
  32. sub getfowner
  33. {
  34. my $getlogin = getlogin();
  35. if (!defined($getlogin)) {
  36. open(SAVEIN, "<&STDIN");
  37. open(STDIN, "<&STDERR");
  38. $getlogin = getlogin();
  39. close(STDIN);
  40. open(STDIN, "<&SAVEIN");
  41. close(SAVEIN);
  42. }
  43. if (!defined($getlogin)) {
  44. open(SAVEIN, "<&STDIN");
  45. open(STDIN, "<&STDOUT");
  46. $getlogin = getlogin();
  47. close(STDIN);
  48. open(STDIN, "<&SAVEIN");
  49. close(SAVEIN);
  50. }
  51. my @fowner;
  52. if (defined($ENV{'LOGNAME'})) {
  53. @fowner = getpwnam($ENV{'LOGNAME'});
  54. if (!@fowner) {
  55. die(sprintf(_g('unable to get login information for username "%s"'), $ENV{'LOGNAME'}));
  56. }
  57. } elsif (defined($getlogin)) {
  58. @fowner = getpwnam($getlogin);
  59. if (!@fowner) {
  60. die(sprintf(_g('unable to get login information for username "%s"'), $getlogin));
  61. }
  62. } else {
  63. warning(sprintf(_g('no utmp entry available and LOGNAME not defined; using uid of process (%d)'), $<));
  64. @fowner = getpwuid($<);
  65. if (!@fowner) {
  66. die (sprintf(_g('unable to get login information for uid %d'), $<));
  67. }
  68. }
  69. @fowner = @fowner[2,3];
  70. return @fowner;
  71. }
  72. sub capit {
  73. my @pieces = map { ucfirst(lc) } split /-/, $_[0];
  74. return join '-', @pieces;
  75. }
  76. #
  77. # Architecture library
  78. #
  79. my (@cpu, @os);
  80. my (%cputable, %ostable);
  81. my (%cputable_re, %ostable_re);
  82. my %debtriplet_to_debarch;
  83. my %debarch_to_debtriplet;
  84. {
  85. my $host_arch;
  86. sub get_host_arch()
  87. {
  88. return $host_arch if defined $host_arch;
  89. $host_arch = `dpkg-architecture -qDEB_HOST_ARCH`;
  90. $? && subprocerr("dpkg-architecture -qDEB_HOST_ARCH");
  91. chomp $host_arch;
  92. return $host_arch;
  93. }
  94. }
  95. sub get_valid_arches()
  96. {
  97. read_cputable() if (!@cpu);
  98. read_ostable() if (!@os);
  99. foreach my $os (@os) {
  100. foreach my $cpu (@cpu) {
  101. my $arch = debtriplet_to_debarch(split(/-/, $os, 2), $cpu);
  102. print $arch."\n" if defined($arch);
  103. }
  104. }
  105. }
  106. sub read_cputable
  107. {
  108. open CPUTABLE, "$pkgdatadir/cputable"
  109. or syserr(_g("unable to open cputable"));
  110. while (<CPUTABLE>) {
  111. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  112. $cputable{$1} = $2;
  113. $cputable_re{$1} = $3;
  114. push @cpu, $1;
  115. }
  116. }
  117. close CPUTABLE;
  118. }
  119. sub read_ostable
  120. {
  121. open OSTABLE, "$pkgdatadir/ostable"
  122. or syserr(_g("unable to open ostable"));
  123. while (<OSTABLE>) {
  124. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  125. $ostable{$1} = $2;
  126. $ostable_re{$1} = $3;
  127. push @os, $1;
  128. }
  129. }
  130. close OSTABLE;
  131. }
  132. sub read_triplettable()
  133. {
  134. read_cputable() if (!@cpu);
  135. open TRIPLETTABLE, "$pkgdatadir/triplettable"
  136. or syserr(_g("unable to open triplettable"));
  137. while (<TRIPLETTABLE>) {
  138. if (m/^(?!\#)(\S+)\s+(\S+)/) {
  139. my $debtriplet = $1;
  140. my $debarch = $2;
  141. if ($debtriplet =~ /<cpu>/) {
  142. foreach my $_cpu (@cpu) {
  143. (my $dt = $debtriplet) =~ s/<cpu>/$_cpu/;
  144. (my $da = $debarch) =~ s/<cpu>/$_cpu/;
  145. $debarch_to_debtriplet{$da} = $dt;
  146. $debtriplet_to_debarch{$dt} = $da;
  147. }
  148. } else {
  149. $debarch_to_debtriplet{$2} = $1;
  150. $debtriplet_to_debarch{$1} = $2;
  151. }
  152. }
  153. }
  154. close TRIPLETTABLE;
  155. }
  156. sub debtriplet_to_gnutriplet(@)
  157. {
  158. read_cputable() if (!@cpu);
  159. read_ostable() if (!@os);
  160. my ($abi, $os, $cpu) = @_;
  161. return undef unless defined($abi) && defined($os) && defined($cpu) &&
  162. exists($cputable{$cpu}) && exists($ostable{"$abi-$os"});
  163. return join("-", $cputable{$cpu}, $ostable{"$abi-$os"});
  164. }
  165. sub gnutriplet_to_debtriplet($)
  166. {
  167. my ($gnu) = @_;
  168. return undef unless defined($gnu);
  169. my ($gnu_cpu, $gnu_os) = split(/-/, $gnu, 2);
  170. return undef unless defined($gnu_cpu) && defined($gnu_os);
  171. read_cputable() if (!@cpu);
  172. read_ostable() if (!@os);
  173. my ($os, $cpu);
  174. foreach my $_cpu (@cpu) {
  175. if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
  176. $cpu = $_cpu;
  177. last;
  178. }
  179. }
  180. foreach my $_os (@os) {
  181. if ($gnu_os =~ /^(.*-)?$ostable_re{$_os}$/) {
  182. $os = $_os;
  183. last;
  184. }
  185. }
  186. return undef if !defined($cpu) || !defined($os);
  187. return (split(/-/, $os, 2), $cpu);
  188. }
  189. sub debtriplet_to_debarch(@)
  190. {
  191. read_triplettable() if (!%debtriplet_to_debarch);
  192. my ($abi, $os, $cpu) = @_;
  193. if (!defined($abi) || !defined($os) || !defined($cpu)) {
  194. return undef;
  195. } elsif (exists $debtriplet_to_debarch{"$abi-$os-$cpu"}) {
  196. return $debtriplet_to_debarch{"$abi-$os-$cpu"};
  197. } else {
  198. return undef;
  199. }
  200. }
  201. sub debarch_to_debtriplet($)
  202. {
  203. read_triplettable() if (!%debarch_to_debtriplet);
  204. local ($_) = @_;
  205. if (/any/ || /all/) {
  206. return ($_, $_, $_);
  207. } elsif (/^([^-]*)-([^-]*)-(.*)/) {
  208. return ($1, $2, $3);
  209. } else {
  210. my $triplet = $debarch_to_debtriplet{$_};
  211. if (defined($triplet)) {
  212. return split('-', $triplet, 3);
  213. } else {
  214. return undef;
  215. }
  216. }
  217. }
  218. sub debian_arch_eq {
  219. my ($a, $b) = @_;
  220. my ($a_abi, $a_os, $a_cpu) = debarch_to_debtriplet($a);
  221. my ($b_abi, $b_os, $b_cpu) = debarch_to_debtriplet($b);
  222. return ("$a_abi-$a_os-$a_cpu" eq "$b_abi-$b_os-$b_cpu");
  223. }
  224. sub debian_arch_is {
  225. my ($real, $alias) = @_;
  226. my ($real_abi, $real_os, $real_cpu) = debarch_to_debtriplet($real);
  227. my ($alias_abi, $alias_os, $alias_cpu) = debarch_to_debtriplet($alias);
  228. if ("$real_abi-$real_os-$real_cpu" eq "$alias_abi-$alias_os-$alias_cpu") {
  229. return 1;
  230. } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "any-any-any") {
  231. return 1;
  232. } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "$real_abi-any-$real_cpu") {
  233. return 1;
  234. } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "$real_abi-$real_os-any") {
  235. return 1;
  236. }
  237. return 0;
  238. }
  239. sub substvars {
  240. my ($v) = @_;
  241. my $lhs;
  242. my $vn;
  243. my $rhs = '';
  244. my $count = 0;
  245. while ($v =~ m/\$\{([-:0-9a-z]+)\}/i) {
  246. # If we have consumed more from the leftover data, then
  247. # reset the recursive counter.
  248. $count= 0 if (length($POSTMATCH) < length($rhs));
  249. $count < $maxsubsts ||
  250. &error(sprintf(_g("too many substitutions - recursive ? - in \`%s'"), $v));
  251. $lhs=$`; $vn=$1; $rhs=$';
  252. if (defined($substvar{$vn})) {
  253. $v= $lhs.$substvar{$vn}.$rhs;
  254. $count++;
  255. } else {
  256. warning(sprintf(_g("unknown substitution variable \${%s}"), $vn));
  257. $v= $lhs.$rhs;
  258. }
  259. }
  260. return $v;
  261. }
  262. sub set_field_importance(@)
  263. {
  264. my @fields = @_;
  265. my $i = 1;
  266. grep($fieldimps{$_} = $i++, @fields);
  267. }
  268. sub sort_field_by_importance($$)
  269. {
  270. my ($a, $b) = @_;
  271. if (defined $fieldimps{$a} && defined $fieldimps{$b}) {
  272. $fieldimps{$a} <=> $fieldimps{$b};
  273. } elsif (defined($fieldimps{$a})) {
  274. -1;
  275. } elsif (defined($fieldimps{$b})) {
  276. 1;
  277. } else {
  278. $a cmp $b;
  279. }
  280. }
  281. sub outputclose {
  282. my ($varlistfile) = @_;
  283. for my $f (keys %f) {
  284. $substvar{"F:$f"} = $f{$f};
  285. }
  286. &parsesubstvars($varlistfile) if (defined($varlistfile));
  287. for my $f (sort sort_field_by_importance keys %f) {
  288. my $v = $f{$f};
  289. if (defined($varlistfile)) {
  290. $v= &substvars($v);
  291. }
  292. $v =~ m/\S/ || next; # delete whitespace-only fields
  293. $v =~ m/\n\S/ && &internerr(sprintf(_g("field %s has newline then non whitespace >%s<"), $f, $v));
  294. $v =~ m/\n[ \t]*\n/ && &internerr(sprintf(_g("field %s has blank lines >%s<"), $f, $v));
  295. $v =~ m/\n$/ && &internerr(sprintf(_g("field %s has trailing newline >%s<"), $f, $v));
  296. if (defined($varlistfile)) {
  297. $v =~ s/,[\s,]*,/,/g;
  298. $v =~ s/^\s*,\s*//;
  299. $v =~ s/\s*,\s*$//;
  300. }
  301. $v =~ s/\$\{\}/\$/g;
  302. print("$f: $v\n") || &syserr(_g("write error on control data"));
  303. }
  304. close(STDOUT) || &syserr(_g("write error on close control data"));
  305. }
  306. sub parsecontrolfile {
  307. my $controlfile = shift;
  308. $controlfile="./$controlfile" if $controlfile =~ m/^\s/;
  309. open(CDATA,"< $controlfile") || &error(sprintf(_g("cannot read control file %s: %s"), $controlfile, $!));
  310. binmode(CDATA);
  311. my $indices = parsecdata(\*CDATA, 'C', 1,
  312. sprintf(_g("control file %s"), $controlfile));
  313. $indices >= 2 || &error(_g("control file must have at least one binary package part"));
  314. for (my $i = 1; $i < $indices; $i++) {
  315. defined($fi{"C$i Package"}) ||
  316. &error(sprintf(_g("per-package paragraph %d in control ".
  317. "info file is missing Package line"),
  318. $i));
  319. }
  320. defined($fi{"C Source"}) ||
  321. &error(_g("source paragraph in control info file is ".
  322. "missing Source line"));
  323. }
  324. my $substvarsparsed = 0;
  325. sub parsesubstvars {
  326. my $varlistfile = shift;
  327. if (length($varlistfile) && !$substvarsparsed) {
  328. $varlistfile="./$varlistfile" if $varlistfile =~ m/\s/;
  329. if (open(SV,"< $varlistfile")) {
  330. binmode(SV);
  331. while (<SV>) {
  332. next if m/^\#/ || !m/\S/;
  333. s/\s*\n$//;
  334. m/^(\w[-:0-9A-Za-z]*)\=/ ||
  335. &error(sprintf(_g("bad line in substvars file %s at line %d"),
  336. $varlistfile, $.));
  337. $substvar{$1}= $';
  338. }
  339. close(SV);
  340. } elsif ($! != ENOENT ) {
  341. &error(sprintf(_g("unable to open substvars file %s: %s"),
  342. $varlistfile, $!));
  343. }
  344. $substvarsparsed = 1;
  345. }
  346. }
  347. sub parsedep {
  348. my ($dep_line, $use_arch, $reduce_arch) = @_;
  349. my @dep_list;
  350. my $host_arch = get_host_arch();
  351. foreach my $dep_and (split(/,\s*/m, $dep_line)) {
  352. my @or_list = ();
  353. ALTERNATE:
  354. foreach my $dep_or (split(/\s*\|\s*/m, $dep_and)) {
  355. my ($package, $relation, $version);
  356. $package = $1 if ($dep_or =~ s/^([a-zA-Z0-9][a-zA-Z0-9+._-]*)\s*//m);
  357. ($relation, $version) = ($1, $2)
  358. if ($dep_or =~ s/^\(\s*(=|<=|>=|<<?|>>?)\s*([^)]+).*\)\s*//m);
  359. my @arches;
  360. @arches = split(/\s+/m, $1) if ($use_arch && $dep_or =~ s/^\[([^]]+)\]\s*//m);
  361. if ($reduce_arch && @arches) {
  362. my $seen_arch='';
  363. foreach my $arch (@arches) {
  364. $arch=lc($arch);
  365. if (debian_arch_is($host_arch, $arch)) {
  366. $seen_arch=1;
  367. next;
  368. } elsif ($arch =~ /^!/) {
  369. my $not_arch;
  370. ($not_arch = $arch) =~ s/^!//;
  371. if (debian_arch_is($host_arch, $not_arch)) {
  372. next ALTERNATE;
  373. } else {
  374. # This is equivilant to
  375. # having seen the current arch,
  376. # unless the current arch
  377. # is also listed..
  378. $seen_arch=1;
  379. }
  380. }
  381. }
  382. if (! $seen_arch) {
  383. next;
  384. }
  385. }
  386. if (length($dep_or)) {
  387. warning(sprintf(_g("can't parse dependency %s"), $dep_and));
  388. return undef;
  389. }
  390. push @or_list, [ $package, $relation, $version, \@arches ];
  391. }
  392. push @dep_list, \@or_list;
  393. }
  394. \@dep_list;
  395. }
  396. sub showdep {
  397. my ($dep_list, $show_arch) = @_;
  398. my @and_list;
  399. foreach my $dep_and (@$dep_list) {
  400. my @or_list = ();
  401. foreach my $dep_or (@$dep_and) {
  402. my ($package, $relation, $version, $arch_list) = @$dep_or;
  403. push @or_list, $package . ($relation && $version ? " ($relation $version)" : '') . ($show_arch && @$arch_list ? " [@$arch_list]" : '');
  404. }
  405. push @and_list, join(' | ', @or_list);
  406. }
  407. join(', ', @and_list);
  408. }
  409. sub parsechangelog {
  410. my ($changelogfile, $changelogformat, $since) = @_;
  411. defined(my $c = open(CDATA, "-|")) || syserr(_g("fork for parse changelog"));
  412. if ($c) {
  413. binmode(CDATA);
  414. parsecdata(\*CDATA, 'L', 0, _g("parsed version of changelog"));
  415. close(CDATA);
  416. $? && subprocerr(_g("parse changelog"));
  417. } else {
  418. binmode(STDOUT);
  419. my @al = ($parsechangelog);
  420. push(@al,"-l$changelogfile");
  421. push(@al, "-F$changelogformat") if defined($changelogformat);
  422. push(@al, "-v$since") if defined($since);
  423. exec(@al) || &syserr("exec parsechangelog $parsechangelog");
  424. }
  425. }
  426. sub init_substvars
  427. {
  428. $substvar{'Format'} = 1.7;
  429. $substvar{'Newline'} = "\n";
  430. $substvar{'Space'} = " ";
  431. $substvar{'Tab'} = "\t";
  432. # XXX: Source-Version is now deprecated, remove in the future.
  433. $substvar{'Source-Version'}= $fi{"L Version"};
  434. $substvar{'binary:Version'} = $fi{"L Version"};
  435. $substvar{'source:Version'} = $fi{"L Version"};
  436. $substvar{'source:Version'} =~ s/\+b[0-9]+$//;
  437. $substvar{'source:Upstream-Version'} = $fi{"L Version"};
  438. $substvar{'source:Upstream-Version'} =~ s/-[^-]*$//;
  439. # FIXME: this needs all progs using controllib to set $version as 'our'.
  440. # We expect the calling program to set $version.
  441. $substvar{"dpkg:Version"} = $version;
  442. $substvar{"dpkg:Upstream-Version"} = $version;
  443. $substvar{"dpkg:Upstream-Version"} =~ s/-[^-]+$//;
  444. }
  445. sub init_substvar_arch()
  446. {
  447. $substvar{'Arch'} = get_host_arch();
  448. }
  449. sub checkpackagename {
  450. my $name = shift || '';
  451. $name =~ m/[^-+.0-9a-z]/o &&
  452. &error(sprintf(_g("source package name `%s' contains illegal character `%s'"), $name, $&));
  453. $name =~ m/^[0-9a-z]/o ||
  454. &error(sprintf(_g("source package name `%s' starts with non-alphanum"), $name));
  455. }
  456. sub checkversion {
  457. my $version = shift || '';
  458. $version =~ m/[^-+:.0-9a-zA-Z~]/o &&
  459. &error(sprintf(_g("version number contains illegal character `%s'"), $&));
  460. }
  461. sub setsourcepackage {
  462. my $v = shift;
  463. checkpackagename( $v );
  464. if (defined($sourcepackage)) {
  465. $v eq $sourcepackage ||
  466. &error(sprintf(_g("source package has two conflicting values - %s and %s"), $sourcepackage, $v));
  467. } else {
  468. $sourcepackage= $v;
  469. }
  470. }
  471. sub readmd5sum {
  472. (my $md5sum = shift) or return;
  473. $md5sum =~ s/^([0-9a-f]{32})\s*\*?-?\s*\n?$/$1/o
  474. || &failure(sprintf(_g("md5sum gave bogus output `%s'"), $md5sum));
  475. return $md5sum;
  476. }
  477. # XXX: Should not be a global!!
  478. my $whatmsg;
  479. sub parsecdata {
  480. my ($cdata, $source, $many);
  481. ($cdata, $source, $many, $whatmsg) = @_;
  482. # many=0: ordinary control data like output from dpkg-parsechangelog
  483. # many=1: many paragraphs like in source control file
  484. # many=-1: single paragraph of control data optionally signed
  485. my $index = '';
  486. my $cf = '';
  487. my $paraborder = 1;
  488. while (<$cdata>) {
  489. s/\s*\n$//;
  490. next if (m/^$/ and $paraborder);
  491. next if (m/^#/);
  492. $paraborder=0;
  493. if (m/^(\S+)\s*:\s*(.*)$/) {
  494. $cf = $1;
  495. my $v = $2;
  496. $cf= &capit($cf);
  497. $fi{"$source$index $cf"}= $v;
  498. $fi{"o:$source$index $cf"}= $1;
  499. if (lc $cf eq 'package') { $p2i{"$source $v"}= $index; }
  500. } elsif (m/^\s+\S/) {
  501. length($cf) || &syntax(_g("continued value line not in field"));
  502. $fi{"$source$index $cf"}.= "\n$_";
  503. } elsif (m/^-----BEGIN PGP/ && $many<0) {
  504. $many == -2 && syntax(_g("expected blank line before PGP signature"));
  505. while (<$cdata>) {
  506. last if m/^$/;
  507. }
  508. $many= -2;
  509. } elsif (m/^$/) {
  510. $paraborder = 1;
  511. if ($many>0) {
  512. $index++; $cf='';
  513. } elsif ($many == -2) {
  514. $_ = <$cdata> while defined($_) && $_ =~ /^\s*$/;
  515. length($_) ||
  516. &syntax(_g("expected PGP signature, found EOF after blank line"));
  517. s/\n$//;
  518. m/^-----BEGIN PGP/ ||
  519. &syntax(sprintf(_g("expected PGP signature, found something else \`%s'"), $_));
  520. $many= -3; last;
  521. } else {
  522. while (<$cdata>) {
  523. /^\s*$/ ||
  524. &syntax(_g("found several \`paragraphs' where only one expected"));
  525. }
  526. }
  527. } else {
  528. &syntax(_g("line with unknown format (not field-colon-value)"));
  529. }
  530. }
  531. $many == -2 && &syntax(_g("found start of PGP body but no signature"));
  532. if (length($cf)) { $index++; }
  533. $index || &syntax(_g("empty file"));
  534. return $index;
  535. }
  536. sub unknown {
  537. my $field = $_;
  538. warning(sprintf(_g("unknown information field '%s' in input data in %s"),
  539. $field, $_[0]));
  540. }
  541. sub syntax {
  542. &error(sprintf(_g("syntax error in %s at line %d: %s"), $whatmsg, $., $_[0]));
  543. }
  544. sub failure { die sprintf(_g("%s: failure: %s"), $progname, $_[0])."\n"; }
  545. sub syserr { die sprintf(_g("%s: failure: %s: %s"), $progname, $_[0], $!)."\n"; }
  546. sub error { die sprintf(_g("%s: error: %s"), $progname, $_[0])."\n"; }
  547. sub internerr { die sprintf(_g("%s: internal error: %s"), $progname, $_[0])."\n"; }
  548. sub warning
  549. {
  550. if (!$quiet_warnings) {
  551. warn sprintf(_g("%s: warning: %s"), $progname, $_[0])."\n";
  552. }
  553. }
  554. sub usageerr
  555. {
  556. printf(STDERR "%s: %s\n\n", $progname, "@_");
  557. &usage;
  558. exit(2);
  559. }
  560. sub warnerror
  561. {
  562. if ($warnable_error) {
  563. warning(@_);
  564. } else {
  565. error(@_);
  566. }
  567. }
  568. sub subprocerr {
  569. my ($p) = @_;
  570. require POSIX;
  571. if (POSIX::WIFEXITED($?)) {
  572. die sprintf(_g("%s: failure: %s gave error exit status %s"),
  573. $progname, $p, POSIX::WEXITSTATUS($?))."\n";
  574. } elsif (POSIX::WIFSIGNALED($?)) {
  575. die sprintf(_g("%s: failure: %s died from signal %s"),
  576. $progname, $p, POSIX::WTERMSIG($?))."\n";
  577. } else {
  578. die sprintf(_g("%s: failure: %s failed with unknown exit code %d"),
  579. $progname, $p, $?)."\n";
  580. }
  581. }
  582. 1;