~ubuntu-branches/ubuntu/hardy/lighttpd/hardy

« back to all changes in this revision

Viewing changes to src/stat_cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremie Corbier
  • Date: 2006-09-22 19:16:08 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060922191608-i9jngvf1wtf3j5rd
Tags: 1.4.12~20060907-1ubuntu1
Merge from debian unstable:
-> Keep the additional dependency on libterm-readline-perl-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#define lstat stat
40
40
#endif
41
41
 
42
 
#if 0
 
42
#if 1
43
43
/* enables debug code for testing if all nodes in the stat-cache as accessable */
44
44
#define DEBUG_STAT_CACHE
45
45
#endif
328
328
}
329
329
#endif
330
330
 
 
331
#ifdef HAVE_LSTAT
 
332
static int stat_cache_lstat(server *srv, char *dname, struct stat *lst) {
 
333
        if (lstat(dname, lst) == 0) {
 
334
                return S_ISLNK(lst->st_mode) ? 0 : 1;
 
335
        }
 
336
        else {
 
337
                log_error_write(srv, __FILE__, __LINE__, "sss",
 
338
                                "lstat failed for:",
 
339
                                dname, strerror(errno));
 
340
        };
 
341
        return -1;
 
342
}
 
343
#endif
 
344
 
331
345
/***
332
346
 *
333
347
 *
450
464
        /*
451
465
         * *lol* 
452
466
         * - open() + fstat() on a named-pipe results in a (intended) hang.
453
 
         * - stat() if regualar file + open() to see if we can read from it is better
 
467
         * - stat() if regular file + open() to see if we can read from it is better
454
468
         *
455
469
         * */
456
 
 
457
470
        if (-1 == stat(name->ptr, &st)) {
458
471
                return HANDLER_ERROR;
459
472
        }
509
522
         * and keeping the file open for the rest of the time. But this can
510
523
         * only be done at network level.
511
524
         * 
 
525
+        * per default it is not a symlink
512
526
         * */
513
 
        if (S_ISLNK(st.st_mode) && !con->conf.follow_symlink) {
514
 
                return HANDLER_ERROR;
 
527
#ifdef HAVE_LSTAT
 
528
        sce->is_symlink = 0;
 
529
        struct stat lst;
 
530
        if (stat_cache_lstat(srv, name->ptr, &lst)  == 0) {
 
531
#ifdef DEBUG_STAT_CACHE
 
532
                        log_error_write(srv, __FILE__, __LINE__, "sb",
 
533
                                        "found symlink", name);
 
534
#endif
 
535
                        sce->is_symlink = 1;
515
536
        }
516
537
 
 
538
        /*
 
539
         * we assume "/" can not be symlink, so
 
540
         * skip the symlink stuff if our path is /
 
541
         **/
 
542
        else if ((name->used > 2)) {
 
543
                char *dname, *s_cur;
 
544
 
 
545
                dname = strndup(name->ptr, name->used);
 
546
                while ((s_cur = strrchr(dname,'/'))) {
 
547
                        *s_cur = '\0';
 
548
                        if (dname == s_cur) {
 
549
#ifdef DEBUG_STAT_CACHE
 
550
                                log_error_write(srv, __FILE__, __LINE__, "s", "reached /");
 
551
#endif
 
552
                                break;
 
553
                        }
 
554
#ifdef DEBUG_STAT_CACHE
 
555
                        log_error_write(srv, __FILE__, __LINE__, "sss",
 
556
                                        "checking if", dname, "is a symlink");
 
557
#endif
 
558
                        if (stat_cache_lstat(srv, dname, &lst)  == 0) {
 
559
                                sce->is_symlink = 1;
 
560
#ifdef DEBUG_STAT_CACHE
 
561
                                log_error_write(srv, __FILE__, __LINE__, "ss",
 
562
                                                "found symlink", dname);
 
563
#endif
 
564
                                break;
 
565
                        };
 
566
                };
 
567
                free(dname);
 
568
        };
 
569
#endif
 
570
 
517
571
        if (S_ISREG(st.st_mode)) {      
518
572
                /* determine mimetype */
519
573
                buffer_reset(sce->content_type);