Changeset 248 for trunk/src/slib.c
- Timestamp:
- Sep 21, 2009, 8:23:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r247 r248 1557 1557 1558 1558 typedef struct openfiles { 1559 SL_TICKET ticket; /* The unique ID. */ 1560 int fd; /* The file descriptor. */ 1561 char * path; /* The file path. */ 1562 int flush; /* Whether we want to flush the cache */ 1563 sh_string * content; /* The file content */ 1559 SL_TICKET ticket; /* The unique ID. */ 1560 int fd; /* The file descriptor. */ 1561 char * path; /* The file path. */ 1562 int flush; /* Whether we want to flush the cache */ 1563 char ofile[SL_OFILE_SIZE]; /* origin file */ 1564 int oline; /* origin line */ 1565 sh_string * content; /* The file content */ 1564 1566 } SL_OFILE; 1565 1567 1566 1568 static SL_OFILE * ofiles[MAXFD]; 1567 1569 1570 static char stale_orig_file[64] = { '\0' }; 1571 static int stale_orig_line = -1; 1572 static char stale_orig_mesg[128]; 1573 1568 1574 SH_MUTEX_STATIC(mutex_ticket, PTHREAD_MUTEX_INITIALIZER); 1569 1575 1570 1576 static unsigned int nonce_counter = TOFFSET; 1577 1578 char * sl_check_stale() 1579 { 1580 if (stale_orig_line == -1) 1581 return NULL; 1582 sl_snprintf(stale_orig_mesg, sizeof(stale_orig_mesg), 1583 _("stale handle, %s, %d"), stale_orig_file, stale_orig_line); 1584 stale_orig_file[0] = '\0'; 1585 stale_orig_line = -1; 1586 return stale_orig_mesg; 1587 } 1571 1588 1572 1589 static … … 1648 1665 } 1649 1666 1650 SL_TICKET sl_make_ticket (int fd, const char * filename) 1667 SL_TICKET sl_make_ticket (const char * ofile, int oline, 1668 int fd, const char * filename) 1651 1669 { 1652 1670 size_t len; … … 1660 1678 } 1661 1679 1662 if (ofiles[fd] != NULL) 1663 { 1664 SL_IRETURN(SL_EINTERNAL06, _("sl_make_ticket")); 1680 if (ofiles[fd] != NULL) /* stale entry */ 1681 { 1682 /* SL_IRETURN(SL_EINTERNAL06, _("sl_make_ticket")); */ 1683 sl_strlcpy(stale_orig_file, ofiles[fd]->ofile, sizeof(stale_orig_file)); 1684 stale_orig_line = ofiles[fd]->oline; 1685 1686 if (ofiles[fd]->content) 1687 sh_string_destroy(&(ofiles[fd]->content)); 1688 (void) free (ofiles[fd]->path); 1689 (void) free (ofiles[fd]); 1690 ofiles[fd] = NULL; 1665 1691 } 1666 1692 … … 1696 1722 ofiles[fd]->content = NULL; 1697 1723 ofiles[fd]->flush = SL_FALSE; 1724 1725 sl_strlcpy(ofiles[fd]->ofile, ofile, SL_OFILE_SIZE); 1726 ofiles[fd]->oline = oline; 1698 1727 1699 1728 SL_IRETURN(ticket, _("sl_make_ticket")); … … 1726 1755 1727 1756 static 1728 int sl_open_file (const char *filename, int mode, int priv) 1757 int sl_open_file (const char * ofile, int oline, 1758 const char *filename, int mode, int priv) 1729 1759 { 1730 1760 struct stat lbuf; … … 1920 1950 } 1921 1951 1922 if (ofiles[fd] != NULL) 1923 { 1952 if (ofiles[fd] != NULL) /* stale entry */ 1953 { 1954 /* 1924 1955 close(fd); 1925 1956 SL_IRETURN(SL_EINTERNAL09, _("sl_open_file")); 1957 */ 1958 sl_strlcpy(stale_orig_file, ofiles[fd]->ofile, sizeof(stale_orig_file)); 1959 stale_orig_line = ofiles[fd]->oline; 1960 1961 if (ofiles[fd]->content) 1962 sh_string_destroy(&(ofiles[fd]->content)); 1963 (void) free (ofiles[fd]->path); 1964 (void) free (ofiles[fd]); 1965 ofiles[fd] = NULL; 1926 1966 } 1927 1967 … … 1961 2001 ofiles[fd]->flush = SL_FALSE; 1962 2002 2003 sl_strlcpy(ofiles[fd]->ofile, ofile, SL_OFILE_SIZE); 2004 ofiles[fd]->oline = oline; 2005 1963 2006 SL_IRETURN(ticket, _("sl_open_file")); 1964 2007 } … … 1971 2014 return (fd); 1972 2015 1973 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 2016 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || 2017 ticket != ofiles[fd]->ticket || fd < 0) 1974 2018 return (SL_EINTERNAL10); 2019 1975 2020 return (fd); 1976 2021 } … … 1987 2032 } 1988 2033 1989 SL_TICKET sl_open_write (const char * fname, int priv) 2034 SL_TICKET sl_open_write (const char * ofile, int oline, 2035 const char * fname, int priv) 1990 2036 { 1991 2037 long status; … … 1995 2041 SL_IRETURN(status, _("sl_open_write")); 1996 2042 1997 status = sl_open_file( fname, SL_OPEN_FOR_WRITE, priv);2043 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_WRITE, priv); 1998 2044 SL_IRETURN(status, _("sl_open_write")); 1999 2045 } 2000 2046 2001 SL_TICKET sl_open_read (const char * fname, int priv) 2047 SL_TICKET sl_open_read (const char * ofile, int oline, 2048 const char * fname, int priv) 2002 2049 { 2003 2050 long status; … … 2012 2059 } 2013 2060 2014 status = sl_open_file( fname, SL_OPEN_FOR_READ, priv);2061 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_READ, priv); 2015 2062 SL_IRETURN(status, _("sl_open_read")); 2016 2063 } … … 2067 2114 } 2068 2115 2069 SL_TICKET sl_open_fastread (const char * fname, int priv) 2116 SL_TICKET sl_open_fastread (const char * ofile, int oline, 2117 const char * fname, int priv) 2070 2118 { 2071 2119 long status; … … 2075 2123 SL_IRETURN(status, _("sl_open_read")); 2076 2124 2077 status = sl_open_file( fname, SL_OPEN_FOR_FASTREAD, priv);2125 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_FASTREAD, priv); 2078 2126 2079 2127 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED) … … 2094 2142 } 2095 2143 2096 SL_TICKET sl_open_rdwr (const char * fname, int priv) 2144 SL_TICKET sl_open_rdwr (const char * ofile, int oline, 2145 const char * fname, int priv) 2097 2146 { 2098 2147 long status; … … 2102 2151 SL_IRETURN(status, _("sl_open_rdwr")); 2103 2152 2104 status = sl_open_file( fname, SL_OPEN_FOR_RDWR, priv);2153 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_RDWR, priv); 2105 2154 SL_IRETURN(status, _("sl_open_rdwr")); 2106 2155 } 2107 2156 2108 SL_TICKET sl_open_safe_rdwr (const char * fname, int priv) 2157 SL_TICKET sl_open_safe_rdwr (const char * ofile, int oline, 2158 const char * fname, int priv) 2109 2159 { 2110 2160 long status; … … 2114 2164 SL_IRETURN(status, _("sl_open_safe_rdwr")); 2115 2165 2116 status = sl_open_file( fname, SL_OPEN_SAFE_RDWR, priv);2166 status = sl_open_file(ofile, oline, fname, SL_OPEN_SAFE_RDWR, priv); 2117 2167 SL_IRETURN(status, _("sl_open_safe_rdwr")); 2118 2168 } 2119 2169 2120 SL_TICKET sl_open_write_trunc (const char * fname, int priv) 2170 SL_TICKET sl_open_write_trunc (const char * ofile, int oline, 2171 const char * fname, int priv) 2121 2172 { 2122 2173 long status; … … 2126 2177 SL_IRETURN(status, _("sl_open_write_trunc")); 2127 2178 2128 status = sl_open_file( fname, SL_OPEN_FOR_WTRUNC, priv);2179 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_WTRUNC, priv); 2129 2180 SL_IRETURN(status, _("sl_open_write_trunc")); 2130 2181 } 2131 2182 2132 SL_TICKET sl_open_rdwr_trunc (const char * fname, int priv) 2183 SL_TICKET sl_open_rdwr_trunc (const char * ofile, int oline, 2184 const char * fname, int priv) 2133 2185 { 2134 2186 long status; … … 2138 2190 SL_IRETURN(status, _("sl_open_rdwr_trunc")); 2139 2191 2140 status = sl_open_file( fname, SL_OPEN_FOR_RWTRUNC, priv);2192 status = sl_open_file(ofile, oline, fname, SL_OPEN_FOR_RWTRUNC, priv); 2141 2193 SL_IRETURN(status, _("sl_open_rdwr_trunc")); 2142 2194 } … … 2150 2202 return (fd); 2151 2203 2152 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 2204 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || 2205 ticket != ofiles[fd]->ticket || fd < 0) 2153 2206 return (SL_EINTERNAL12); 2154 2207 … … 2167 2220 return (NULL); 2168 2221 2169 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 2222 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || 2223 ticket != ofiles[fd]->ticket || fd < 0) 2170 2224 return (NULL); 2171 2225
Note:
See TracChangeset
for help on using the changeset viewer.