Ignore:
Timestamp:
May 22, 2019, 4:09:18 PM (5 years ago)
Author:
coas-nagasima
Message:

ファイルディスクリプタ処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c

    r374 r387  
    5858#include "util/ntopt.h"
    5959#include "ntshell_main.h"
    60 #include "socket_stub.h"
     60#include "fdtable.h"
    6161
    6262char command[NTOPT_TEXT_MAXLEN];
     
    7878}
    7979
     80void stdio_open(ID portid);
    8081static int usrcmd_ntopt_callback(long *args, void *extobj);
    8182
     
    8687void ntshell_task_init(ID portid)
    8788{
    88         serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
     89        stdio_open(portid);
    8990}
    9091
     
    9596{
    9697        ntshell_state = 1;
    97         ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
     98
     99        if (setjmp(process_exit) == 0) {
     100                ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
     101        }
     102
     103        fflush(stdout);
     104        clean_fd();
     105
    98106        ntshell_state = 2;
    99107}
     
    139147                printf("Unknown command found.\n");
    140148
    141         clean_fd();
    142 
    143149        return result;
    144150}
     
    285291}
    286292
    287 struct sigaction sigtable[7];
    288 
    289 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
    290 {
    291         struct sigaction *sat;
     293// musl-1.1.18\src\internal\ksigaction.h
     294struct k_sigaction {
     295        void(*handler)(int);
     296        unsigned long flags;
     297        void(*restorer)(void);
     298        unsigned mask[2];
     299};
     300
     301struct k_sigaction sigtable[7];
     302
     303int shell_sigaction(int sig, const struct k_sigaction *__restrict sa,
     304        struct k_sigaction *__restrict old, size_t size)
     305{
     306        struct k_sigaction *sat;
    292307
    293308        switch(sig){
     
    318333
    319334        if (old != NULL)
    320                 memcpy(old, sat, sizeof(struct sigaction));
    321 
    322         memcpy(sat, sa, sizeof(struct sigaction));
     335                memcpy(old, sat, offsetof(struct k_sigaction, mask) + size);
     336
     337        memcpy(sat, sa, offsetof(struct k_sigaction, mask) + size);
    323338
    324339        return 0;
     
    368383}
    369384
     385int shell_nanosleep(const struct timespec *req, struct timespec *rem)
     386{
     387        ER ret;
     388        TMO tmo;
     389        SYSTIM prev, now, diff;
     390
     391        if ((req == NULL) || (req->tv_nsec < 0) || (req->tv_nsec >= 1000000000))
     392                return -EINVAL;
     393
     394        get_tim(&prev);
     395
     396        tmo = req->tv_sec * 1000000 + req->tv_nsec / 1000;
     397        ret = tslp_tsk(tmo);
     398        if (ret == E_OK) {
     399                if (rem != NULL) {
     400                        get_tim(&now);
     401                        diff = now - prev;
     402                        rem->tv_sec = diff / 1000000ll;
     403                        rem->tv_nsec = (diff - (rem->tv_sec * 1000000ll)) * 1000ll;
     404                }
     405                return 0;
     406        }
     407        else if (ret == E_TMOUT) {
     408                if (rem != NULL) {
     409                        rem->tv_sec = 0;
     410                        rem->tv_nsec = 0;
     411                }
     412                return 0;
     413        }
     414
     415        return -EFAULT;
     416}
Note: See TracChangeset for help on using the changeset viewer.