… | |
… | |
33 | #include <signal.h> |
33 | #include <signal.h> |
34 | |
34 | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <material.h> |
36 | #include <material.h> |
37 | |
37 | |
|
|
38 | #include <sys/time.h> |
|
|
39 | #include <sys/resource.h> |
|
|
40 | |
38 | #include <glib.h> |
41 | #include <glib.h> |
39 | |
42 | |
40 | refcnt_base::refcnt_t refcnt_dummy; |
43 | refcnt_base::refcnt_t refcnt_dummy; |
41 | ssize_t slice_alloc; |
44 | ssize_t slice_alloc; |
42 | rand_gen rndm, rmg_rndm; |
45 | rand_gen rndm, rmg_rndm; |
… | |
… | |
197 | } |
200 | } |
198 | |
201 | |
199 | /* convert materialname to materialtype_t */ |
202 | /* convert materialname to materialtype_t */ |
200 | |
203 | |
201 | materialtype_t * |
204 | materialtype_t * |
202 | name_to_material (const shstr &name) |
205 | name_to_material (const shstr_cmp name) |
203 | { |
206 | { |
204 | for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next) |
207 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
205 | if (name == mt->name) |
208 | if (name == mt->name) |
206 | return mt; |
209 | return mt; |
207 | |
210 | |
208 | return 0; |
211 | return 0; |
209 | } |
212 | } |
… | |
… | |
215 | transmute_materialname (object *op, const object *change) |
218 | transmute_materialname (object *op, const object *change) |
216 | { |
219 | { |
217 | materialtype_t *mt; |
220 | materialtype_t *mt; |
218 | int j; |
221 | int j; |
219 | |
222 | |
220 | if (op->materialname == NULL) |
223 | if (!op->materialname) |
221 | return; |
224 | return; |
222 | |
225 | |
223 | if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) |
226 | if (change->materialname && strcmp (op->materialname, change->materialname)) |
224 | return; |
227 | return; |
225 | |
228 | |
226 | if (!op->is_armor ()) |
229 | if (!op->is_armor ()) |
227 | return; |
230 | return; |
228 | |
231 | |
… | |
… | |
248 | void |
251 | void |
249 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
252 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
250 | { |
253 | { |
251 | materialtype_t *mt, *lmt; |
254 | materialtype_t *mt, *lmt; |
252 | |
255 | |
253 | if (op->materialname != NULL) |
256 | if (!op->materialname) |
254 | return; |
257 | return; |
255 | |
258 | |
256 | if (nmt == NULL) |
259 | if (nmt) |
|
|
260 | lmt = nmt; |
|
|
261 | else |
257 | { |
262 | { |
258 | lmt = NULL; |
263 | lmt = 0; |
259 | |
264 | |
260 | for (mt = materialt; mt && mt->next; mt = mt->next) |
265 | for (mt = materialt; mt; mt = mt->next) |
261 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
266 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
262 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
267 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
263 | { |
268 | { |
264 | lmt = mt; |
269 | lmt = mt; |
265 | if (!(op->is_weapon () || op->is_armor ())) |
270 | if (!(op->is_weapon () || op->is_armor ())) |
266 | break; |
271 | break; |
267 | } |
272 | } |
268 | } |
273 | } |
269 | else |
|
|
270 | lmt = nmt; |
|
|
271 | |
274 | |
272 | if (lmt != NULL) |
275 | if (lmt) |
273 | { |
276 | { |
274 | if (op->stats.dam && op->is_weapon ()) |
277 | if (op->stats.dam && op->is_weapon ()) |
275 | { |
278 | { |
276 | op->stats.dam += lmt->damage; |
279 | op->stats.dam += lmt->damage; |
277 | if (op->stats.dam < 1) |
280 | if (op->stats.dam < 1) |
… | |
… | |
446 | void |
449 | void |
447 | fork_abort (const char *msg) |
450 | fork_abort (const char *msg) |
448 | { |
451 | { |
449 | if (!fork ()) |
452 | if (!fork ()) |
450 | { |
453 | { |
|
|
454 | signal (SIGINT , SIG_IGN); |
|
|
455 | signal (SIGTERM, SIG_IGN); |
451 | signal (SIGABRT, SIG_DFL); |
456 | signal (SIGABRT, SIG_IGN); |
|
|
457 | |
|
|
458 | signal (SIGSEGV, SIG_DFL); |
|
|
459 | signal (SIGBUS , SIG_DFL); |
|
|
460 | signal (SIGILL , SIG_DFL); |
|
|
461 | signal (SIGTRAP, SIG_DFL); |
|
|
462 | |
452 | // try to put corefiles into a subdirectory, if existing, to allow |
463 | // try to put corefiles into a subdirectory, if existing, to allow |
453 | // an administrator to reduce the I/O load. |
464 | // an administrator to reduce the I/O load. |
454 | chdir ("cores"); |
465 | chdir ("cores"); |
|
|
466 | |
|
|
467 | // try to detach us from as many external dependencies as possible |
|
|
468 | // as coredumping can take time by closing all fd's. |
|
|
469 | { |
|
|
470 | struct rlimit lim; |
|
|
471 | |
|
|
472 | if (getrlimit (RLIMIT_NOFILE, &lim)) |
|
|
473 | lim.rlim_cur = 1024; |
|
|
474 | |
|
|
475 | for (int i = 0; i < lim.rlim_cur; ++i) |
|
|
476 | close (i); |
|
|
477 | } |
|
|
478 | |
|
|
479 | { |
|
|
480 | sigset_t empty; |
|
|
481 | sigemptyset (&empty); |
|
|
482 | sigprocmask (SIG_SETMASK, &empty, 0); |
|
|
483 | } |
|
|
484 | |
|
|
485 | // try to coredump with SIGTRAP |
|
|
486 | kill (getpid (), SIGTRAP); |
455 | abort (); |
487 | abort (); |
456 | } |
488 | } |
457 | |
489 | |
458 | LOG (llevError, "fork abort: %s\n", msg); |
490 | LOG (llevError, "fork abort: %s\n", msg); |
459 | } |
491 | } |