Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 141377 | Differences between
and this patch

Collapse All | Expand All

(-)readtab.c.orig (-15 / +94 lines)
Lines 19-24 Link Here
19
 
19
 
20
    The GNU General Public License can also be found in the file
20
    The GNU General Public License can also be found in the file
21
    `COPYING' that comes with the Anacron source distribution.
21
    `COPYING' that comes with the Anacron source distribution.
22
23
    Changes:
24
25
    May 2003 (Derik van Zuetphen)
26
	replaced obstack with malloc/realloc calls
27
28
    Jul 2006 (Timothy Redaelli)
29
        conditional patch to replace obstack with malloc/realloc calls
22
*/
30
*/
23
31
24
32
Lines 29-44 Link Here
29
#include <errno.h>
37
#include <errno.h>
30
#include <stdio.h>
38
#include <stdio.h>
31
#include <stdlib.h>
39
#include <stdlib.h>
32
#include <obstack.h>
33
#include <limits.h>
40
#include <limits.h>
34
#include <fnmatch.h>
41
#include <fnmatch.h>
35
#include <unistd.h>
42
#include <unistd.h>
36
#include <signal.h>
43
#include <signal.h>
37
#include "global.h"
44
#include "global.h"
38
#include "matchrx.h"
45
#include "matchrx.h"
46
#ifdef __linux__
47
#include <obstack.h>
48
49
static struct obstack input_o;
50
static struct obstack tab_o;
51
52
/* some definitions for the obstack macros */
53
#define obstack_chunk_alloc xmalloc
54
#define obstack_chunk_free free
55
#else
56
#define MAXTABLINE	1000
57
#endif
39
58
40
static struct obstack input_o;   /* holds input line */
41
static struct obstack tab_o;    /* holds processed data read from anacrontab */
42
static FILE *tab;
59
static FILE *tab;
43
job_rec **job_array;
60
job_rec **job_array;
44
int njobs;                       /* number of jobs to run */
61
int njobs;                       /* number of jobs to run */
Lines 47-56 Link Here
47
static job_rec *last_job_rec;    /* last job stored in memory, at the moment */
64
static job_rec *last_job_rec;    /* last job stored in memory, at the moment */
48
static env_rec *last_env_rec;    /* last environment assignment stored */
65
static env_rec *last_env_rec;    /* last environment assignment stored */
49
66
50
/* some definitions for the obstack macros */
51
#define obstack_chunk_alloc xmalloc
52
#define obstack_chunk_free free
53
54
static void *
67
static void *
55
xmalloc (size_t size)
68
xmalloc (size_t size)
56
/* Just like standard malloc(), only never returns NULL. */
69
/* Just like standard malloc(), only never returns NULL. */
Lines 63-68 Link Here
63
    return ptr;
76
    return ptr;
64
}
77
}
65
78
79
#ifndef __linux__
80
static void *
81
xrealloc (void *mem, size_t size)
82
/* Just like standard realloc(), only never returns NULL. */
83
{
84
    void * ptr;
85
86
    ptr = realloc(mem,size);
87
    if (ptr == NULL)
88
	die("Memory exhausted");
89
    return ptr;
90
}
91
#endif
92
66
static int
93
static int
67
conv2int(const char *s)
94
conv2int(const char *s)
68
/* Return the int or -1 on over/under-flow
95
/* Return the int or -1 on over/under-flow
Lines 78-98 Link Here
78
}
105
}
79
106
80
static char *
107
static char *
81
read_tab_line ()
108
#ifndef __linux__
109
read_tab_line (char *line)
82
/* Read one line and return a pointer to it.
110
/* Read one line and return a pointer to it.
83
Return NULL if no more lines.
111
Return NULL if no more lines.
84
 */
112
 */
85
{
113
{
86
    int c;
114
    int c;
115
    int i = 0;
87
116
88
    if (feof(tab)) return NULL;
117
    if (feof(tab)) return NULL;
118
    while (i < MAXTABLINE-1 && (c = getc(tab)) != EOF && c != '\n')
119
	line[i++] = c;
120
    if (ferror(tab)) die_e("Error reading %s", anacrontab);
121
    line[i] = 0;
122
    return line;
123
#else
124
read_tab_line ()
125
{
126
    int c;
127
    
128
    if (feof(tab)) return NULL;
89
    while ((c = getc(tab)) != EOF && c != '\n')
129
    while ((c = getc(tab)) != EOF && c != '\n')
90
	obstack_1grow(&input_o, c);
130
        obstack_1grow(&input_o, c);
91
    if (ferror(tab)) die_e("Error reading %s", anacrontab);
131
    if (ferror(tab)) die_e("Error reading %s", anacrontab);
92
    obstack_1grow(&input_o, '\0');
132
    obstack_1grow(&input_o, '\0');
93
    return obstack_finish(&input_o);
133
    return obstack_finish(&input_o);
134
#endif
94
}
135
}
95
136
137
96
static int
138
static int
97
job_arg_num(const char *ident)
139
job_arg_num(const char *ident)
98
/* Return the command-line-argument number refering to this job-identifier.
140
/* Return the command-line-argument number refering to this job-identifier.
Lines 119-126 Link Here
119
161
120
    var_len = strlen(env_var);
162
    var_len = strlen(env_var);
121
    val_len = strlen(value);
163
    val_len = strlen(value);
164
#ifndef __linux__
165
    er = (env_rec*)xmalloc(sizeof(env_rec));
166
    er->assign = (char*)xmalloc(var_len + 1 + val_len + 1);
167
#else
122
    er = obstack_alloc(&tab_o, sizeof(env_rec));
168
    er = obstack_alloc(&tab_o, sizeof(env_rec));
123
    er->assign = obstack_alloc(&tab_o, var_len + 1 + val_len + 1);
169
    er->assign = obstack_alloc(&tab_o, var_len + 1 + val_len + 1);
170
#endif
124
    strcpy(er->assign, env_var);
171
    strcpy(er->assign, env_var);
125
    er->assign[var_len] = '=';
172
    er->assign[var_len] = '=';
126
    strcpy(er->assign + var_len + 1, value);
173
    strcpy(er->assign + var_len + 1, value);
Lines 151-164 Link Here
151
		 anacrontab, line_num);
198
		 anacrontab, line_num);
152
	return;
199
	return;
153
    }
200
    }
201
#ifndef __linux__
202
    jr = (job_rec*)xmalloc(sizeof(job_rec));
203
#else
154
    jr = obstack_alloc(&tab_o, sizeof(job_rec));
204
    jr = obstack_alloc(&tab_o, sizeof(job_rec));
205
#endif
155
    jr->period = period;
206
    jr->period = period;
156
    jr->delay = delay;
207
    jr->delay = delay;
157
    jr->tab_line = line_num;
208
    jr->tab_line = line_num;
158
    jr->ident = obstack_alloc(&tab_o, ident_len + 1);
209
#ifndef __linux__
210
    jr->ident = (char*)xmalloc(ident_len + 1);
211
#else
212
    jr = obstack_alloc(&tab_o, sizeof(job_rec));
213
#endif
159
    strcpy(jr->ident, ident);
214
    strcpy(jr->ident, ident);
160
    jr->arg_num = job_arg_num(ident);
215
    jr->arg_num = job_arg_num(ident);
216
#ifndef __linux__
217
    jr->command = (char*)xmalloc(command_len + 1);
218
#else
161
    jr->command = obstack_alloc(&tab_o, command_len + 1);
219
    jr->command = obstack_alloc(&tab_o, command_len + 1);
220
#endif
162
    strcpy(jr->command, command);
221
    strcpy(jr->command, command);
163
    jr->job_pid = jr->mailer_pid = 0;
222
    jr->job_pid = jr->mailer_pid = 0;
164
    if (last_job_rec != NULL) last_job_rec->next = jr;
223
    if (last_job_rec != NULL) last_job_rec->next = jr;
Lines 222-229 Link Here
222
read_tab()
281
read_tab()
223
/* Read the anacrontab file into memory */
282
/* Read the anacrontab file into memory */
224
{
283
{
284
#ifndef __linux__
285
    char tab_line[MAXTABLINE];
286
#else
225
    char *tab_line;
287
    char *tab_line;
226
288
#endif
227
    first_job_rec = last_job_rec = NULL;
289
    first_job_rec = last_job_rec = NULL;
228
    first_env_rec = last_env_rec = NULL;
290
    first_env_rec = last_env_rec = NULL;
229
    jobs_read = 0;
291
    jobs_read = 0;
Lines 231-236 Link Here
231
    /* Open the anacrontab file */
293
    /* Open the anacrontab file */
232
    tab = fopen(anacrontab, "r");
294
    tab = fopen(anacrontab, "r");
233
    if (tab == NULL) die_e("Error opening %s", anacrontab);
295
    if (tab == NULL) die_e("Error opening %s", anacrontab);
296
#ifndef __linux__
297
    while ((read_tab_line(tab_line)) != NULL)
298
    {
299
	line_num++;
300
	parse_tab_line(tab_line);
301
#else
234
    /* Initialize the obstacks */
302
    /* Initialize the obstacks */
235
    obstack_init(&input_o);
303
    obstack_init(&input_o);
236
    obstack_init(&tab_o);
304
    obstack_init(&tab_o);
Lines 239-245 Link Here
239
	line_num++;
307
	line_num++;
240
	parse_tab_line(tab_line);
308
	parse_tab_line(tab_line);
241
	obstack_free(&input_o, tab_line);
309
	obstack_free(&input_o, tab_line);
242
    }
310
#endif
311
}
243
    if (fclose(tab)) die_e("Error closing %s", anacrontab);
312
    if (fclose(tab)) die_e("Error closing %s", anacrontab);
244
}
313
}
245
314
Lines 269-285 Link Here
269
338
270
    j = first_job_rec;
339
    j = first_job_rec;
271
    njobs = 0;
340
    njobs = 0;
341
#ifndef __linux__
342
    job_array = NULL;
343
#endif
272
    while (j != NULL)
344
    while (j != NULL)
273
    {
345
    {
274
	if (j->arg_num != -1 && (update_only || consider_job(j)))
346
	if (j->arg_num != -1 && (update_only || consider_job(j)))
275
	{
347
	{
348
#ifndef __linux__
349
	    job_array = (job_rec**)xrealloc(job_array, (njobs+1)*sizeof(j));
350
	    job_array[njobs] = j;
351
	    njobs++;
352
#else
276
	    njobs++;
353
	    njobs++;
277
	    obstack_grow(&tab_o, &j, sizeof(j));
354
	    obstack_grow(&tab_o, &j, sizeof(j));
278
	}
355
#endif
279
	j = j->next;
356
	j = j->next;
280
    }
357
    }
281
    job_array = obstack_finish(&tab_o);
358
#ifdef __linux__
282
359
	job_array = obstack_finish(&tab_o);
360
#endif
361
    }
283
    /* sort the jobs */
362
    /* sort the jobs */
284
    qsort(job_array, njobs, sizeof(*job_array),
363
    qsort(job_array, njobs, sizeof(*job_array),
285
	  (int (*)(const void *, const void *))execution_order);
364
	  (int (*)(const void *, const void *))execution_order);

Return to bug 141377