Changeset 3870 for neercs


Ignore:
Timestamp:
Nov 2, 2009, 3:30:15 PM (11 years ago)
Author:
Pascal Terjan
Message:
  • Preserve errno when needed, and return -1 when it is set
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/mytrace.c

    r3869 r3870  
    194194    struct user_regs_struct regs;
    195195    size_t size = strlen(path) + 1;
    196     int ret;
     196    int ret, err;
    197197
    198198    if(ptrace(PTRACE_GETREGS, t->pid, NULL, &regs) < 0)
    199199    {
    200200        perror("PTRACE_GETREGS (open)\n");
    201         return errno;
     201        return -1;
    202202    }
    203203
     
    209209
    210210    ret = remote_syscall(t, MYCALL_OPEN, regs.RSP, O_RDWR, 0755);
     211    err = errno;
    211212
    212213    /* Restore the data */
    213214    memcpy_into_target(t, regs.RSP, backup_data, size);
    214215
     216    errno = err;
    215217    return ret;
    216218#else
     
    235237    struct user_regs_struct regs;
    236238    char *backup_data;
    237     int ret;
     239    int ret, err;
    238240
    239241    if(ptrace(PTRACE_GETREGS, t->pid, NULL, &regs) < 0)
    240242    {
    241243        perror("PTRACE_GETREGS (write)\n");
    242         return errno;
     244        return -1;
    243245    }
    244246
     
    252254
    253255    ret = remote_syscall(t, MYCALL_WRITE, fd, regs.RSP, len);
     256    err = errno;
    254257
    255258    /* Restore the data */
    256259    memcpy_into_target(t, regs.RSP, backup_data, len);
    257260
     261    errno = err;
    258262    return ret;
    259263#else
     
    331335    {
    332336        perror("PTRACE_GETREGS (exec)\n");
    333         return errno;
     337        return -1;
    334338    }
    335339
Note: See TracChangeset for help on using the changeset viewer.