bus error on using acl_get_fd , acl_set_fd

This is a discussion on bus error on using acl_get_fd , acl_set_fd within the C Programming forums, part of the General Programming Boards category; Hi all, I am trying to write a program to copy a file and also its ACL's. However, though the ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 11:14 AM
  4. Initializing array of structures causing bus error
    By Aaron M in forum C Programming
    Replies: 5
    Last Post: 03-05-2006, 12:40 AM
  5. Replies: 72
    Last Post: 11-25-2002, 04:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21