diff options
author | sin <sin@2f30.org> | 2014-09-21 10:36:46 +0100 |
---|---|---|
committer | sin <sin@2f30.org> | 2014-09-21 10:36:46 +0100 |
commit | 770251566889c6ac9bbb54bbe49b4582c4d2e1a8 (patch) | |
tree | 63174745267310c3f8310f1f5c62e88e98e29287 /ratox.c | |
parent | 9f234f9156bd2687a30f99ad66f9861154ec7446 (diff) |
Only close file descriptors when they are not -1
Diffstat (limited to 'ratox.c')
-rw-r--r-- | ratox.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -83,9 +83,9 @@ static void setstatus(void *); static void sendfriendreq(void *); static struct slot gslots[] = { - [NAME] = { .name = "name", .cb = setname, .outtype = STATIC }, - [STATUS] = { .name = "status", .cb = setstatus, .outtype = STATIC }, - [REQUEST] = { .name = "request", .cb = sendfriendreq, .outtype = FOLDER }, + [NAME] = { .name = "name", .cb = setname, .outtype = STATIC, .dirfd = -1 }, + [STATUS] = { .name = "status", .cb = setstatus, .outtype = STATIC, .dirfd = -1 }, + [REQUEST] = { .name = "request", .cb = sendfriendreq, .outtype = FOLDER, .dirfd = -1 }, }; static struct file gfiles[] = { @@ -1148,8 +1148,11 @@ shutdown(void) ftmp = TAILQ_NEXT(f, entry); for (i = 0; i < LEN(ffiles); i++) { - unlinkat(f->dirfd, ffiles[i].name, 0); - close(f->fd[i]); + if (f->dirfd != -1) { + unlinkat(f->dirfd, ffiles[i].name, 0); + if (f->fd[i] != -1) + close(f->fd[i]); + } } rmdir(f->idstr); /* T0D0: cancel transmissions */ @@ -1160,8 +1163,11 @@ shutdown(void) for (r = TAILQ_FIRST(&reqhead); r; r = rtmp) { rtmp = TAILQ_NEXT(r, entry); - unlinkat(gslots[REQUEST].fd[OUT], r->idstr, 0); - close(r->fd); + if (gslots[REQUEST].fd[OUT] != -1) { + unlinkat(gslots[REQUEST].fd[OUT], r->idstr, 0); + if (r->fd != -1) + close(r->fd); + } TAILQ_REMOVE(&reqhead, r, entry); free(r->msgstr); free(r); @@ -1170,10 +1176,13 @@ shutdown(void) /* global files and slots */ for (i = 0; i < LEN(gslots); i++) { for (m = 0; m < LEN(gfiles); m++) { - unlinkat(gslots[i].dirfd, gfiles[m].name, - (gslots[i].outtype == FOLDER && m == OUT) - ? AT_REMOVEDIR : 0); - close(gslots[i].fd[m]); + if (gslots[i].dirfd != -1) { + unlinkat(gslots[i].dirfd, gfiles[m].name, + (gslots[i].outtype == FOLDER && m == OUT) + ? AT_REMOVEDIR : 0); + if (gslots[i].fd[m] != -1) + close(gslots[i].fd[m]); + } } rmdir(gslots[i].name); } |