- Timestamp:
- Oct 12, 2009, 10:40:45 AM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/samhain.c
r248 r252 920 920 { if (errno != ENOENT) perror(_("fopen")); return 0; } 921 921 if (NULL == fgets(line, sizeof(line), fp)) 922 { perror(_("fgets")); (void) fclose(fp); return 0; }923 (void) fclose(fp);922 { perror(_("fgets")); (void) sl_fclose(FIL__, __LINE__, fp); return 0; } 923 (void) sl_fclose(FIL__, __LINE__, fp); 924 924 p = line; 925 925 while (*p == ' ' || *p == '\f' || *p == '\n' || … … 1003 1003 exit (1); 1004 1004 case 0: 1005 if (0 != close (0))1005 if (0 != sl_close_fd (FIL__, __LINE__, 0)) 1006 1006 { 1007 1007 _exit(4); … … 2100 2100 2101 2101 { 2102 char * stale = sl_check_stale(); 2103 2102 char * stale; 2103 2104 stale = sl_check_stale(); 2105 if (stale) 2106 { 2107 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN, 2108 stale, _("sl_check_stale")); 2109 } 2110 2111 stale = sl_check_badfd(); 2104 2112 if (stale) 2105 2113 { -
trunk/src/sh_entropy.c
r235 r252 138 138 if( do_restart ) { 139 139 if( fd != -1 ) { 140 close(fd );140 sl_close_fd(FIL__, __LINE__, fd ); 141 141 fd = -1; 142 142 } … … 195 195 _("sh_entropy") ); 196 196 SH_FREE(name); 197 close(fd);197 sl_close_fd(FIL__, __LINE__, fd); 198 198 SL_RETURN( -1, _("sh_entropy") ); 199 199 } … … 212 212 _("cannot write to EGD"), 213 213 _("sh_entropy") ); 214 close(fd);214 sl_close_fd(FIL__, __LINE__, fd); 215 215 SL_RETURN( -1, _("sh_entropy") ); 216 216 } … … 254 254 _("cannot write to EGD"), 255 255 _("sh_entropy") ); 256 close(fd);256 sl_close_fd(FIL__, __LINE__, fd); 257 257 SL_RETURN( -1, _("sh_entropy") ); 258 258 } … … 274 274 } 275 275 memset(buffer, 0, sizeof(buffer) ); 276 close(fd);276 sl_close_fd(FIL__, __LINE__, fd); 277 277 SL_RETURN( 0, _("sh_entropy") ); /* success */ 278 278 } … … 310 310 m_count = 0; 311 311 312 close(fd2);312 sl_close_fd(FIL__, __LINE__, fd2); 313 313 314 314 TPT((0, FIL__, __LINE__, _("msg=<read_mbytes: OK>\n"))); … … 559 559 */ 560 560 if (source->pid == (pid_t) - 1) { 561 close(pipedes[0]);562 close(pipedes[1]);561 sl_close_fd(FIL__, __LINE__, pipedes[0]); 562 sl_close_fd(FIL__, __LINE__, pipedes[1]); 563 563 if (envp[0] != NULL) free(envp[0]); 564 564 SL_RETURN(NULL, _("sh_popen")); … … 580 580 /* close the pipe descriptors 581 581 */ 582 close (pipedes[STDIN_FILENO]);583 close (pipedes[STDOUT_FILENO]);582 sl_close_fd (FIL__, __LINE__, pipedes[STDIN_FILENO]); 583 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 584 584 585 585 /* don't leak file descriptors … … 649 649 free(envp[0]); 650 650 651 close (pipedes[STDOUT_FILENO]);651 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 652 652 retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC); 653 653 … … 657 657 { 658 658 aud_kill (FIL__, __LINE__, source->pid, SIGKILL); 659 close (pipedes[STDOUT_FILENO]);659 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 660 660 waitpid (source->pid, NULL, 0); 661 661 source->pid = 0; … … 676 676 SL_ENTER(_("sh_pclose")); 677 677 678 retval = fclose(source->pipe);678 retval = sl_fclose(FIL__, __LINE__, source->pipe); 679 679 if (retval) 680 680 { -
trunk/src/sh_err_console.c
r170 r252 378 378 val_return = write(fd[cc], "\r\n", 2); 379 379 } while (val_return < 0 && errno == EINTR); 380 (void) close(fd[cc]);380 (void) sl_close_fd(FIL__, __LINE__, fd[cc]); 381 381 service_failure[cc] = 0; 382 382 } -
trunk/src/sh_extern.c
r248 r252 40 40 static FILE * pdbgc = NULL; 41 41 #define PDBG_OPEN if (pdbg == NULL) pdbg = fopen(PDGBFILE"main", "a") 42 #define PDBG_CLOSE fclose (pdbg); pdbg = NULL42 #define PDBG_CLOSE sl_fclose (FIL__, __LINE__, pdbg); pdbg = NULL 43 43 #define PDBG(arg) fprintf(pdbg, "PDBG: step %d\n", arg); fflush(pdbg) 44 44 #define PDBG_D(arg) fprintf(pdbg, "PDBG: %d\n", arg); fflush(pdbg) … … 46 46 47 47 #define PDBGC_OPEN if (pdbgc == NULL) pdbgc = fopen(PDGBFILE"child", "a") 48 #define PDBGC_CLOSE fclose (pdbgc); pdbgc = NULL48 #define PDBGC_CLOSE sl_fclose (FIL__, __LINE__, pdbgc); pdbgc = NULL 49 49 #define PDBGC(arg) fprintf(pdbgc, "PDBGC: step %d\n", arg); fflush(pdbgc) 50 50 #define PDBGC_D(arg) fprintf(pdbgc, "PDBGC: %d\n", arg); fflush(pdbgc) … … 238 238 PDBG_S("fork() failure"); 239 239 /*@-usedef@*/ 240 (void) close(pipedes[0]);241 (void) close(pipedes[1]);240 (void) sl_close_fd(FIL__, __LINE__, pipedes[0]); 241 (void) sl_close_fd(FIL__, __LINE__, pipedes[1]); 242 242 /*@+usedef@*/ 243 243 errnum = errno; … … 297 297 /* close the pipe descriptors 298 298 */ 299 (void) close (pipedes[STDIN_FILENO]);300 (void) close (pipedes[STDOUT_FILENO]);299 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDIN_FILENO]); 300 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 301 301 302 302 /* don't leak file descriptors … … 442 442 sl_close(fd); 443 443 else if (pfd != -1) 444 close(pfd);444 sl_close_fd(FIL__, __LINE__, pfd); 445 445 } 446 446 #endif … … 496 496 { 497 497 PDBG_S("is w"); 498 (void) close (pipedes[STDIN_FILENO]);498 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDIN_FILENO]); 499 499 (void) retry_fcntl (FIL__, __LINE__, pipedes[STDOUT_FILENO], 500 500 F_SETFD, FD_CLOEXEC); … … 504 504 { 505 505 PDBG_S("is r"); 506 (void) close (pipedes[STDOUT_FILENO]);506 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 507 507 (void) retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], 508 508 F_SETFD, FD_CLOEXEC); … … 526 526 527 527 (void) aud_kill (FIL__, __LINE__, task->pid, SIGKILL); 528 (void) close (pipedes[STDOUT_FILENO]);529 (void) close (pipedes[STDIN_FILENO]);528 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 529 (void) sl_close_fd (FIL__, __LINE__, pipedes[STDIN_FILENO]); 530 530 (void) waitpid (task->pid, NULL, 0); 531 531 task->pid = 0; … … 541 541 PDBG_D(task->pipeFD); 542 542 543 task->pipeTI = sl_make_ticket(FIL__, __LINE__, task->pipeFD, _("pipe") );543 task->pipeTI = sl_make_ticket(FIL__, __LINE__, task->pipeFD, _("pipe"), outf); 544 544 545 545 flags = (int) retry_fcntl (FIL__, __LINE__, task->pipeFD, F_GETFL, 0); … … 572 572 PDBG_S(" -> pclose"); 573 573 (void) fflush(task->pipe); 574 (void) fclose(task->pipe);575 574 if (!SL_ISERROR(task->pipeTI)) 576 575 (void) sl_close(task->pipeTI); -
trunk/src/sh_forward.c
r248 r252 1753 1753 } 1754 1754 1755 (void) close (sockfd);1755 (void) sl_close_fd (FIL__, __LINE__, sockfd); 1756 1756 memset(answer, 0, TRANS_BYTES + 256); 1757 1757 MUNLOCK(answer, TRANS_BYTES + 256); … … 1763 1763 } 1764 1764 1765 (void) close (sockfd);1765 (void) sl_close_fd (FIL__, __LINE__, sockfd); 1766 1766 memset(answer, 0, TRANS_BYTES + 256); 1767 1767 MUNLOCK(answer, TRANS_BYTES + 256); … … 1775 1775 1776 1776 1777 (void) close (sockfd);1777 (void) sl_close_fd (FIL__, __LINE__, sockfd); 1778 1778 memset(answer, 0, 512); 1779 1779 MUNLOCK(answer, 512); … … 2203 2203 if (conn->fd != (-1)) 2204 2204 { 2205 close (conn->fd);2205 sl_close_fd (FIL__, __LINE__, conn->fd); 2206 2206 conn->fd = -1; 2207 2207 } … … 4681 4681 newconn->fd = -1; 4682 4682 newconn->state = CONN_FREE; 4683 close(rc);4683 sl_close_fd(FIL__, __LINE__, rc); 4684 4684 SL_RETURN( (-1), _("sh_forward_accept")); 4685 4685 } … … 4698 4698 newconn->fd = -1; 4699 4699 newconn->state = CONN_FREE; 4700 close(rc);4700 sl_close_fd(FIL__, __LINE__, rc); 4701 4701 SL_RETURN( (-1), _("sh_forward_accept")); 4702 4702 } … … 5780 5780 */ 5781 5781 TPT(( 0, FIL__, __LINE__, _("msg=<close syslog socket>\n"))); 5782 close(syslog_sock);5782 sl_close_fd(FIL__, __LINE__, syslog_sock); 5783 5783 syslog_sock = -1; 5784 5784 } … … 5830 5830 errnum = errno; 5831 5831 sh_forward_printerr (_("syslog bind"), errnum, 514, __LINE__); 5832 close(sock);5832 sl_close_fd(FIL__, __LINE__, sock); 5833 5833 SL_RETURN((-1), _("create_syslog_socket")); 5834 5834 } -
trunk/src/sh_gpg.c
r248 r252 88 88 FILE * pdbgc; 89 89 #define PDBG_OPEN pdbg = fopen(PDGBFILE"main", "a") 90 #define PDBG_CLOSE fclose (pdbg)90 #define PDBG_CLOSE sl_fclose (FIL__, __LINE__, pdbg) 91 91 #define PDBG(arg) fprintf(pdbg, "PDBG: step %d\n", arg); fflush(pdbg) 92 92 #define PDBG_D(arg) fprintf(pdbg, "PDBG: %d\n", arg); fflush(pdbg) … … 94 94 95 95 #define PDBGC_OPEN pdbgc = fopen(PDGBFILE"child", "a") 96 #define PDBGC_CLOSE fclose (pdbgc)96 #define PDBGC_CLOSE sl_fclose (FIL__, __LINE__, pdbgc) 97 97 #define PDBGC(arg) fprintf(pdbgc, "PDBG: step %d\n", arg); fflush(pdbgc) 98 98 #define PDBGC_D(arg) fprintf(pdbgc, "PDBG: %d\n", arg); fflush(pdbgc) … … 446 446 if (source->pid == (pid_t) - 1) 447 447 { 448 close(pipedes[0]);449 close(pipedes[1]);448 sl_close_fd(FIL__, __LINE__, pipedes[0]); 449 sl_close_fd(FIL__, __LINE__, pipedes[1]); 450 450 if (envp[0] != NULL) 451 451 free(envp[0]); … … 468 468 /* close the pipe descriptors 469 469 */ 470 close (pipedes[STDIN_FILENO]);471 close (pipedes[STDOUT_FILENO]);470 sl_close_fd (FIL__, __LINE__, pipedes[STDIN_FILENO]); 471 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 472 472 473 473 … … 618 618 free(envp[0]); 619 619 620 close (pipedes[STDOUT_FILENO]);620 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 621 621 retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC); 622 622 retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], F_SETFL, O_NONBLOCK); … … 627 627 { 628 628 aud_kill (FIL__, __LINE__, source->pid, SIGKILL); 629 close (pipedes[STDOUT_FILENO]);629 sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]); 630 630 waitpid (source->pid, NULL, 0); 631 631 source->pid = 0; … … 643 643 SL_ENTER(_("sh_gpg_pclose")); 644 644 645 status = fclose(source->pipe);645 status = sl_fclose(FIL__, __LINE__, source->pipe); 646 646 if (status) 647 647 SL_RETURN( (-1), _("sh_gpg_pclose")); -
trunk/src/sh_hash.c
r248 r252 786 786 static void sh_hash_getline_end (void) 787 787 { 788 fclose (sh_fin_fd);788 sl_fclose (FIL__, __LINE__, sh_fin_fd); 789 789 sh_fin_fd = NULL; 790 790 return; … … 816 816 if (sh_fin_fd != NULL) 817 817 { 818 fclose (sh_fin_fd);818 sl_fclose (FIL__, __LINE__, sh_fin_fd); 819 819 sh_fin_fd = NULL; 820 820 } … … 1307 1307 SH_FREE(buf); 1308 1308 sl_close(fd); 1309 fclose(fin_cp);1309 sl_fclose(FIL__, __LINE__, fin_cp); /* fin_cp = fdopen(dup(), "rb"); */ 1310 1310 1311 1311 fd = fdTmp; -
trunk/src/sh_kern.c
r223 r252 559 559 struct proc_dir_entry proc_root_dir; 560 560 561 int status = close(mpipe[0]);561 int status = sl_close_fd(FIL__, __LINE__, mpipe[0]); 562 562 563 563 setpgid(0, 0); … … 710 710 /* Close reading side of pipe, and wait some milliseconds 711 711 */ 712 close (mpipe[1]);712 sl_close_fd (FIL__, __LINE__, mpipe[1]); 713 713 retry_msleep (0, ShKernDelay); /* milliseconds */ 714 714 … … 789 789 status = WEXITSTATUS(status); 790 790 } 791 close (mpipe[0]);791 sl_close_fd (FIL__, __LINE__, mpipe[0]); 792 792 if (res <= 0) 793 793 { … … 989 989 status = write( fd, "1", 1 ); 990 990 } while (status < 0 && errno == EINTR); 991 close (fd );991 sl_close_fd (FIL__, __LINE__, fd ); 992 992 993 993 if (status > 0) … … 1001 1001 status = write( fd, "0", 1 ); 1002 1002 } while (status < 0 && errno == EINTR); 1003 close (fd );1003 sl_close_fd (FIL__, __LINE__, fd ); 1004 1004 } 1005 1005 } … … 1385 1385 */ 1386 1386 default: 1387 close(kd);1387 sl_close_fd(FIL__, __LINE__, kd); 1388 1388 status = read_from_child(mpid, mpipe, &kinfo); 1389 1389 break; -
trunk/src/sh_log_check.c
r237 r252 108 108 if (1 != fwrite(&save_rec, sizeof(struct logfile_record), 1, fd)) 109 109 { 110 (void) fclose(fd);110 (void) sl_fclose(FIL__, __LINE__, fd); 111 111 (void) remove(path); 112 112 } 113 113 else 114 114 { 115 (void) fclose(fd);115 (void) sl_fclose(FIL__, __LINE__, fd); 116 116 } 117 117 } … … 144 144 } 145 145 } 146 (void) fclose(fd);146 (void) sl_fclose(FIL__, __LINE__, fd); 147 147 } 148 148 SH_FREE(path); … … 329 329 330 330 if (thisfile->fp) 331 fclose(thisfile->fp);331 sl_fclose(FIL__, __LINE__, thisfile->fp); 332 332 if (thisfile->filename) 333 333 SH_FREE(thisfile->filename); … … 614 614 { 615 615 fgetpos(logfile->fp, &(logfile->offset)); 616 fclose(logfile->fp);616 sl_fclose(FIL__, __LINE__, logfile->fp); 617 617 logfile->fp = NULL; 618 618 sh_string_destroy(&s); … … 690 690 { 691 691 fgetpos(logfile->fp, &(logfile->offset)); 692 fclose(logfile->fp);692 sl_fclose(FIL__, __LINE__, logfile->fp); 693 693 logfile->fp = NULL; 694 694 sh_string_destroy(&s); … … 744 744 } 745 745 fgetpos(logfile->fp, &(logfile->offset)); 746 fclose(logfile->fp);746 sl_fclose(FIL__, __LINE__, logfile->fp); 747 747 logfile->fp = NULL; 748 748 memset(s, '\0', size); … … 1168 1168 } 1169 1169 1170 fclose(fp); remove(template);1170 sl_fclose(FIL__, __LINE__, fp); remove(template); 1171 1171 1172 1172 -
trunk/src/sh_mail.c
r248 r252 734 734 if (connfile != NULL) 735 735 { 736 (void) fclose (connfile);736 (void) sl_fclose (FIL__, __LINE__, connfile); 737 737 connfile = NULL; 738 738 } … … 795 795 if (connfile != NULL) 796 796 { 797 (void) fclose (connfile);797 (void) sl_fclose (FIL__, __LINE__, connfile); 798 798 connfile = NULL; 799 799 } … … 1091 1091 { 1092 1092 TPT(( 0, FIL__, __LINE__, _("msg=<fdopen() failed>\n"))); 1093 (void) close(fd);1093 (void) sl_close_fd(FIL__, __LINE__, fd); 1094 1094 SL_RETURN( NULL, _("sh_mail_start_conn")); 1095 1095 } … … 1105 1105 _("mail"), sh.host.name); 1106 1106 TPT(( 0, FIL__, __LINE__, _("msg=<Timeout>\n"))); 1107 (void) fclose(connFile);1107 (void) sl_fclose(FIL__, __LINE__, connFile); 1108 1108 SL_RETURN( NULL, _("sh_mail_start_conn")); 1109 1109 } … … 1135 1135 1136 1136 TPT(( 0, FIL__, __LINE__, _("msg=<Timeout.>\n"))); 1137 (void) fclose(connFile);1137 (void) sl_fclose(FIL__, __LINE__, connFile); 1138 1138 SL_RETURN( NULL, _("sh_mail_start_conn")); 1139 1139 } … … 1167 1167 _("mail"), this_address); 1168 1168 TPT(( 0, FIL__, __LINE__, _("msg=<Timeout.>\n"))); 1169 (void) fclose(connFile);1169 (void) sl_fclose(FIL__, __LINE__, connFile); 1170 1170 SL_RETURN( NULL, _("sh_mail_start_conn")); 1171 1171 } … … 1188 1188 _("mail"), address); 1189 1189 TPT(( 0, FIL__, __LINE__, _("msg=<Timeout.>\n"))); 1190 (void) fclose(connFile);1190 (void) sl_fclose(FIL__, __LINE__, connFile); 1191 1191 SL_RETURN( NULL, _("sh_mail_start_conn")); 1192 1192 } … … 1234 1234 if (ecount == address_num) 1235 1235 { 1236 (void) fclose(connFile);1236 (void) sl_fclose(FIL__, __LINE__, connFile); 1237 1237 SL_RETURN( NULL, _("sh_mail_start_conn")); 1238 1238 } … … 1253 1253 _("mail"), address); 1254 1254 TPT(( 0, FIL__, __LINE__, _("msg=<Timeout.>\n"))); 1255 (void) fclose(connFile);1255 (void) sl_fclose(FIL__, __LINE__, connFile); 1256 1256 SL_RETURN( NULL, _("sh_mail_start_conn")); 1257 1257 } -
trunk/src/sh_mem.c
r170 r252 100 100 this = this->next; 101 101 } 102 fclose(fd);102 sl_fclose(FIL__, __LINE__, fd); 103 103 104 104 SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem); -
trunk/src/sh_mounts.c
r184 r252 749 749 } 750 750 751 fclose(tab);751 sl_fclose(FIL__, __LINE__, tab); 752 752 } 753 753 #endif … … 806 806 } 807 807 808 (void) fclose(tab);808 (void) sl_fclose(FIL__, __LINE__, tab); 809 809 aix_fs_get (NULL, NULL); /* reset */ 810 810 } -
trunk/src/sh_port2proc.c
r251 r252 182 182 if (*ptr == '\0' || *ptr == '\n') 183 183 { 184 fclose(fd);184 sl_fclose(FIL__, __LINE__, fd); 185 185 *procpid = (size_t) pid; 186 186 SL_RETURN(0, _("proc_max_pid")); 187 187 } 188 188 } 189 fclose(fd);189 sl_fclose(FIL__, __LINE__, fd); 190 190 } 191 191 } … … 415 415 } 416 416 #endif 417 fclose(fd);417 sl_fclose(FIL__, __LINE__, fd); 418 418 *pid = (unsigned long) new->pid; 419 419 if (new->path) … … 432 432 } 433 433 } 434 fclose(fd);434 sl_fclose(FIL__, __LINE__, fd); 435 435 } 436 436 err_out: -
trunk/src/sh_portcheck.c
r237 r252 312 312 SH_FREE(splits); 313 313 sh_string_destroy(&s); 314 fclose(fp);314 sl_fclose(FIL__, __LINE__, fp); 315 315 return buf; 316 316 } … … 320 320 } 321 321 sh_string_destroy(&s); 322 fclose(fp);322 sl_fclose(FIL__, __LINE__, fp); 323 323 } 324 324 return NULL; … … 360 360 SH_FREE(splits); 361 361 sh_string_destroy(&s); 362 fclose(fp);362 sl_fclose(FIL__, __LINE__, fp); 363 363 return buf; 364 364 } … … 369 369 } 370 370 sh_string_destroy(&s); 371 fclose(fp);371 sl_fclose(FIL__, __LINE__, fp); 372 372 } 373 373 return NULL; … … 874 874 } 875 875 } 876 close (fd);876 sl_close_fd (FIL__, __LINE__, fd); 877 877 return 0; 878 878 } … … 988 988 port); 989 989 } 990 close (fd);990 sl_close_fd (FIL__, __LINE__, fd); 991 991 return 0; 992 992 } … … 1226 1226 for (port = min_port; port <= max_port; ++port) 1227 1227 { 1228 1229 1228 if ((sock = socket(AF_INET, type, protocol)) < 0 ) 1230 1229 { … … 1265 1264 /* we can bind the port, thus it is unused 1266 1265 */ 1267 close (sock);1266 sl_close_fd (FIL__, __LINE__, sock); 1268 1267 } 1269 1268 else … … 1290 1289 #endif 1291 1290 } 1292 close (sock);1291 sl_close_fd (FIL__, __LINE__, sock); 1293 1292 } 1294 1293 } -
trunk/src/sh_processcheck.c
r230 r252 683 683 if (*ptr == '\0' || *ptr == '\n') 684 684 { 685 fclose(fd);685 sl_fclose(FIL__, __LINE__, fd); 686 686 *procpid = (size_t) pid; 687 687 SL_RETURN(0, _("proc_max_pid")); 688 688 } 689 689 } 690 fclose(fd);690 sl_fclose(FIL__, __LINE__, fd); 691 691 } 692 692 } -
trunk/src/sh_socket.c
r200 r252 396 396 if (sizeof(name.sun_path) < (1 + sl_strlen(sh_sockname))) 397 397 { 398 close(pf_unix_fd); pf_unix_fd = -1;398 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 399 399 sh_error_handle ((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 400 400 _("PID dir path too long"), … … 418 418 if (sh_socket_remove() < 0) 419 419 { 420 close(pf_unix_fd); pf_unix_fd = -1;420 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 421 421 sh_error_handle ((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 422 422 _("Unlink of socket failed, maybe path not trusted"), … … 428 428 if (bind ((pf_unix_fd), (struct sockaddr *) &name, size) < 0) 429 429 { 430 close(pf_unix_fd); pf_unix_fd = -1;430 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 431 431 sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 432 432 sh_error_message (errno, errbuf, sizeof(errbuf)), … … 439 439 &optval, sizeof(optval))) 440 440 { 441 close(pf_unix_fd); pf_unix_fd = -1;441 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 442 442 sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 443 443 sh_error_message (errno, errbuf, sizeof(errbuf)), … … 450 450 if (flags < 0) 451 451 { 452 close(pf_unix_fd); pf_unix_fd = -1;452 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 453 453 sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 454 454 sh_error_message (errno, errbuf, sizeof(errbuf)), … … 460 460 if (flags < 0) 461 461 { 462 close(pf_unix_fd); pf_unix_fd = -1;462 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 463 463 sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 464 464 sh_error_message (errno, errbuf, sizeof(errbuf)), … … 469 469 if (0 != listen(pf_unix_fd, 5)) 470 470 { 471 close(pf_unix_fd); pf_unix_fd = -1;471 sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1; 472 472 sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 473 473 sh_error_message (errno, errbuf, sizeof(errbuf)), … … 630 630 sh_error_message (errno, errbuf, sizeof(errbuf)), 631 631 _("sh_socket_read: setsockopt")); 632 close(talkfd);632 sl_close_fd(FIL__, __LINE__, talkfd); 633 633 return -1; 634 634 } … … 643 643 sh_error_message (errno, errbuf, sizeof(errbuf)), 644 644 _("sh_socket_read: recvmsg")); 645 close(talkfd);645 sl_close_fd(FIL__, __LINE__, talkfd); 646 646 return -1; 647 647 } … … 666 666 { 667 667 /* no data */ 668 close(talkfd);668 sl_close_fd(FIL__, __LINE__, talkfd); 669 669 return 0; 670 670 } … … 672 672 sh_error_message (errno, errbuf, sizeof(errbuf)), 673 673 _("sh_socket_read: recvfrom")); 674 close(talkfd);674 sl_close_fd(FIL__, __LINE__, talkfd); 675 675 return -1; 676 676 } … … 682 682 sh_error_message (errno, errbuf, sizeof(errbuf)), 683 683 _("sh_socket_read: getpeereid")); 684 close(talkfd);684 sl_close_fd(FIL__, __LINE__, talkfd); 685 685 return -1; 686 686 } … … 693 693 sh_error_message (errno, errbuf, sizeof(errbuf)), 694 694 _("sh_socket_read: getsockopt")); 695 close(talkfd);695 sl_close_fd(FIL__, __LINE__, talkfd); 696 696 return -1; 697 697 } … … 744 744 fdmax = data_size / sizeof(int); 745 745 for (fdcount = 0; fdcount < fdmax; ++fdcount) 746 (void) close(fdsbuf[fdcount]);746 (void) sl_close_fd(FIL__, __LINE__, fdsbuf[fdcount]); 747 747 } 748 748 } 749 749 750 close(talkfd);750 sl_close_fd(FIL__, __LINE__, talkfd); 751 751 return -1; 752 752 } … … 775 775 _("sh_socket_read")); 776 776 sh_set_sockpass(); 777 close(talkfd);777 sl_close_fd(FIL__, __LINE__, talkfd); 778 778 return -1; 779 779 } … … 782 782 _("Socket credentials not supported on this OS"), 783 783 _("sh_socket_read")); 784 close(talkfd);784 sl_close_fd(FIL__, __LINE__, talkfd); 785 785 return -1; 786 786 #endif … … 796 796 _("client does not have required uid"), 797 797 _("sh_socket_read: getsockopt")); 798 close(talkfd);798 sl_close_fd(FIL__, __LINE__, talkfd); 799 799 return -1; 800 800 } … … 816 816 _("Bad message format: command too long"), 817 817 _("sh_socket_read")); 818 close(talkfd);818 sl_close_fd(FIL__, __LINE__, talkfd); 819 819 return -1; 820 820 } … … 824 824 _("Bad message format: hostname too long"), 825 825 _("sh_socket_read")); 826 close(talkfd);826 sl_close_fd(FIL__, __LINE__, talkfd); 827 827 return -1; 828 828 } … … 848 848 _("Bad message format"), 849 849 _("sh_socket_read")); 850 close(talkfd);850 sl_close_fd(FIL__, __LINE__, talkfd); 851 851 return -1; 852 852 } … … 865 865 */ 866 866 nbytes = send (talkfd, cmd, strlen(cmd) + 1, 0); 867 close(talkfd);867 sl_close_fd(FIL__, __LINE__, talkfd); 868 868 if (nbytes < 0) 869 869 { … … 904 904 sh_error_message (errno, errbuf, sizeof(errbuf)), 905 905 _("sh_socket_read: sendto")); 906 close(talkfd);906 sl_close_fd(FIL__, __LINE__, talkfd); 907 907 return -1; 908 908 } … … 935 935 sh_error_message (errno, errbuf, sizeof(errbuf)), 936 936 _("sh_socket_read: sendto")); 937 close(talkfd);937 sl_close_fd(FIL__, __LINE__, talkfd); 938 938 return -1; 939 939 } … … 946 946 */ 947 947 nbytes = send (talkfd, _("END"), 4, 0); 948 close(talkfd);948 sl_close_fd(FIL__, __LINE__, talkfd); 949 949 return 0; 950 950 } -
trunk/src/sh_static.c
r170 r252 54 54 #include "sh_pthread.h" 55 55 56 extern int sl_close_fd (const char * file, int line, int fd); 57 extern int sl_fclose (const char * file, int line, FILE * fp); 58 59 56 60 #ifndef _PATH_PASSWD 57 61 #define _PATH_PASSWD "/etc/passwd" … … 60 64 #define _PATH_GROUP "/etc/group" 61 65 #endif 66 67 #undef FIL__ 68 #define FIL__ _("sh_static.c") 62 69 63 70 extern int sl_strlcpy(char * dst, /*@null@*/const char * src, size_t siz); … … 123 130 } 124 131 } while (1); 125 fclose(stream);132 sl_fclose(FIL__, __LINE__, stream); 126 133 } 127 134 … … 171 178 } 172 179 } while (1); 173 fclose(stream);180 sl_fclose(FIL__, __LINE__, stream); 174 181 } 175 182 … … 219 226 } 220 227 } while (1); 221 fclose(stream);228 sl_fclose(FIL__, __LINE__, stream); 222 229 } 223 230 … … 267 274 } 268 275 } while (1); 269 fclose(stream);276 sl_fclose(FIL__, __LINE__, stream); 270 277 } 271 278 … … 341 348 SH_MUTEX_LOCK(pwf_lock); 342 349 if (pwf) { 343 fclose(pwf);350 sl_fclose(FIL__, __LINE__, pwf); 344 351 pwf = NULL; 345 352 } … … 395 402 SH_MUTEX_LOCK(grf_lock); 396 403 if (grf) { 397 fclose(grf);404 sl_fclose(FIL__, __LINE__, grf); 398 405 grf = NULL; 399 406 } … … 498 505 rv = setgroups(num_groups, group_list); 499 506 DO_CLOSE: 500 fclose(grf);507 sl_fclose(FIL__, __LINE__, grf); 501 508 } 502 509 … … 863 870 #include <arpa/inet.h> 864 871 865 /* close()872 /* sl_close_fd(FIL__, __LINE__, ) 866 873 */ 867 874 #include <unistd.h> … … 1185 1192 while (retries++ < MAX_RETRIES) { 1186 1193 if (fd != -1) 1187 close(fd);1194 sl_close_fd(FIL__, __LINE__, fd); 1188 1195 1189 1196 memset(packet, 0, PACKETSZ); … … 1344 1351 DPRINTF("Answer type = |%d|\n", a->atype); 1345 1352 1346 close(fd);1353 sl_close_fd(FIL__, __LINE__, fd); 1347 1354 1348 1355 if (outpacket) … … 1390 1397 fail: 1391 1398 if (fd != -1) 1392 close(fd);1399 sl_close_fd(FIL__, __LINE__, fd); 1393 1400 if (lookup) 1394 1401 free(lookup); … … 1546 1553 1547 1554 if (action!=GETHOSTENT) { 1548 fclose(fp);1555 sl_fclose(FIL__, __LINE__, fp); 1549 1556 } 1550 1557 return ret; 1551 1558 } 1552 1559 if (action!=GETHOSTENT) { 1553 fclose(fp);1560 sl_fclose(FIL__, __LINE__, fp); 1554 1561 } 1555 1562 return ret; … … 1619 1626 } 1620 1627 } 1621 fclose(fp);1628 sl_fclose(FIL__, __LINE__, fp); 1622 1629 } else { 1623 1630 DPRINTF("failed to open %s\n", "resolv.conf"); -
trunk/src/sh_suidchk.c
r249 r252 294 294 MSG_SUID_ERROR, 295 295 sh_error_message(errno, errbuf, sizeof(errbuf))); 296 (void) close(fd);296 (void) sl_close_fd(FIL__, __LINE__, fd); 297 297 return -1; 298 298 } … … 303 303 MSG_SUID_ERROR, 304 304 _("Possible race: lstat != fstat")); 305 (void) close(fd);305 (void) sl_close_fd(FIL__, __LINE__, fd); 306 306 return -1; 307 307 } … … 311 311 MSG_SUID_ERROR, 312 312 _("Possible race: not a regular file")); 313 (void) close(fd);313 (void) sl_close_fd(FIL__, __LINE__, fd); 314 314 return -1; 315 315 } … … 319 319 MSG_SUID_ERROR, 320 320 _("Possible race: not a suid/sgid file")); 321 (void) close(fd);321 (void) sl_close_fd(FIL__, __LINE__, fd); 322 322 return -1; 323 323 } … … 334 334 MSG_SUID_ERROR, 335 335 sh_error_message(errno, errbuf, sizeof(errbuf))); 336 (void) close(fd);336 (void) sl_close_fd(FIL__, __LINE__, fd); 337 337 return -1; 338 338 } … … 341 341 MSG_SUID_ERROR, 342 342 _("The fchmod() function is not available")); 343 (void) close(fd);343 (void) sl_close_fd(FIL__, __LINE__, fd); 344 344 return -1; 345 345 #endif … … 349 349 MSG_SUID_ERROR, 350 350 _("Not truncated because hardlink count gt 1")); 351 (void) close(fd);351 (void) sl_close_fd(FIL__, __LINE__, fd); 352 352 return -1; 353 353 } … … 359 359 MSG_SUID_ERROR, 360 360 sh_error_message(errno, errbuf, sizeof(errbuf))); 361 (void) close(fd);361 (void) sl_close_fd(FIL__, __LINE__, fd); 362 362 return -1; 363 363 } … … 370 370 MSG_SUID_ERROR, 371 371 sh_error_message(errno, errbuf, sizeof(errbuf))); 372 (void) close(fd);372 (void) sl_close_fd(FIL__, __LINE__, fd); 373 373 return -1; 374 374 } 375 375 } 376 (void) close (fd);376 (void) sl_close_fd (FIL__, __LINE__, fd); 377 377 return (0); 378 378 } … … 568 568 } 569 569 570 (void) close (readFile);570 (void) sl_close_fd (FIL__, __LINE__, readFile); 571 571 (void) fchmod(writeFile, S_IRUSR | S_IWUSR | S_IXUSR); 572 (void) close (writeFile);572 (void) sl_close_fd (FIL__, __LINE__, writeFile); 573 573 574 574 if (do_truncate (fullpath) == -1) … … 613 613 theFile->c_group, (int) theFile->group, 614 614 timestrc, timestra, timestrm); 615 (void) fclose (filePtr);615 (void) sl_fclose (FIL__, __LINE__, filePtr); 616 616 } 617 617 /*@+usedef@*/ … … 788 788 { 789 789 do { 790 status = close (file_d);790 status = sl_close_fd (FIL__, __LINE__, file_d); 791 791 } while (status == -1 && errno == EINTR); 792 792 … … 985 985 if (status != 0) 986 986 { 987 int elevel = SH_ERR_ERR; 988 size_t tlen; 989 987 990 status = errno; 988 991 tmp = sh_util_safe_name(tmpcat); 989 sh_error_handle (SH_ERR_ERR, FIL__, __LINE__, status, MSG_ERR_LSTAT, 992 tlen = strlen(tmp); 993 if (tlen >= 6 && 0 == strcmp(&tmp[tlen-6], _("/.gvfs"))) 994 elevel = SH_ERR_NOTICE; 995 sh_error_handle (elevel, FIL__, __LINE__, status, MSG_ERR_LSTAT, 990 996 sh_error_message(status, errbuf, sizeof(errbuf)), 991 tmp cat);997 tmp ); 992 998 SH_FREE(tmp); 993 999 } … … 2034 2040 if (stat (mnt->mnt_dir, &disk_stats) == -1) 2035 2041 { 2036 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN, 2037 _("stat() failed"), 2042 char errmsg[256]; 2043 int elevel = SH_ERR_ERR; 2044 size_t tlen = strlen(mnt->mnt_dir); 2045 if (tlen >= 6 && 0 == strcmp(&((mnt->mnt_dir)[tlen-6]), _("/.gvfs"))) 2046 elevel = SH_ERR_NOTICE; 2047 sl_snprintf(errmsg, sizeof(errmsg), _("stat(%s) failed"), 2048 mnt->mnt_dir); 2049 sh_error_handle (elevel, FIL__, __LINE__, 0, MSG_E_SUBGEN, 2050 errmsg, 2038 2051 _("filesystem_type_uncached") ); 2039 2052 return NULL; -
trunk/src/sh_tools.c
r248 r252 149 149 if (errno == EACCES || errno == EADDRINUSE) 150 150 retval = 1; 151 close (sd);151 sl_close_fd (FIL__, __LINE__, sd); 152 152 return retval; 153 153 } … … 155 155 /* bind() succeeds, iface exists 156 156 */ 157 close(sd);157 sl_close_fd(FIL__, __LINE__, sd); 158 158 return 1; 159 159 } … … 702 702 sl_strlcat(errmsg, _(", address "), errsiz); 703 703 sl_strlcat(errmsg, address, errsiz); 704 close(fd);704 sl_close_fd(FIL__, __LINE__, fd); 705 705 fail = (-1); 706 706 } -
trunk/src/sh_unix.c
r251 r252 1293 1293 fd++; 1294 1294 else 1295 close(fd++);1295 sl_close_fd(FIL__, __LINE__, fd++); 1296 1296 } 1297 1297 … … 1971 1971 /* Close first tree file descriptors 1972 1972 */ 1973 close (0); /* if running as daemon */1974 close (1); /* if running as daemon */1975 close (2); /* if running as daemon */1973 sl_close_fd (FIL__, __LINE__, 0); /* if running as daemon */ 1974 sl_close_fd (FIL__, __LINE__, 1); /* if running as daemon */ 1975 sl_close_fd (FIL__, __LINE__, 2); /* if running as daemon */ 1976 1976 1977 1977 /* Enable full error logging … … 2306 2306 _("time"), sh.srvtime.name); 2307 2307 } 2308 close(fd);2308 sl_close_fd(FIL__, __LINE__, fd); 2309 2309 } 2310 2310 else … … 2910 2910 2911 2911 r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); 2912 /* close (fd); */2912 /* sl_close_fd (FIL__, __LINE__, fd); */ 2913 2913 2914 2914 if (r == -1) … … 3439 3439 int fstat_return; 3440 3440 int fstat_errno = 0; 3441 int try = 0; 3441 3442 3442 3443 sh_string * content = NULL; … … 3464 3465 stat_errno = errno; 3465 3466 3467 theFile->link_path = NULL; 3468 3469 try_again: 3470 3466 3471 fd = -1; 3467 3472 fstat_return = -1; 3468 3473 rval_open = -1; 3469 3474 3470 theFile->link_path = NULL;3471 3472 3475 if (stat_return == 0 && S_ISREG(buf.st_mode)) 3473 3476 { … … 3475 3478 path /* theFile->fullpath */, SL_YESPRIV); 3476 3479 if (SL_ISERROR(rval_open)) 3477 err_open = errno; 3478 3479 { 3480 char * stale = sl_check_stale(); 3481 3482 if (stale) 3483 { 3484 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, err_open, MSG_E_SUBGEN, 3485 stale, _("sh_unix_getinfo_open")); 3486 } 3487 } 3480 { 3481 char * stale = sl_check_stale(); 3482 3483 if (stale) 3484 { 3485 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, err_open, MSG_E_SUBGEN, 3486 stale, _("sh_unix_getinfo_open")); 3487 } 3488 3489 if (errno == EBADF && try == 0) /* obsolete, but we keep this, just in case */ 3490 { 3491 ++try; 3492 goto try_again; 3493 } 3494 err_open = errno; 3495 } 3488 3496 3489 3497 alert_timeout = 120; /* this is per 8K block now ! */ … … 3529 3537 MSG_E_SUBGEN, 3530 3538 stale, _("sh_unix_getinfo_fstat")); 3539 } 3540 3541 if (try == 0) /* obsolete, but we keep this, just in case */ 3542 { 3543 ++try; 3544 sl_close(rval_open); 3545 goto try_again; 3531 3546 } 3532 3547 } -
trunk/src/sh_utmp.c
r170 r252 283 283 if (sh_utmpfile != NULL) 284 284 { 285 (void) fclose (sh_utmpfile);285 (void) sl_fclose (FIL__, __LINE__, sh_utmpfile); 286 286 sh_utmpfile = NULL; 287 287 } … … 341 341 SL_ENTER(_("sh_utmp_endutent")); 342 342 if (NULL != sh_utmpfile) 343 (void) fclose(sh_utmpfile);343 (void) sl_fclose(FIL__, __LINE__, sh_utmpfile); 344 344 sh_utmpfile = NULL; 345 345 SL_RET0(_("sh_utmp_endutent")); -
trunk/src/slib.c
r248 r252 1559 1559 SL_TICKET ticket; /* The unique ID. */ 1560 1560 int fd; /* The file descriptor. */ 1561 FILE * stream; /* The file descriptor. */ 1561 1562 char * path; /* The file path. */ 1562 1563 int flush; /* Whether we want to flush the cache */ … … 1571 1572 static int stale_orig_line = -1; 1572 1573 static char stale_orig_mesg[128]; 1574 1575 static char badfd_orig_file[64] = { '\0' }; 1576 static int badfd_orig_line = -1; 1577 static char badfd_orig_mesg[128]; 1573 1578 1574 1579 SH_MUTEX_STATIC(mutex_ticket, PTHREAD_MUTEX_INITIALIZER); … … 1587 1592 } 1588 1593 1594 char * sl_check_badfd() 1595 { 1596 if (badfd_orig_line == -1) 1597 return NULL; 1598 sl_snprintf(badfd_orig_mesg, sizeof(badfd_orig_mesg), 1599 _("close on file descriptor with allocated handle, %s, %d"), 1600 badfd_orig_file, badfd_orig_line); 1601 badfd_orig_file[0] = '\0'; 1602 badfd_orig_line = -1; 1603 return badfd_orig_mesg; 1604 } 1605 1589 1606 static 1590 1607 SL_TICKET sl_create_ticket (unsigned int myindex) … … 1666 1683 1667 1684 SL_TICKET sl_make_ticket (const char * ofile, int oline, 1668 int fd, const char * filename )1685 int fd, const char * filename, FILE * stream) 1669 1686 { 1670 1687 size_t len; … … 1721 1738 ofiles[fd]->fd = fd; 1722 1739 ofiles[fd]->content = NULL; 1740 ofiles[fd]->stream = stream; 1723 1741 ofiles[fd]->flush = SL_FALSE; 1724 1742 … … 1786 1804 * the mask is returned." 1787 1805 */ 1788 (void) umask (0); 1806 (void) umask (0); 1789 1807 1790 1808 if (mode == SL_OPEN_FOR_FASTREAD) … … 1927 1945 if (stat_return < 0) 1928 1946 { 1929 close (fd);1947 sl_close_fd (FIL__, __LINE__, fd); 1930 1948 errno = errval; 1931 1949 SL_IRETURN(SL_EFSTAT, _("sl_open_file")); … … 1936 1954 if (lstat_return != ENOENT && buf.st_ino != lbuf.st_ino) 1937 1955 { 1938 close (fd);1956 sl_close_fd (FIL__, __LINE__, fd); 1939 1957 SL_IRETURN(SL_EBOGUS, _("sl_open_file")); 1940 1958 } … … 1946 1964 if (fd >= MAXFD) 1947 1965 { 1948 close(fd);1966 sl_close_fd(FIL__, __LINE__, fd); 1949 1967 SL_IRETURN(SL_TOOMANY, _("sl_open_file")); 1950 1968 } … … 1953 1971 { 1954 1972 /* 1955 close(fd);1973 sl_close_fd(FIL__, __LINE__, fd); 1956 1974 SL_IRETURN(SL_EINTERNAL09, _("sl_open_file")); 1957 1975 */ … … 1968 1986 if ( (ofiles[fd] = (SL_OFILE *) malloc(sizeof(SL_OFILE))) == NULL) 1969 1987 { 1970 close(fd);1988 sl_close_fd(FIL__, __LINE__, fd); 1971 1989 SL_IRETURN(SL_EMEM, _("sl_open_file")); 1972 1990 } … … 1978 1996 free (ofiles[fd]); 1979 1997 ofiles[fd] = NULL; 1980 close(fd);1998 sl_close_fd(FIL__, __LINE__, fd); 1981 1999 SL_IRETURN(SL_EMEM, _("sl_open_file")); 1982 2000 } … … 1991 2009 (void) free (ofiles[fd]); 1992 2010 ofiles[fd] = NULL; 1993 close(fd);2011 sl_close_fd(FIL__, __LINE__, fd); 1994 2012 SL_IRETURN(ticket, _("sl_open_file")); 1995 2013 } … … 1999 2017 ofiles[fd]->fd = fd; 2000 2018 ofiles[fd]->content = NULL; 2019 ofiles[fd]->stream = NULL; 2001 2020 ofiles[fd]->flush = SL_FALSE; 2002 2021 … … 2005 2024 2006 2025 SL_IRETURN(ticket, _("sl_open_file")); 2026 } 2027 2028 FILE * sl_stream (SL_TICKET ticket, char * mode) 2029 { 2030 int fd; 2031 2032 if (SL_ISERROR(fd = sl_read_ticket(ticket))) 2033 return (NULL); 2034 2035 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || 2036 ticket != ofiles[fd]->ticket || fd < 0) 2037 return (NULL); 2038 2039 if (!ofiles[fd]->stream) 2040 ofiles[fd]->stream = fdopen(fd, mode); 2041 2042 return ofiles[fd]->stream; 2007 2043 } 2008 2044 … … 2259 2295 { 2260 2296 register int fd; 2297 FILE * fp = NULL; 2261 2298 2262 2299 SL_ENTER(_("sl_close")); … … 2276 2313 sh_string_destroy(&(ofiles[fd]->content)); 2277 2314 (void) free (ofiles[fd]->path); 2315 fp = ofiles[fd]->stream; 2278 2316 (void) free (ofiles[fd]); 2279 2317 ofiles[fd] = NULL; … … 2282 2320 /* This may fail, but what to do then ? 2283 2321 */ 2284 if (0 != close(fd)) 2285 { 2286 TPT((0, FIL__, __LINE__, 2287 _("msg=<Error closing file.>, fd=<%d>, err=<%s>\n"), 2288 fd, strerror(errno))); 2322 if (fp) 2323 { 2324 if (0 != fclose (fp)) /* within sl_close */ 2325 { 2326 TPT((0, FIL__, __LINE__, 2327 _("msg=<Error fclosing file.>, fd=<%d>, err=<%s>\n"), 2328 fd, strerror(errno))); 2329 } 2330 } 2331 else 2332 { 2333 if (0 != close(fd)) /* within sl_close */ 2334 { 2335 TPT((0, FIL__, __LINE__, 2336 _("msg=<Error closing file.>, fd=<%d>, err=<%s>\n"), 2337 fd, strerror(errno))); 2338 } 2289 2339 } 2290 2340 2291 2341 SL_IRETURN(SL_ENONE, _("sl_close")); 2342 } 2343 2344 int sl_close_fd (const char * file, int line, int fd) 2345 { 2346 int ret = -1; 2347 2348 SL_ENTER(_("sl_close_fd")); 2349 2350 if (fd >= 0 && fd < MAXFD && ofiles[fd] != NULL) /* stale ofiles[fd] handle */ 2351 { 2352 sl_strlcpy(badfd_orig_file, file, sizeof(badfd_orig_file)); 2353 badfd_orig_line = line; 2354 } 2355 2356 ret = close(fd); /* within sl_close_fd wrapper */ 2357 2358 SL_IRETURN(ret, _("sl_close_fd")); 2359 } 2360 2361 int sl_fclose (const char * file, int line, FILE * fp) 2362 { 2363 int ret = -1; 2364 int fd; 2365 2366 SL_ENTER(_("sl_fclose")); 2367 2368 fd = fileno(fp); 2369 2370 if (fd >= 0 && fd < MAXFD && ofiles[fd] != NULL) /* stale ofiles[fd] handle */ 2371 { 2372 sl_strlcpy(badfd_orig_file, file, sizeof(badfd_orig_file)); 2373 badfd_orig_line = line; 2374 } 2375 2376 ret = fclose(fp); /* within sl_fclose wrapper */ 2377 2378 SL_IRETURN(ret, _("sl_fclose")); 2292 2379 } 2293 2380
Note:
See TracChangeset
for help on using the changeset viewer.