Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Oct 1998 15:11:17 -0800 (PST)
From:      edavis@hooked.net
To:        freebsd-gnats-submit@FreeBSD.ORG
Subject:   bin/8469: fchdir not implemented in libc_r
Message-ID:  <199810272311.PAA08659@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         8469
>Category:       bin
>Synopsis:       fchdir not implemented in libc_r
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 27 15:20:00 PST 1998
>Last-Modified:
>Originator:     Eric Davis
>Organization:
>Release:        FreeBSD 2.2.7
>Environment:
FreeBSD core.hooked.net 2.2.7-STABLE FreeBSD 2.2.7-STABLE #0: Tue Oct 27 12:04:10 PST 1998     edavis@core.hooked.net:/usr/src/sys/compile/CORE  i386
>Description:
fchdir() is broken for apps linked against libc_r
>How-To-Repeat:
One way:
  Try compiling an application that contains a call to fchdir() using
  the '-pthread' argument to force the use of libc_r:

#include <unistd.h>
#include <fcntl.h>
void main()
{
    int fd;
    fd = open("/etc", 0, 0);
    fchdir(fd);
}

core [133] [~] cc -pthread main.c
/var/tmp/ccB105761.o: Undefined symbol `_fchdir' referenced from text segment
/usr/lib/libc_r.so.3.0: Undefined symbol `_fchdir' referenced


Second way:
  Call the realpath() library function which in turn calls fchdir().
  This application will compile cleanly and cause a run time error:

#include <sys/param.h>
#include <stdlib.h>
void main()
{
    char path[MAXPATHLEN];
    realpath("/etc", path);
}

core [142] [~] cc -pthread main.c
core [143] [~] ./a.out
/usr/libexec/ld.so: Undefined symbol "_fchdir" called from a.out:/usr/lib/libc_r.so.3.0 at 0x200886a8



>Fix:
Apply the following patch to the libc_r source directory:


diff -rN /usr/src/lib/libc_r.orig/uthread/Makefile.inc /usr/src/lib/libc_r/uthre
ad/Makefile.inc
31a32
>       uthread_fchdir.c \
diff -rN /usr/src/lib/libc_r.orig/uthread/uthread_fchdir.c /usr/src/lib/libc_r/u
thread/uthread_fchdir.c
0a1,51
> /*
>  * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
>  * All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in the
>  *    documentation and/or other materials provided with the distribution.
>  * 3. All advertising materials mentioning features or use of this software
>  *    must display the following acknowledgement:
>  *    This product includes software developed by John Birrell.
>  * 4. Neither the name of the author nor the names of any co-contributors
>  *    may be used to endorse or promote products derived from this software
>  *    without specific prior written permission.
>  *
>  * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
>  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
>  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
>  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
>  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
>  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
>  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
>  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
>  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  *
>  */
> #include <sys/types.h>
> #include <unistd.h>
> #include <dirent.h>
> #ifdef _THREAD_SAFE
> #include <pthread.h>
> #include "pthread_private.h"
> 
> int
> fchdir(int fd)
> {
>       int             ret;
> 
>       if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0
) {
>               ret = _thread_sys_fchdir(fd);
>               _thread_fd_unlock(fd, FD_WRITE);
>       }
>       return (ret);
> }
> #endif

>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810272311.PAA08659>