writing a opened file - Unix

This is a discussion on writing a opened file - Unix ; hi all... I want to patch some of sections(ELF format) of my program itself. but first problem is I can't open the program in O_RDWD... for example, this program is called TEST, I execute this program by ./ TEST TEST ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: writing a opened file

  1. writing a opened file

    hi all...

    I want to patch some of sections(ELF format) of my program itself.
    but first problem is I can't open the program in O_RDWD...
    for example, this program is called TEST, I execute this program by ./
    TEST TEST
    but the program return fail...

    #include
    #include
    #include
    #include
    #include
    #include

    int
    main(int argc, char **argv)
    {
    int fd;

    if (elf_version(EV_CURRENT) == EV_NONE) (4)
    exit(-1);

    if ((fd = open(argv[1], O_RDWD, 0)) < 0)
    exit(-1);

    close(fd);
    }

    how could I overcome this?
    I'm under Ubuntu 7.10, using gcc 4.12
    thanx!

    Dave.

  2. Re: writing a opened file

    What's O_RDWD?

  3. Re: writing a opened file

    Dave wrote:

    # if ((fd = open(argv[1], O_RDWD, 0)) < 0)
    # exit(-1);

    What's the errno?

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    You face forward, or you face the possibility of shock and damage.

  4. Re: writing a opened file

    SM Ryan writes:
    >Dave wrote:
    >
    ># if ((fd = open(argv[1], O_RDWD, 0)) < 0)
    ># exit(-1);
    >
    >What's the errno?
    >


    And more importantly, what's the operating system? Some allow
    modification of open text files (SVR4), others will return ETXTBSY.

    scott

  5. Re: writing a opened file

    * Dave
    | if ((fd = open(argv[1], O_RDWD, 0)) < 0)
    | exit(-1);

    Try
    if ((fd = open(argv[1], O_RDWD, 0)) < 0) {
    perror("open() failure: ");
    exit(-1);
    }
    Instead.

    R'

  6. Re: writing a opened file

    On 2月5日, 下午1時56分, sc...@slp53.sl.home (Scott Lurndal) wrote:
    > SM Ryan writes:
    > >Dave wrote:

    >
    > ># if ((fd = open(argv[1], O_RDWD, 0)) < 0)
    > ># exit(-1);

    >
    > >What's the errno?

    >
    > And more importantly, what's the operating system? Some allow
    > modification of open text files (SVR4), others will return ETXTBSY.
    >
    > scott


    My operation system is Ubuntu 7.10 with kernel ver. 2.6.19
    ETXTBSY is what exactly what I got when I trying to reopen the file!!

    Dave.

+ Reply to Thread