| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: jobs.c,v 1.11 2010/02/26 16:25:49 joerg Exp $ */ | | 1 | /* $NetBSD: jobs.c,v 1.12 2010/05/05 00:07:07 joerg Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. | | 4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code was developed as part of Google's Summer of Code 2007 program. | | 7 | * This code was developed as part of Google's Summer of Code 2007 program. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * | | 12 | * |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -136,54 +136,63 @@ pbulk_item_end(const char *line) | | | @@ -136,54 +136,63 @@ pbulk_item_end(const char *line) |
136 | line_end = strchr(line, '\n'); | | 136 | line_end = strchr(line, '\n'); |
137 | if (line_end == NULL) | | 137 | if (line_end == NULL) |
138 | return NULL; | | 138 | return NULL; |
139 | line = line_end + 1; | | 139 | line = line_end + 1; |
140 | if (strncmp(line, "PKGNAME=", 8) == 0) | | 140 | if (strncmp(line, "PKGNAME=", 8) == 0) |
141 | return line; | | 141 | return line; |
142 | } while (*line != '\0'); | | 142 | } while (*line != '\0'); |
143 | | | 143 | |
144 | return line; | | 144 | return line; |
145 | } | | 145 | } |
146 | | | 146 | |
147 | SLIST_HEAD(depth_tree_head, build_job); | | 147 | SLIST_HEAD(depth_tree_head, build_job); |
148 | | | 148 | |
149 | static void | | 149 | static int |
150 | compute_tree_depth_rec(struct build_job *job, struct build_job *root, | | 150 | compute_tree_depth_rec(struct build_job *job, struct build_job *root, |
151 | struct depth_tree_head *head, int *count) | | 151 | struct depth_tree_head *head, int *count) |
152 | { | | 152 | { |
153 | struct dependency_list *dep_iter; | | 153 | struct dependency_list *dep_iter; |
154 | struct build_job *job_iter; | | 154 | struct build_job *job_iter; |
155 | | | 155 | |
156 | if (job == root && *count != 0) | | 156 | if (job == root && *count != 0) { |
157 | errx(1, "Cyclic dependency for package %s", job->pkgname); | | 157 | fprintf(stderr, "Cyclic dependency for package:\n%s\n", job->pkgname); |
| | | 158 | return -1; |
| | | 159 | } |
158 | | | 160 | |
159 | SLIST_FOREACH(job_iter, head, depth_tree_link) { | | 161 | SLIST_FOREACH(job_iter, head, depth_tree_link) { |
160 | if (job_iter == job) | | 162 | if (job_iter == job) |
161 | return; | | 163 | return 0; |
162 | } | | 164 | } |
163 | SLIST_INSERT_HEAD(head, job, depth_tree_link); | | 165 | SLIST_INSERT_HEAD(head, job, depth_tree_link); |
164 | *count = *count + 1; | | 166 | *count = *count + 1; |
165 | SLIST_FOREACH(dep_iter, &job->depending_pkgs, depends_link) | | 167 | SLIST_FOREACH(dep_iter, &job->depending_pkgs, depends_link) { |
166 | compute_tree_depth_rec(dep_iter->dependency, root, head, count); | | 168 | if (compute_tree_depth_rec(dep_iter->dependency, root, |
| | | 169 | head, count)) { |
| | | 170 | fprintf(stderr, "%s\n", job->pkgname); |
| | | 171 | return -1; |
| | | 172 | } |
| | | 173 | } |
| | | 174 | return 0; |
167 | } | | 175 | } |
168 | | | 176 | |
169 | static void | | 177 | static void |
170 | compute_tree_depth(struct build_job *job) | | 178 | compute_tree_depth(struct build_job *job) |
171 | { | | 179 | { |
172 | struct depth_tree_head head; | | 180 | struct depth_tree_head head; |
173 | | | 181 | |
174 | SLIST_INIT(&head); | | 182 | SLIST_INIT(&head); |
175 | job->pkg_depth = 0; | | 183 | job->pkg_depth = 0; |
176 | compute_tree_depth_rec(job, job, &head, &job->pkg_depth); | | 184 | if (compute_tree_depth_rec(job, job, &head, &job->pkg_depth)) |
| | | 185 | exit(1); |
177 | } | | 186 | } |
178 | | | 187 | |
179 | void | | 188 | void |
180 | init_jobs(const char *scan_output, const char *success_file, const char *error_file) | | 189 | init_jobs(const char *scan_output, const char *success_file, const char *error_file) |
181 | { | | 190 | { |
182 | char *input; | | 191 | char *input; |
183 | const char *input_iter; | | 192 | const char *input_iter; |
184 | int fd; | | 193 | int fd; |
185 | size_t i; | | 194 | size_t i; |
186 | | | 195 | |
187 | TAILQ_INIT(&buildable_jobs); | | 196 | TAILQ_INIT(&buildable_jobs); |
188 | | | 197 | |
189 | if ((fd = open(scan_output, O_RDONLY, 0)) == -1) | | 198 | if ((fd = open(scan_output, O_RDONLY, 0)) == -1) |