Thread: bus error on using acl_get_fd , acl_set_fd

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    22

    bus error on using acl_get_fd , acl_set_fd

    Hi all,
    I am trying to write a program to copy a file and also its ACL's. However, though the program compiles I get a bus error after acl_set_fd
    Here is the program
    Code:
    #include<stdio.h>
    #include<sys/types.h>
    #include<errno.h>
    #include<fcntl.h>
    #include<sys/uio.h>
    #include<unistd.h>
    #include<sys/acl.h>
    
    #define BUFSIZE 8192
    
    int main(int argc,char *argv[])
    {
            int fs , fd , ret ;
            acl_t acl = 0 ;
            char buffer[BUFSIZE];
            size_t nbytes = BUFSIZE ;
            ssize_t count ;
            if(argc == 3)
            {
                    fs = open(argv[1],O_RDONLY) ;
                    if(fs == -1)
                    {
                            perror("cant open file for reading\n");
                            return 0 ;
                    }
                    fd = open(argv[2],O_RDWR | O_CREAT,0777);
                    if(fd == -1)
                    {
                            perror("cant open file for writing\n");
                            return 0;
                    }
                    acl = acl_get_fd(fs) ;
                    if(acl = (acl_t)NULL)
                            perror("failed to get ACLs\n") ;
                    while((count = read(fs , buffer , nbytes)))
                            write(fd , buffer , count) ;
                    printf("File copy complete\n");
                    printf("setting ACL's for file\n");
                    ret = acl_set_fd(fd , acl) ;
                    printf("Done!!!!!!");
                    if(ret == -1)
                    {
                            perror("Failed to set ACL\n");
                            return 0 ;
                    }
                    if(ret == 0)
                            printf("ACL set successfully\n");
                    close(fd);
                    close(fs);
            }
            else
                    printf("usage : ./acl_prg source dest\n");
            return 0;
    }
    I am running this on Mac OS X 10.4

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    22
    This is the output I get :

    # ./acl_prg 1.txt 2.txt
    File copy complete
    setting ACL's for file
    Bus error

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > if(acl = (acl_t)NULL)
    You made it NULL, not tested it for NULL.

    1. Casting NULL is unnecessary
    2. Add more compiler warnings (say -Wall) to catch the problem early.
    3. Use a debugger to trap the error, and allow you to examine the input parameters at the point of the fault.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    22
    Oh, I completely overlooked that.

    Thanks a lot for pointing out. Works fine now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SM Bus
    By yanol in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2008, 10:02 AM
  2. Bus Error (rand)
    By nacho4d in forum C Programming
    Replies: 4
    Last Post: 06-22-2007, 04:38 AM
  3. sem_init -> bus error
    By g_p in forum C Programming
    Replies: 4
    Last Post: 12-03-2006, 12:14 PM
  4. Initializing array of structures causing bus error
    By Aaron M in forum C Programming
    Replies: 5
    Last Post: 03-05-2006, 01:40 AM
  5. Replies: 72
    Last Post: 11-25-2002, 05:55 PM