Ignore:
Timestamp:
May 27, 2009, 9:09:42 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.8

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  
    548548        }
    549549        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;
    550556                *converted_size = 0;
    551557                return true;
  • branches/samba-3.2.x/source/lib/dbwrap_util.c

    r149 r232  
    7979}
    8080
    81 bool dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
     81int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
    8282{
    8383        struct db_record *rec;
     
    8787        rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr));
    8888        if (rec == NULL) {
    89                 return false;
     89                return -1;
    9090        }
    9191
  • branches/samba-3.2.x/source/lib/events.c

    r138 r232  
    6464        DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te,
    6565                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        }
    6769        return 0;
    6870}
     
    134136        struct event_context *event_ctx = fde->event_ctx;
    135137
    136         DLIST_REMOVE(event_ctx->fd_events, fde);
     138        if (event_ctx) {
     139                DLIST_REMOVE(event_ctx->fd_events, fde);
     140        }
    137141        return 0;
    138142}
     
    242246                int selrtn, fd_set *read_fds, fd_set *write_fds)
    243247{
    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)) {
    260255
    261256                DEBUG(10, ("Running event \"%s\" %lx\n",
     
    268263                        event_ctx->timed_events->private_data);
    269264
    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;
    279266        }
    280267
     
    283270                 * No fd ready
    284271                 */
    285                 return fired;
    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) {
    289276                uint16 flags = 0;
    290277
    291                 next = fde->next;
    292278                if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ;
    293279                if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE;
     
    295281                if (flags) {
    296282                        fde->handler(event_ctx, fde, flags, fde->private_data);
    297                         fired = True;
    298                 }
    299         }
    300 
    301         return fired;
     283                        return true;
     284                }
     285        }
     286
     287        return false;
    302288}
    303289
     
    355341}
    356342
     343static 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
     356void event_context_reinit(struct event_context *ev)
     357{
     358        event_context_destructor(ev);
     359        return;
     360}
     361
    357362struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
    358363{
    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;
    392373}
    393374
  • branches/samba-3.2.x/source/lib/ldb/include/ldb.h

    r133 r232  
    992992               enum ldb_scope scope,
    993993               const char *expression,
    994                const char * const *attrs, struct ldb_result **res);
     994               const char * const *attrs, struct ldb_result **_res);
    995995
    996996/*
  • branches/samba-3.2.x/source/lib/replace/replace.h

    r136 r232  
    329329#define pread rep_pread
    330330ssize_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
    331334#endif
    332335
     
    334337#define pwrite rep_pwrite
    335338ssize_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
    336342#endif
    337343
  • branches/samba-3.2.x/source/lib/sendfile.c

    r133 r232  
    6666                } while (nwritten == -1 && errno == EINTR);
    6767                if (nwritten == -1) {
    68                         if (errno == ENOSYS) {
     68                        if (errno == ENOSYS || errno == EINVAL) {
    6969                                /* Ok - we're in a world of pain here. We just sent
    7070                                 * the header, but the sendfile failed. We have to
     
    144144                } while (nwritten == -1 && errno == EINTR);
    145145                if (nwritten == -1) {
    146                         if (errno == ENOSYS) {
     146                        if (errno == ENOSYS || errno == EINVAL) {
    147147                                /* Ok - we're in a world of pain here. We just sent
    148148                                 * the header, but the sendfile failed. We have to
  • branches/samba-3.2.x/source/lib/system.c

    r137 r232  
    149149        } while (ret == -1 && ((errno == EINTR)||(errno == EAGAIN)));
    150150#endif
     151        return ret;
     152}
     153
     154/*******************************************************************
     155A writev wrapper that will deal with EINTR.
     156********************************************************************/
     157
     158ssize_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);
    151176        return ret;
    152177}
  • branches/samba-3.2.x/source/lib/time.c

    r204 r232  
    904904        ret.tv_nsec = pst->st_atimensec;
    905905        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;
    906918#else
    907919#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
     
    920932#elif defined(HAVE_STAT_ST_ATIMENSEC)
    921933        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;
    923943#else
    924944#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
     
    944964        ret.tv_nsec = pst->st_mtimensec;
    945965        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;
    946978#else
    947979#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
     
    960992#elif defined(HAVE_STAT_ST_MTIMENSEC)
    961993        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;
    9631003#else
    9641004#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
     
    9841024        ret.tv_nsec = pst->st_ctimensec;
    9851025        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;
    9861038#else
    9871039#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
     
    10001052#elif defined(HAVE_STAT_ST_CTIMENSEC)
    10011053        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;
    10031063#else
    10041064#error  CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
  • branches/samba-3.2.x/source/lib/util.c

    r149 r232  
    10411041
    10421042bool reinit_after_fork(struct messaging_context *msg_ctx,
     1043                       struct event_context *ev_ctx,
    10431044                       bool parent_longlived)
    10441045{
     
    10571058        }
    10581059
    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);
    10681075        }
    10691076
  • branches/samba-3.2.x/source/lib/util_sock.c

    r228 r232  
    10381038
    10391039/****************************************************************************
     1040 Write all data from an iov array
     1041****************************************************************************/
     1042
     1043ssize_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/****************************************************************************
    10401109 Write data to a fd.
    10411110****************************************************************************/
    10421111
     1112/****************************************************************************
     1113 Write data to a fd.
     1114****************************************************************************/
     1115
    10431116ssize_t write_data(int fd, const char *buffer, size_t N)
    10441117{
    1045         size_t total=0;
    10461118        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;
    10741143}
    10751144
     
    20172086{
    20182087        TALLOC_CTX *ctx = talloc_tos();
     2088        char addr[INET6_ADDRSTRLEN];
    20192089        char *name = NULL;
    20202090        const char *dnsname;
     
    20682138                /* Use DNS to resolve the name, but only the first address */
    20692139                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),
    20732143                                        &ss);
    2074                         servername = name;
     2144                        servername = addr;
    20752145                }
    20762146        }
  • branches/samba-3.2.x/source/lib/util_tdb.c

    r133 r232  
    8787                tdb_setalarm_sigptr(tdb, NULL);
    8888                CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
    89                 if (gotalarm) {
     89                if (gotalarm && (ret == -1)) {
    9090                        DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
    9191                                timeout, key.dptr, tdb_name(tdb)));
  • branches/samba-3.2.x/source/lib/xfile.c

    r136 r232  
    355355size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f)
    356356{
     357        size_t remaining = size * nmemb;
    357358        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;
    363378        }
    364379        return total/size;
Note: See TracChangeset for help on using the changeset viewer.