129 if (strcmp (entry->d_name, ".") == 0)
130 continue;
131 if (strcmp (entry->d_name, "..") == 0)
132 continue;
133 new_work = (work_p)malloc (sizeof (work_t));
134 if (new_work == NULL)
135 errno_abort ("Unable to allocate space");
136 new_work->path = (char*)malloc (path_max);
137 if (new_work->path == NULL)
138 errno_abort ("Unable to allocate path");
139 strcpy (new_work->path, work->path);
140 strcat (new_work->path, "/");
141 strcat (new_work->path, entry->d_name);
142 new_work->string = work->string;
143 new_work->next = NULL;
144 status = pthread_mutex_lock (&crew->mutex);
145 if (status != 0)
146 err_abort (status, "Lock mutex");
147 if (crew->first == NULL) {
148 crew->first = new_work;
149 crew->last = new_work;
150 } else {
151 crew->last->next = new_work;
152 crew->last = new_work;
153 }
154 crew->work_count++;
155 DPRINTF ((
156 "Crew %d: add %#lx, first %#lx, last %#lx, %d\n",
157 mine->index, new_work, crew->first,
158 crew->last, crew->work_count));
159 status = pthread_cond_signal (&crew->go);
160 status = pthread_mutex_unlock (&crew->mutex);
161 if (status != 0)
162 err_abort (status, "Unlock mutex");
163 }
164
165 closedir (directory);
166 } else if (S_ISREG (filestat.st_mode)) {
167 FILE *search;
168 char buffer[256], *bufptr, *search_ptr;
169
170 /*
171 * If this is a file, not a directory, then search
172 * it for the string.
173 */
174 search = fopen (work->path, "r");
175 if (search == NULL)
176 fprintf (
177 stderr, "Unable to open %s: %d (%s)\n",
178 work->path,
179 errno, strerror (errno));
180 else {
181
182 while (1) {
183 bufptr = fgets (
184 buffer, sizeof (buffer), search);
185 if (bufptr == NULL) {
186 if (feof (search))
187 break;
188 if (ferror (search)) {
189 fprintf (
190 stderr,
191 "Unable to read %s: %d (%s)\n",
192 work->path,
193 errno, strerror (errno));
194 break;
195 }
196 }
197 search_ptr = strstr (buffer, work->string);
198 if (search_ptr != NULL) {
199 printf (
200 "Thread %d found \"%s\" in %s\n",
201 mine->index, work->string, work->path);
202 break;
203 }
204 }
205 fclose (search);
206 }
207 } else
208 fprintf (
209 stderr,
210 "Thread %d: %s is type %o (%s))\n",
211 mine->index,
212 work->path,
213 filestat.st_mode & S_IFMT,
214 (S_ISFIFO (filestat.st_mode) ? "FIFO"
215 :(S_ISCHR (filestat.st_mode) ? "CHR"