~ubuntu-branches/debian/sid/trinity/sid

« back to all changes in this revision

Viewing changes to files.c

  • Committer: Package Import Robot
  • Author(s): gustavo panizzo
  • Date: 2014-01-17 21:10:15 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140117211015-k2qbnpu0osa5mlil
Tags: 1.3-1
* New upstream version 1.3.
* Removed wrong dependency on linux-headers. (Closes: #733771).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "constants.h"
20
20
#include "list.h"
21
21
#include "random.h"
 
22
#include "utils.h"
22
23
 
23
24
static int files_added = 0;
24
25
const char **fileindex;
68
69
                }
69
70
 
70
71
                if (!strcmp(path, ignored_paths[i])) {
71
 
//                      printf("Skipping %s\n", path);
 
72
                        debugf("Skipping %s\n", path);
72
73
                        return 1;
73
74
                }
74
75
        }
85
86
 
86
87
        for (i = 0; ignored_patterns[i]; i++) {
87
88
                if (!strcmp(path + offset, ignored_patterns[i])) {
88
 
//                      printf("Skipping pattern %s\n", path);
 
89
                        debugf("Skipping pattern %s\n", path);
89
90
                        return 1;
90
91
                }
91
92
        }
92
93
 
93
94
        /* special case to match tty* until I do globbing */
94
95
        if (!strncmp(path + offset, "tty", 3)) {
95
 
//              printf("Skipping %s\n", path);
 
96
                debugf("Skipping %s\n", path);
96
97
                return 1;
97
98
        }
98
99
        return 0;
99
100
}
100
101
 
101
 
 
102
 
static struct namelist * alloc_namenode(void)
103
 
{
104
 
        struct namelist *newnode;
105
 
 
106
 
        newnode = malloc(sizeof(struct namelist));
107
 
        if (newnode == NULL)
108
 
                exit(EXIT_FAILURE);
109
 
 
110
 
        memset(newnode, 0, sizeof(struct namelist));
111
 
        return newnode;
112
 
}
113
 
 
114
102
static void add_to_namelist(const char *name)
115
103
{
116
104
        struct namelist *newnode;
117
105
        struct list_head *list = (struct list_head *) names;
118
106
 
119
 
        newnode = alloc_namenode();
 
107
        newnode = zmalloc(sizeof(struct namelist));
120
108
        newnode->name = strdup(name);
121
109
        list_add_tail(&newnode->list, list);
122
110
}
204
192
        ret = nftw(dirpath, file_tree_callback, 32, flags);
205
193
        if (ret != 0) {
206
194
                if (shm->exit_reason != EXIT_SIGINT)
207
 
                        output(0, "Something went wrong during nftw(%s). Returned %d\n", dirpath, ret);
 
195
                        output(0, "Something went wrong during nftw(%s). (%d:%s)\n",
 
196
                                dirpath, ret, strerror(errno));
208
197
                return;
209
198
        }
210
199
 
220
209
        my_uid = getuid();
221
210
        my_gid = getgid();
222
211
 
223
 
        names = alloc_namenode();
 
212
        names = zmalloc(sizeof(struct namelist));
224
213
        INIT_LIST_HEAD(&names->list);
225
214
 
226
215
        output(1, "Generating file descriptors\n");
283
272
        case O_RDWR:    modestr = "read-write"; break;
284
273
        default: modestr = "unknown"; break;
285
274
        }
286
 
        output(2, "[%d] fd[%i] = %s (%s)\n",
287
 
                getpid(), fd, filename, modestr);
 
275
        output(2, "fd[%i] = %s (%s)\n", fd, filename, modestr);
288
276
        return fd;
289
277
}
290
278
 
335
323
 
336
324
        return fileindex[rand() % files_in_index];
337
325
}
338
 
 
339
 
const char * generate_pathname(void)
340
 
{
341
 
        const char *pathname = get_filename();
342
 
        char *newpath;
343
 
        unsigned int len;
344
 
        unsigned int i, chance;
345
 
 
346
 
        if (pathname == NULL)           /* As above, handle -n correctly. */
347
 
                return NULL;
348
 
 
349
 
        len = strlen(pathname);
350
 
 
351
 
        chance = rand() % 100;
352
 
        switch (chance) {
353
 
 
354
 
        case 0 ... 90:
355
 
                /* 90% chance of returning an unmangled filename */
356
 
                return pathname;
357
 
 
358
 
        case 91 ... 99:
359
 
                /* Create a bogus filename. */
360
 
                newpath = malloc(page_size);    // FIXME: We leak this.
361
 
                if (newpath == NULL)
362
 
                        return pathname;        // give up.
363
 
 
364
 
                generate_random_page(newpath);
365
 
 
366
 
                /* sometimes, just complete junk. */
367
 
                if (rand_bool())
368
 
                        goto out;
369
 
 
370
 
                /* Sometimes, pathname + junk */
371
 
                if (rand_bool())
372
 
                        (void) strncpy(newpath, pathname, len);
373
 
                else {
374
 
                        /* make it look relative to cwd */
375
 
                        newpath[0] = '.';
376
 
                        (void) strncpy(newpath + 1, pathname, len);
377
 
                }
378
 
 
379
 
                /* Sometimes, remove all /'s */
380
 
                if (rand_bool()) {
381
 
                        for (i = 0; i < len; i++) {
382
 
                                if (newpath[i] == '/')
383
 
                                        newpath[i] = rand();
384
 
                        }
385
 
                }
386
 
out:
387
 
                /* 50/50 chance of making it look like a dir */
388
 
                if (rand_bool()) {
389
 
                        newpath[len] = '/';
390
 
                        newpath[len + 1] = 0;
391
 
                }
392
 
 
393
 
                return newpath;
394
 
        default:
395
 
                BUG("Unreachable");
396
 
        }
397
 
}