What's wrong with this really simple function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
 I have created this 5-liner system call, which basically opens a
file, write "Hello World" to it, and then returns. That's all.

Now, when I actually call it, it creates the file successfully but
writes nothing to it. The file is created and is only zero bytes. So,
either write didn't write, or close didn't close. Any help would be
greatly appreciated.

#define SUCCESS 0
#define CANT_OPEN_FILE 1
#define YOU_ARE_NOT_ROOT 3
#define OTHER_STUPID_ERROR 4

asmlinkage long sys_dump(char * filename)
{
    int fd;
    if(!capable(CAP_SYS_ADMIN))
        return YOU_ARE_NOT_ROOT;

    fd=sys_open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRWXU);
    if(fd==-1)
        return CANT_OPEN_FILE;

    if(sys_write(fd,"Hello World From inside the kernel!",35)==0)
    {
        sys_close(fd);
        return OTHER_STUPID_ERROR;
    }

    sys_close(fd);
    return SUCCESS;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux