summaryrefslogtreecommitdiff
path: root/src/errors.c
blob: 309f79343a31e664ed14bf1131925690148b69fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * dpkg - main program for package management
 * main.c - main program
 *
 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with dpkg; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <config.h>
#include <compat.h>

#include <dpkg/i18n.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <ctype.h>

#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
#include <dpkg/myopt.h>

#include "main.h"

int abort_processing = 0;

static int nerrs = 0;

struct error_report {
  struct error_report *next;
  const char *what;
};

static struct error_report *reports = NULL;
static struct error_report **lastreport= &reports;
static struct error_report emergency;

void print_error_perpackage(const char *emsg, const char *arg) {
  struct error_report *nr;
  
  fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
          DPKG, arg, cipaction->olong, emsg);

  statusfd_send("status: %s : %s : %s", arg, "error", emsg);

  nr= malloc(sizeof(struct error_report));
  if (!nr) {
    perror(_("dpkg: failed to allocate memory for new entry in list of failed packages."));
    abort_processing = 1;
    nr= &emergency;
  }
  nr->what= arg;
  nr->next = NULL;
  *lastreport= nr;
  lastreport= &nr->next;
    
  if (nerrs++ < errabort) return;
  fprintf(stderr, _("dpkg: too many errors, stopping\n"));
  abort_processing = 1;
}

int reportbroken_retexitstatus(void) {
  if (reports) {
    fputs(_("Errors were encountered while processing:\n"),stderr);
    while (reports) {
      fprintf(stderr," %s\n",reports->what);
      reports= reports->next;
    }
  }
  if (abort_processing) {
    fputs(_("Processing was halted because there were too many errors.\n"),stderr);
  }
  return nerrs ? 1 : 0;
}

int skip_due_to_hold(struct pkginfo *pkg) {
  if (pkg->want != want_hold) return 0;
  if (fc_hold) {
    fprintf(stderr, _("Package %s was on hold, processing it anyway as you requested\n"),
            pkg->name);
    return 0;
  }
  printf(_("Package %s is on hold, not touching it.  Use --force-hold to override.\n"),
         pkg->name);
  return 1;
}

void forcibleerr(int forceflag, const char *fmt, ...) {
  va_list al;
  va_start(al,fmt);
  if (forceflag) {
    warning(_("overriding problem because --force enabled:"));
    fputc(' ', stderr);
    vfprintf(stderr,fmt,al);
    fputc('\n',stderr);
  } else {
    ohshitv(fmt,al);
  }
  va_end(al);
}