Changeset 232 for branches/samba-3.2.x/source/lib
- Timestamp:
- May 27, 2009, 9:09:42 AM (16 years ago)
- Location:
- branches/samba-3.2.x/source/lib
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/lib/charcnv.c
r228 r232 548 548 } 549 549 if (srclen == 0) { 550 ob = ((ctx != NULL) ? talloc_strdup(ctx, "") : SMB_STRDUP("")); 551 if (ob == NULL) { 552 errno = ENOMEM; 553 return false; 554 } 555 *dest = ob; 550 556 *converted_size = 0; 551 557 return true; -
branches/samba-3.2.x/source/lib/dbwrap_util.c
r149 r232 79 79 } 80 80 81 booldbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)81 int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v) 82 82 { 83 83 struct db_record *rec; … … 87 87 rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr)); 88 88 if (rec == NULL) { 89 return false;89 return -1; 90 90 } 91 91 -
branches/samba-3.2.x/source/lib/events.c
r138 r232 64 64 DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, 65 65 te->event_name)); 66 DLIST_REMOVE(te->event_ctx->timed_events, te); 66 if (te->event_ctx) { 67 DLIST_REMOVE(te->event_ctx->timed_events, te); 68 } 67 69 return 0; 68 70 } … … 134 136 struct event_context *event_ctx = fde->event_ctx; 135 137 136 DLIST_REMOVE(event_ctx->fd_events, fde); 138 if (event_ctx) { 139 DLIST_REMOVE(event_ctx->fd_events, fde); 140 } 137 141 return 0; 138 142 } … … 242 246 int selrtn, fd_set *read_fds, fd_set *write_fds) 243 247 { 244 bool fired = False; 245 struct fd_event *fde, *next; 246 247 /* Run all events that are pending, not just one (as we 248 did previously. */ 249 250 while (event_ctx->timed_events) { 251 struct timeval now; 252 GetTimeOfDay(&now); 253 254 if (timeval_compare( 255 &now, &event_ctx->timed_events->when) < 0) { 256 /* Nothing to do yet */ 257 DEBUG(11, ("run_events: Nothing to do\n")); 258 break; 259 } 248 struct fd_event *fde; 249 struct timeval now; 250 251 GetTimeOfDay(&now); 252 253 if ((event_ctx->timed_events != NULL) 254 && (timeval_compare(&now, &event_ctx->timed_events->when) >= 0)) { 260 255 261 256 DEBUG(10, ("Running event \"%s\" %lx\n", … … 268 263 event_ctx->timed_events->private_data); 269 264 270 fired = True; 271 } 272 273 if (fired) { 274 /* 275 * We might have changed the socket status during the timed 276 * events, return to run select again. 277 */ 278 return True; 265 return true; 279 266 } 280 267 … … 283 270 * No fd ready 284 271 */ 285 return f ired;286 } 287 288 for (fde = event_ctx->fd_events; fde; fde = next) {272 return false; 273 } 274 275 for (fde = event_ctx->fd_events; fde; fde = fde->next) { 289 276 uint16 flags = 0; 290 277 291 next = fde->next;292 278 if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ; 293 279 if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE; … … 295 281 if (flags) { 296 282 fde->handler(event_ctx, fde, flags, fde->private_data); 297 fired = True;298 } 299 } 300 301 return f ired;283 return true; 284 } 285 } 286 287 return false; 302 288 } 303 289 … … 355 341 } 356 342 343 static int event_context_destructor(struct event_context *ev) 344 { 345 while (ev->fd_events != NULL) { 346 ev->fd_events->event_ctx = NULL; 347 DLIST_REMOVE(ev->fd_events, ev->fd_events); 348 } 349 while (ev->timed_events != NULL) { 350 ev->timed_events->event_ctx = NULL; 351 DLIST_REMOVE(ev->timed_events, ev->timed_events); 352 } 353 return 0; 354 } 355 356 void event_context_reinit(struct event_context *ev) 357 { 358 event_context_destructor(ev); 359 return; 360 } 361 357 362 struct event_context *event_context_init(TALLOC_CTX *mem_ctx) 358 363 { 359 return TALLOC_ZERO_P(NULL, struct event_context); 360 } 361 362 int set_event_dispatch_time(struct event_context *event_ctx, 363 const char *event_name, struct timeval when) 364 { 365 struct timed_event *te; 366 367 for (te = event_ctx->timed_events; te; te = te->next) { 368 if (strcmp(event_name, te->event_name) == 0) { 369 DLIST_REMOVE(event_ctx->timed_events, te); 370 te->when = when; 371 add_event_by_time(te); 372 return 1; 373 } 374 } 375 return 0; 376 } 377 378 /* Returns 1 if event was found and cancelled, 0 otherwise. */ 379 380 int cancel_named_event(struct event_context *event_ctx, 381 const char *event_name) 382 { 383 struct timed_event *te; 384 385 for (te = event_ctx->timed_events; te; te = te->next) { 386 if (strcmp(event_name, te->event_name) == 0) { 387 TALLOC_FREE(te); 388 return 1; 389 } 390 } 391 return 0; 364 struct event_context *result; 365 366 result = TALLOC_ZERO_P(mem_ctx, struct event_context); 367 if (result == NULL) { 368 return NULL; 369 } 370 371 talloc_set_destructor(result, event_context_destructor); 372 return result; 392 373 } 393 374 -
branches/samba-3.2.x/source/lib/ldb/include/ldb.h
r133 r232 992 992 enum ldb_scope scope, 993 993 const char *expression, 994 const char * const *attrs, struct ldb_result ** res);994 const char * const *attrs, struct ldb_result **_res); 995 995 996 996 /* -
branches/samba-3.2.x/source/lib/replace/replace.h
r136 r232 329 329 #define pread rep_pread 330 330 ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset); 331 #define LIBREPLACE_PREAD_REPLACED 1 332 #else 333 #define LIBREPLACE_PREAD_NOT_REPLACED 1 331 334 #endif 332 335 … … 334 337 #define pwrite rep_pwrite 335 338 ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset); 339 #define LIBREPLACE_PWRITE_REPLACED 1 340 #else 341 #define LIBREPLACE_PWRITE_NOT_REPLACED 1 336 342 #endif 337 343 -
branches/samba-3.2.x/source/lib/sendfile.c
r133 r232 66 66 } while (nwritten == -1 && errno == EINTR); 67 67 if (nwritten == -1) { 68 if (errno == ENOSYS ) {68 if (errno == ENOSYS || errno == EINVAL) { 69 69 /* Ok - we're in a world of pain here. We just sent 70 70 * the header, but the sendfile failed. We have to … … 144 144 } while (nwritten == -1 && errno == EINTR); 145 145 if (nwritten == -1) { 146 if (errno == ENOSYS ) {146 if (errno == ENOSYS || errno == EINVAL) { 147 147 /* Ok - we're in a world of pain here. We just sent 148 148 * the header, but the sendfile failed. We have to -
branches/samba-3.2.x/source/lib/system.c
r137 r232 149 149 } while (ret == -1 && ((errno == EINTR)||(errno == EAGAIN))); 150 150 #endif 151 return ret; 152 } 153 154 /******************************************************************* 155 A writev wrapper that will deal with EINTR. 156 ********************************************************************/ 157 158 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt) 159 { 160 ssize_t ret; 161 162 #if 0 163 /* Try to confuse write_data_iov a bit */ 164 if ((random() % 5) == 0) { 165 return sys_write(fd, iov[0].iov_base, iov[0].iov_len); 166 } 167 if (iov[0].iov_len > 1) { 168 return sys_write(fd, iov[0].iov_base, 169 (random() % (iov[0].iov_len-1)) + 1); 170 } 171 #endif 172 173 do { 174 ret = writev(fd, iov, iovcnt); 175 } while (ret == -1 && errno == EINTR); 151 176 return ret; 152 177 } -
branches/samba-3.2.x/source/lib/time.c
r204 r232 904 904 ret.tv_nsec = pst->st_atimensec; 905 905 return ret; 906 #elif defined(HAVE_STAT_ST_ATIME_N) 907 struct timespec ret; 908 ret.tv_sec = pst->st_atime; 909 ret.tv_nsec = pst->st_atime_n; 910 return ret; 911 #elif defined(HAVE_STAT_ST_UATIME) 912 struct timespec ret; 913 ret.tv_sec = pst->st_atime; 914 ret.tv_nsec = pst->st_uatime * 1000; 915 return ret; 916 #elif defined(HAVE_STAT_ST_ATIMESPEC) 917 return pst->st_atimespec; 906 918 #else 907 919 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT … … 920 932 #elif defined(HAVE_STAT_ST_ATIMENSEC) 921 933 pst->st_atime = ts.tv_sec; 922 pst->st_atimensec = ts.tv_nsec 934 pst->st_atimensec = ts.tv_nsec; 935 #elif defined(HAVE_STAT_ST_ATIME_N) 936 pst->st_atime = ts.tv_sec; 937 pst->st_atime_n = ts.tv_nsec; 938 #elif defined(HAVE_STAT_ST_UATIME) 939 pst->st_atime = ts.tv_sec; 940 pst->st_uatime = ts.tv_nsec / 1000; 941 #elif defined(HAVE_STAT_ST_ATIMESPEC) 942 pst->st_atimespec = ts; 923 943 #else 924 944 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT … … 944 964 ret.tv_nsec = pst->st_mtimensec; 945 965 return ret; 966 #elif defined(HAVE_STAT_ST_MTIME_N) 967 struct timespec ret; 968 ret.tv_sec = pst->st_mtime; 969 ret.tv_nsec = pst->st_mtime_n; 970 return ret; 971 #elif defined(HAVE_STAT_ST_UMTIME) 972 struct timespec ret; 973 ret.tv_sec = pst->st_mtime; 974 ret.tv_nsec = pst->st_umtime * 1000; 975 return ret; 976 #elif defined(HAVE_STAT_ST_MTIMESPEC) 977 return pst->st_mtimespec; 946 978 #else 947 979 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT … … 960 992 #elif defined(HAVE_STAT_ST_MTIMENSEC) 961 993 pst->st_mtime = ts.tv_sec; 962 pst->st_mtimensec = ts.tv_nsec 994 pst->st_mtimensec = ts.tv_nsec; 995 #elif defined(HAVE_STAT_ST_MTIME_N) 996 pst->st_mtime = ts.tv_sec; 997 pst->st_mtime_n = ts.tv_nsec; 998 #elif defined(HAVE_STAT_ST_UMTIME) 999 pst->st_mtime = ts.tv_sec; 1000 pst->st_umtime = ts.tv_nsec / 1000; 1001 #elif defined(HAVE_STAT_ST_MTIMESPEC) 1002 pst->st_mtimespec = ts; 963 1003 #else 964 1004 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT … … 984 1024 ret.tv_nsec = pst->st_ctimensec; 985 1025 return ret; 1026 #elif defined(HAVE_STAT_ST_CTIME_N) 1027 struct timespec ret; 1028 ret.tv_sec = pst->st_ctime; 1029 ret.tv_nsec = pst->st_ctime_n; 1030 return ret; 1031 #elif defined(HAVE_STAT_ST_UCTIME) 1032 struct timespec ret; 1033 ret.tv_sec = pst->st_ctime; 1034 ret.tv_nsec = pst->st_uctime * 1000; 1035 return ret; 1036 #elif defined(HAVE_STAT_ST_CTIMESPEC) 1037 return pst->st_ctimespec; 986 1038 #else 987 1039 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT … … 1000 1052 #elif defined(HAVE_STAT_ST_CTIMENSEC) 1001 1053 pst->st_ctime = ts.tv_sec; 1002 pst->st_ctimensec = ts.tv_nsec 1054 pst->st_ctimensec = ts.tv_nsec; 1055 #elif defined(HAVE_STAT_ST_CTIME_N) 1056 pst->st_ctime = ts.tv_sec; 1057 pst->st_ctime_n = ts.tv_nsec; 1058 #elif defined(HAVE_STAT_ST_UCTIME) 1059 pst->st_ctime = ts.tv_sec; 1060 pst->st_uctime = ts.tv_nsec / 1000; 1061 #elif defined(HAVE_STAT_ST_CTIMESPEC) 1062 pst->st_ctimespec = ts; 1003 1063 #else 1004 1064 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -
branches/samba-3.2.x/source/lib/util.c
r149 r232 1041 1041 1042 1042 bool reinit_after_fork(struct messaging_context *msg_ctx, 1043 struct event_context *ev_ctx, 1043 1044 bool parent_longlived) 1044 1045 { … … 1057 1058 } 1058 1059 1059 /* 1060 * For clustering, we need to re-init our ctdbd connection after the 1061 * fork 1062 */ 1063 status = messaging_reinit(msg_ctx); 1064 if (!NT_STATUS_IS_OK(status)) { 1065 DEBUG(0,("messaging_reinit() failed: %s\n", 1066 nt_errstr(status))); 1067 return false; 1060 if (msg_ctx) { 1061 /* 1062 * For clustering, we need to re-init our ctdbd connection after the 1063 * fork 1064 */ 1065 status = messaging_reinit(msg_ctx); 1066 if (!NT_STATUS_IS_OK(status)) { 1067 DEBUG(0,("messaging_reinit() failed: %s\n", 1068 nt_errstr(status))); 1069 return false; 1070 } 1071 } 1072 1073 if (ev_ctx) { 1074 event_context_reinit(ev_ctx); 1068 1075 } 1069 1076 -
branches/samba-3.2.x/source/lib/util_sock.c
r228 r232 1038 1038 1039 1039 /**************************************************************************** 1040 Write all data from an iov array 1041 ****************************************************************************/ 1042 1043 ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt) 1044 { 1045 int i; 1046 size_t to_send; 1047 ssize_t thistime; 1048 size_t sent; 1049 struct iovec *iov_copy, *iov; 1050 1051 to_send = 0; 1052 for (i=0; i<iovcnt; i++) { 1053 to_send += orig_iov[i].iov_len; 1054 } 1055 1056 thistime = sys_writev(fd, orig_iov, iovcnt); 1057 if ((thistime <= 0) || (thistime == to_send)) { 1058 return thistime; 1059 } 1060 sent = thistime; 1061 1062 /* 1063 * We could not send everything in one call. Make a copy of iov that 1064 * we can mess with. We keep a copy of the array start in iov_copy for 1065 * the TALLOC_FREE, because we're going to modify iov later on, 1066 * discarding elements. 1067 */ 1068 1069 iov_copy = (struct iovec *)TALLOC_MEMDUP( 1070 talloc_tos(), orig_iov, sizeof(struct iovec) * iovcnt); 1071 1072 if (iov_copy == NULL) { 1073 errno = ENOMEM; 1074 return -1; 1075 } 1076 iov = iov_copy; 1077 1078 while (sent < to_send) { 1079 /* 1080 * We have to discard "thistime" bytes from the beginning 1081 * iov array, "thistime" contains the number of bytes sent 1082 * via writev last. 1083 */ 1084 while (thistime > 0) { 1085 if (thistime < iov[0].iov_len) { 1086 char *new_base = 1087 (char *)iov[0].iov_base + thistime; 1088 iov[0].iov_base = new_base; 1089 iov[0].iov_len -= thistime; 1090 break; 1091 } 1092 thistime -= iov[0].iov_len; 1093 iov += 1; 1094 iovcnt -= 1; 1095 } 1096 1097 thistime = sys_writev(fd, iov, iovcnt); 1098 if (thistime <= 0) { 1099 break; 1100 } 1101 sent += thistime; 1102 } 1103 1104 TALLOC_FREE(iov_copy); 1105 return sent; 1106 } 1107 1108 /**************************************************************************** 1040 1109 Write data to a fd. 1041 1110 ****************************************************************************/ 1042 1111 1112 /**************************************************************************** 1113 Write data to a fd. 1114 ****************************************************************************/ 1115 1043 1116 ssize_t write_data(int fd, const char *buffer, size_t N) 1044 1117 { 1045 size_t total=0;1046 1118 ssize_t ret; 1047 char addr[INET6_ADDRSTRLEN]; 1048 1049 while (total < N) { 1050 ret = sys_write(fd,buffer + total,N - total); 1051 1052 if (ret == -1) { 1053 if (fd == get_client_fd()) { 1054 /* Try and give an error message saying 1055 * what client failed. */ 1056 DEBUG(0,("write_data: write failure in " 1057 "writing to client %s. Error %s\n", 1058 get_peer_addr(fd,addr,sizeof(addr)), 1059 strerror(errno) )); 1060 } else { 1061 DEBUG(0,("write_data: write failure. " 1062 "Error = %s\n", strerror(errno) )); 1063 } 1064 return -1; 1065 } 1066 1067 if (ret == 0) { 1068 return total; 1069 } 1070 1071 total += ret; 1072 } 1073 return (ssize_t)total; 1119 struct iovec iov; 1120 1121 iov.iov_base = CONST_DISCARD(char *, buffer); 1122 iov.iov_len = N; 1123 1124 ret = write_data_iov(fd, &iov, 1); 1125 if (ret >= 0) { 1126 return ret; 1127 } 1128 1129 if (fd == get_client_fd()) { 1130 char addr[INET6_ADDRSTRLEN]; 1131 /* 1132 * Try and give an error message saying what client failed. 1133 */ 1134 DEBUG(0, ("write_data: write failure in writing to client %s. " 1135 "Error %s\n", get_peer_addr(fd,addr,sizeof(addr)), 1136 strerror(errno))); 1137 } else { 1138 DEBUG(0,("write_data: write failure. Error = %s\n", 1139 strerror(errno) )); 1140 } 1141 1142 return -1; 1074 1143 } 1075 1144 … … 2017 2086 { 2018 2087 TALLOC_CTX *ctx = talloc_tos(); 2088 char addr[INET6_ADDRSTRLEN]; 2019 2089 char *name = NULL; 2020 2090 const char *dnsname; … … 2068 2138 /* Use DNS to resolve the name, but only the first address */ 2069 2139 struct sockaddr_storage ss; 2070 if (interpret_string_addr(&ss, servername, 0)) {2071 print_sockaddr( name,2072 sizeof( name),2140 if (interpret_string_addr(&ss, servername, 0)) { 2141 print_sockaddr(addr, 2142 sizeof(addr), 2073 2143 &ss); 2074 servername = name;2144 servername = addr; 2075 2145 } 2076 2146 } -
branches/samba-3.2.x/source/lib/util_tdb.c
r133 r232 87 87 tdb_setalarm_sigptr(tdb, NULL); 88 88 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); 89 if (gotalarm ) {89 if (gotalarm && (ret == -1)) { 90 90 DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n", 91 91 timeout, key.dptr, tdb_name(tdb))); -
branches/samba-3.2.x/source/lib/xfile.c
r136 r232 355 355 size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f) 356 356 { 357 size_t remaining = size * nmemb; 357 358 size_t total = 0; 358 while (total < size*nmemb) { 359 int c = x_fgetc(f); 360 if (c == EOF) break; 361 (total+(char *)p)[0] = (char)c; 362 total++; 359 360 while (remaining > 0) { 361 size_t thistime; 362 363 x_fillbuf(f); 364 365 if (f->bufused == 0) { 366 f->flags |= X_FLAG_EOF; 367 break; 368 } 369 370 thistime = MIN(f->bufused, remaining); 371 372 memcpy((char *)p+total, f->next, thistime); 373 374 f->next += thistime; 375 f->bufused -= thistime; 376 remaining -= thistime; 377 total += thistime; 363 378 } 364 379 return total/size;
Note:
See TracChangeset
for help on using the changeset viewer.