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 / +91 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-228 Link Here
222
read_tab()
281
read_tab()
223
/* Read the anacrontab file into memory */
282
/* Read the anacrontab file into memory */
224
{
283
{
225
    char *tab_line;
284
    char tab_line[MAXTABLINE];
226
285
227
    first_job_rec = last_job_rec = NULL;
286
    first_job_rec = last_job_rec = NULL;
228
    first_env_rec = last_env_rec = NULL;
287
    first_env_rec = last_env_rec = NULL;
Lines 231-236 Link Here
231
    /* Open the anacrontab file */
290
    /* Open the anacrontab file */
232
    tab = fopen(anacrontab, "r");
291
    tab = fopen(anacrontab, "r");
233
    if (tab == NULL) die_e("Error opening %s", anacrontab);
292
    if (tab == NULL) die_e("Error opening %s", anacrontab);
293
#ifndef __linux__
294
    while ((read_tab_line(tab_line)) != NULL)
295
    {
296
	line_num++;
297
	parse_tab_line(tab_line);
298
#else
234
    /* Initialize the obstacks */
299
    /* Initialize the obstacks */
235
    obstack_init(&input_o);
300
    obstack_init(&input_o);
236
    obstack_init(&tab_o);
301
    obstack_init(&tab_o);
Lines 239-245 Link Here
239
	line_num++;
304
	line_num++;
240
	parse_tab_line(tab_line);
305
	parse_tab_line(tab_line);
241
	obstack_free(&input_o, tab_line);
306
	obstack_free(&input_o, tab_line);
242
    }
307
#endif
308
}
243
    if (fclose(tab)) die_e("Error closing %s", anacrontab);
309
    if (fclose(tab)) die_e("Error closing %s", anacrontab);
244
}
310
}
245
311
Lines 269-285 Link Here
269
335
270
    j = first_job_rec;
336
    j = first_job_rec;
271
    njobs = 0;
337
    njobs = 0;
338
#ifndef __linux__
339
    job_array = NULL;
340
#endif
272
    while (j != NULL)
341
    while (j != NULL)
273
    {
342
    {
274
	if (j->arg_num != -1 && (update_only || consider_job(j)))
343
	if (j->arg_num != -1 && (update_only || consider_job(j)))
275
	{
344
	{
345
#ifndef __linux__
346
	    job_array = (job_rec**)xrealloc(job_array, (njobs+1)*sizeof(j));
347
	    job_array[njobs] = j;
348
	    njobs++;
349
#else
276
	    njobs++;
350
	    njobs++;
277
	    obstack_grow(&tab_o, &j, sizeof(j));
351
	    obstack_grow(&tab_o, &j, sizeof(j));
278
	}
352
#endif
279
	j = j->next;
353
	j = j->next;
280
    }
354
    }
281
    job_array = obstack_finish(&tab_o);
355
#ifdef __linux__
282
356
	job_array = obstack_finish(&tab_o);
357
#endif
358
    }
283
    /* sort the jobs */
359
    /* sort the jobs */
284
    qsort(job_array, njobs, sizeof(*job_array),
360
    qsort(job_array, njobs, sizeof(*job_array),
285
	  (int (*)(const void *, const void *))execution_order);
361
	  (int (*)(const void *, const void *))execution_order);

Return to bug 141377