Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 632198
Collapse All | Expand All

(-)filter/foomatic-rip/foomaticrip.c (-2 / +3 lines)
Lines 517-523 Link Here
517
    while (isspace(*p++) && left-- > 0)
517
    while (isspace(*p++) && left-- > 0)
518
        ;
518
        ;
519
519
520
    fwrite((void *)p, left, 1, postpipe);
520
    fwrite_or_die((void *)p, left, 1, postpipe);
521
    fflush(postpipe);
521
    fflush(postpipe);
522
}
522
}
523
523
Lines 572-578 Link Here
572
        }
572
        }
573
    }
573
    }
574
574
575
    n = fread(buf, 1, sizeof(buf) - 1, file);
575
    n = fread_or_die(buf, 1, sizeof(buf) - 1, file);
576
    buf[n] = '\0';
576
    buf[n] = '\0';
577
    type = guess_file_type(buf, n, &startpos);
577
    type = guess_file_type(buf, n, &startpos);
578
    /* We do not use any JCL preceeded to the inputr data, as it is simply
578
    /* We do not use any JCL preceeded to the inputr data, as it is simply
Lines 745-750 Link Here
745
745
746
    signal(SIGTERM, signal_terminate);
746
    signal(SIGTERM, signal_terminate);
747
    signal(SIGINT, signal_terminate);
747
    signal(SIGINT, signal_terminate);
748
    signal(SIGPIPE, SIG_IGN);
748
749
749
750
750
    config_from_file(CONFIG_PATH "/filter.conf");
751
    config_from_file(CONFIG_PATH "/filter.conf");
(-)filter/foomatic-rip/pdf.c (-1 / +1 lines)
Lines 56-62 Link Here
56
    if (!pd)
56
    if (!pd)
57
      rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n");
57
      rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n");
58
58
59
    bytes = fread(output, 1, 31, pd);
59
    bytes = fread_or_die(output, 1, 31, pd);
60
    pclose(pd);
60
    pclose(pd);
61
61
62
    if (bytes <= 0 || sscanf(output, "PageCount: %d", &pagecount) < 1)
62
    if (bytes <= 0 || sscanf(output, "PageCount: %d", &pagecount) < 1)
(-)filter/foomatic-rip/postscript.c (-6 / +6 lines)
Lines 1032-1045 Link Here
1032
1032
1033
                    if (!isempty(psfifo->data)) {
1033
                    if (!isempty(psfifo->data)) {
1034
                        /* Send psfifo to renderer */
1034
                        /* Send psfifo to renderer */
1035
                        fwrite(psfifo->data, psfifo->len, 1, rendererhandle);
1035
                        fwrite_or_die(psfifo->data, psfifo->len, 1, rendererhandle);
1036
                        /* flush psfifo */
1036
                        /* flush psfifo */
1037
                        dstrclear(psfifo);
1037
                        dstrclear(psfifo);
1038
                    }
1038
                    }
1039
1039
1040
                    /* Send line to renderer */
1040
                    /* Send line to renderer */
1041
                    if (!printprevpage) {
1041
                    if (!printprevpage) {
1042
                        fwrite(line->data, line->len, 1, rendererhandle);
1042
                        fwrite_or_die(line->data, line->len, 1, rendererhandle);
1043
1043
1044
                        while (stream_next_line(line, stream) > 0) {
1044
                        while (stream_next_line(line, stream) > 0) {
1045
                            if (startswith(line->data, "%%")) {
1045
                            if (startswith(line->data, "%%")) {
Lines 1049-1055 Link Here
1049
                                break;
1049
                                break;
1050
                            }
1050
                            }
1051
                            else {
1051
                            else {
1052
                                fwrite(line->data, line->len, 1, rendererhandle);
1052
                                fwrite_or_die(line->data, line->len, 1, rendererhandle);
1053
                                linect++;
1053
                                linect++;
1054
                            }
1054
                            }
1055
                        }
1055
                        }
Lines 1141-1154 Link Here
1141
1141
1142
        if (psfifo->len) {
1142
        if (psfifo->len) {
1143
            /* Send psfifo to the renderer */
1143
            /* Send psfifo to the renderer */
1144
            fwrite(psfifo->data, psfifo->len, 1, rendererhandle);
1144
            fwrite_or_die(psfifo->data, psfifo->len, 1, rendererhandle);
1145
            dstrclear(psfifo);
1145
            dstrclear(psfifo);
1146
        }
1146
        }
1147
1147
1148
        /* Print the rest of the input data */
1148
        /* Print the rest of the input data */
1149
        if (more_stuff) {
1149
        if (more_stuff) {
1150
            while (stream_next_line(tmp, stream))
1150
            while (stream_next_line(tmp, stream))
1151
                fwrite(tmp->data, tmp->len, 1, rendererhandle);
1151
                fwrite_or_die(tmp->data, tmp->len, 1, rendererhandle);
1152
        }
1152
        }
1153
    }
1153
    }
1154
1154
Lines 1197-1203 Link Here
1197
1197
1198
    /* Feed the PostScript header and the FIFO contents */
1198
    /* Feed the PostScript header and the FIFO contents */
1199
    if (prepend)
1199
    if (prepend)
1200
        fwrite(prepend->data, prepend->len, 1, kid3in);
1200
        fwrite_or_die(prepend->data, prepend->len, 1, kid3in);
1201
1201
1202
    /* We are the parent, return glob to the file handle */
1202
    /* We are the parent, return glob to the file handle */
1203
    *fd = kid3in;
1203
    *fd = kid3in;
(-)filter/foomatic-rip/process.c (-1 / +5 lines)
Lines 125-130 Link Here
125
    }
125
    }
126
126
127
    if (pid == 0) { /* Child */
127
    if (pid == 0) { /* Child */
128
129
        // Reset sigpipe behavior to default for all children
130
        signal(SIGPIPE, SIG_DFL);
131
128
        if (pipe_in) {
132
        if (pipe_in) {
129
            close(pfdin[1]);
133
            close(pfdin[1]);
130
            in = fdopen(pfdin[0], "r");
134
            in = fdopen(pfdin[0], "r");
Lines 179-185 Link Here
179
    if (out && dup2(fileno(out), fileno(stdout)) < 0)
183
    if (out && dup2(fileno(out), fileno(stdout)) < 0)
180
        rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "%s: Could not dup stdout\n", (const char *)cmd);
184
        rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "%s: Could not dup stdout\n", (const char *)cmd);
181
185
182
    execl(get_modern_shell(), get_modern_shell(), "-c", (const char *)cmd, (char *)NULL);
186
    execl(get_modern_shell(), get_modern_shell(), "-e", "-c", (const char *)cmd, (char *)NULL);
183
187
184
    _log("Error: Executing \"%s -c %s\" failed (%s).\n", get_modern_shell(), (const char *)cmd, strerror(errno));
188
    _log("Error: Executing \"%s -c %s\" failed (%s).\n", get_modern_shell(), (const char *)cmd, strerror(errno));
185
    return EXIT_PRNERR_NORETRY_BAD_SETTINGS;
189
    return EXIT_PRNERR_NORETRY_BAD_SETTINGS;
(-)filter/foomatic-rip/renderer.c (-3 / +3 lines)
Lines 52-58 Link Here
52
        return 0;
52
        return 0;
53
    }
53
    }
54
54
55
    bytes = fread(output, 1, 10, pd);
55
    bytes = fread_or_die(output, 1, 10, pd);
56
    pclose(pd);
56
    pclose(pd);
57
57
58
    if (bytes > 0 && startswith(output, "hello"))
58
    if (bytes > 0 && startswith(output, "hello"))
Lines 288-294 Link Here
288
         * also contains the "<esc>%-12345X" which has to be in the beginning
288
         * also contains the "<esc>%-12345X" which has to be in the beginning
289
         * of the job */
289
         * of the job */
290
        if (p)
290
        if (p)
291
            fwrite(original_opts[0], 1, p - original_opts[0], stream);
291
            fwrite_or_die(original_opts[0], 1, p - original_opts[0], stream);
292
        else
292
        else
293
            fprintf(stream, "%s\n", original_opts[0]);
293
            fprintf(stream, "%s\n", original_opts[0]);
294
294
Lines 392-398 Link Here
392
392
393
    /* A JCL trailer */
393
    /* A JCL trailer */
394
    if (argv_count(jclprepend) > 0 && !driverjcl)
394
    if (argv_count(jclprepend) > 0 && !driverjcl)
395
        fwrite(jclappend->data, jclappend->len, 1, fileh);
395
        fwrite_or_die(jclappend->data, jclappend->len, 1, fileh);
396
396
397
    fclose(in);
397
    fclose(in);
398
    if (fclose(fileh) != 0)
398
    if (fclose(fileh) != 0)
(-)filter/foomatic-rip/util.c (-3 / +20 lines)
Lines 29-34 Link Here
29
#include <unistd.h>
29
#include <unistd.h>
30
#include <stdarg.h>
30
#include <stdarg.h>
31
#include <assert.h>
31
#include <assert.h>
32
#include <errno.h>
32
33
33
34
34
const char* shellescapes = "|;<>&!$\'\"`#*?()[]{}";
35
const char* shellescapes = "|;<>&!$\'\"`#*?()[]{}";
Lines 291-296 Link Here
291
    return psrc +1;
292
    return psrc +1;
292
}
293
}
293
294
295
size_t fwrite_or_die(const void* ptr, size_t size, size_t count, FILE* stream) {
296
  size_t res = fwrite(ptr, size, count, stream);
297
  if (ferror(stream))
298
    rip_die(EXIT_PRNERR, "Encountered error %s during fwrite", strerror(errno));
299
300
  return res;
301
}
302
303
size_t fread_or_die(void* ptr, size_t size, size_t count, FILE* stream) {
304
  size_t res = fread(ptr, size, count, stream);
305
  if (ferror(stream))
306
    rip_die(EXIT_PRNERR, "Encountered error %s during fread", strerror(errno));
307
308
  return res;
309
}
310
294
int find_in_path(const char *progname, const char *paths, char *found_in)
311
int find_in_path(const char *progname, const char *paths, char *found_in)
295
{
312
{
296
    char *pathscopy;
313
    char *pathscopy;
Lines 1111-1125 Link Here
1111
1128
1112
    if (alreadyread && alreadyread_len)
1129
    if (alreadyread && alreadyread_len)
1113
    {
1130
    {
1114
        if (fwrite(alreadyread, 1, alreadyread_len, dest) < alreadyread_len)
1131
        if (fwrite_or_die(alreadyread, 1, alreadyread_len, dest) < alreadyread_len)
1115
        {
1132
        {
1116
            _log("Could not write to temp file\n");
1133
            _log("Could not write to temp file\n");
1117
            return 0;
1134
            return 0;
1118
        }
1135
        }
1119
    }
1136
    }
1120
1137
1121
    while ((bytes = fread(buf, 1, 8192, src)))
1138
    while ((bytes = fread_or_die(buf, 1, 8192, src)))
1122
        fwrite(buf, 1, bytes, dest);
1139
        fwrite_or_die(buf, 1, bytes, dest);
1123
1140
1124
    return !ferror(src) && !ferror(dest);
1141
    return !ferror(src) && !ferror(dest);
1125
}
1142
}
(-)filter/foomatic-rip/util.h (+5 lines)
Lines 98-103 Link Here
98
*/
98
*/
99
const char * strncpy_tochar(char *dest, const char *src, size_t max, const char *stopchars);
99
const char * strncpy_tochar(char *dest, const char *src, size_t max, const char *stopchars);
100
100
101
/* "safe" versions of standard <cstdio> fwrite and fread that will cause the
102
 * program to exit gracefully when a write/read fails */
103
size_t fwrite_or_die(const void* ptr, size_t size, size_t count, FILE* stream);
104
size_t fread_or_die(void* ptr, size_t size, size_t count, FILE* stream);
105
101
/* 'paths' is a colon seperated list of paths (like $PATH) 
106
/* 'paths' is a colon seperated list of paths (like $PATH) 
102
 * 'found_in' may be NULL if it is not needed */
107
 * 'found_in' may be NULL if it is not needed */
103
int find_in_path(const char *progname, const char *paths, char *found_in);
108
int find_in_path(const char *progname, const char *paths, char *found_in);

Return to bug 632198