Changeset 409 for trunk/user/ksh


Ignore:
Timestamp:
Dec 20, 2017, 4:51:09 PM (6 years ago)
Author:
alain
Message:

Fix bugs in exec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/ksh.c

    r408 r409  
    6161        if (argc != 2)
    6262    {
    63                 printf("usage: cat pathname\n");
     63                printf("  usage: cat pathname\n");
    6464                return;
    6565        }
     
    6767        path = argv[1];
    6868
    69     printf("error: not implemented yet\n");
     69    printf("  error: not implemented yet\n");
    7070
    7171/*
     
    7474        if (fd < 0)
    7575    {
    76                 printf("error: cannot open %s\n", path);
     76                printf("  error: cannot open %s\n", path);
    7777                goto exit;
    7878        }
     
    8181        if (stat(path, &st) == -1)
    8282    {
    83                 printf("error: cannot stat %s\n", path);
     83                printf("  error: cannot stat %s\n", path);
    8484                goto exit;
    8585        }
    8686        if (S_ISDIR(st.st_mode)) {
    87                 printf("error: %s is a directory\n", path);
     87                printf("  error: %s is a directory\n", path);
    8888                goto exit;
    8989        }
     
    9393        buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
    9494        if (buf == NULL || buf == (char *)-1) {
    95                 printf("error: cannot map %s\n", path);
     95                printf("  error: cannot map %s\n", path);
    9696                goto exit;
    9797        }
     
    117117        if (argc != 2)
    118118    {
    119                 printf("usage: cd pathname\n");
     119                printf("  usage: cd pathname\n");
    120120                return;
    121121        }
     
    123123        path = argv[1];
    124124
    125     printf("error: not implemented yet\n");
     125    printf("  error: not implemented yet\n");
    126126/*
    127127        path = argv[1];
     
    129129        if (chdir(path) == -1)
    130130    {
    131                 printf("error: cannot cd to %s\n", path);
     131                printf("  error: cannot cd to %s\n", path);
    132132        }
    133133*/
     
    146146        if (argc != 3)
    147147    {
    148                 printf("usage: cp src_pathname dst_pathname\n");
    149                 return;
    150         }
    151 
    152     printf("error: not implemented yet\n");
     148                printf("  usage: cp src_pathname dst_pathname\n");
     149                return;
     150        }
     151
     152    printf("  error: not implemented yet\n");
    153153
    154154/*
     
    159159        src_fd = open(srcpath, O_RDONLY, 0);
    160160        if (src_fd < 0) {
    161                 printf("error: cannot open %s / err = %d\n", srcpath, errno);
     161                printf("  error: cannot open %s / err = %d\n", srcpath, errno);
    162162                goto exit;
    163163        }
     
    165165        // get file size
    166166        if (stat(srcpath, &st) == -1) {
    167                 printf("error: cannot stat %s\n", srcpath);
     167                printf("  error: cannot stat %s\n", srcpath);
    168168                goto exit;
    169169        }
    170170        if (S_ISDIR(st.st_mode)) {
    171                 printf("error: %s is a directory\n", srcpath);
     171                printf("  error: %s is a directory\n", srcpath);
    172172                goto exit;
    173173        }
     
    177177        dst_fd = open(dstpath, O_CREAT|O_TRUNC|O_RDWR, 0);
    178178        if (dst_fd < 0) {
    179                 printf("error: cannot open %s / err = %d\n", dstpath, errno);
     179                printf("  error: cannot open %s / err = %d\n", dstpath, errno);
    180180                goto exit;
    181181        }
    182182        if (stat(dstpath, &st) == -1) {
    183                 printf("error: cannot stat %s\n", dstpath);
     183                printf("  error: cannot stat %s\n", dstpath);
    184184                goto exit;
    185185        }
    186186        if (S_ISDIR(st.st_mode)) {
    187                 printf("error: %s is a directory\n", dstpath);
     187                printf("  error: %s is a directory\n", dstpath);
    188188                goto exit;
    189189        }
     
    199199                ret = read(src_fd, buf, rlen);
    200200                if (ret == -1) {
    201                         printf("error: cannot read from file %s\n", srcpath);
     201                        printf("  error: cannot read from file %s\n", srcpath);
    202202                        goto exit;
    203203                }
     
    207207                ret = write(dst_fd, buf, rlen);
    208208                if (ret == -1) {
    209                         printf("error: cannot write to file %s\n", dstpath);
     209                        printf("  error: cannot write to file %s\n", dstpath);
    210210                        goto exit;
    211211                }
     
    214214                // check
    215215                if (wlen != rlen) {
    216                         printf("error: cannot write on device\n");
     216                        printf("  error: cannot write on device\n");
    217217                        goto exit;
    218218                }
     
    235235        if (argc != 1)
    236236    {
    237                 printf("usage: %s\n", argv[0]);
     237                printf("  usage: %s\n", argv[0]);
    238238                return;
    239239        }
     
    253253        if (argc != 2)
    254254    {
    255                 printf("usage: %s pid\n", argv[0]);
     255                printf("  usage: %s pid\n", argv[0]);
    256256                return;
    257257        }
     
    261261        if( kill( pid , 9 ) )   // TODO replace 9 by SIGKILL
    262262    {
    263                 printf("error: unable to kill process %x\n", pid );
     263                printf("  error: unable to kill process %x\n", pid );
    264264        }
    265265}   // end cmd_kill()
     
    274274        if (argc != 2)
    275275    {
    276                 printf("usage: %s pathname \n", argv[0] );
     276                printf("  usage: %s pathname \n", argv[0] );
    277277                return;
    278278        }
     
    285285    if (pid == 0)  // it is the child process
    286286    {
    287         printf("CHILD\n");
    288         exit(0);
    289 
    290287        // exec system call
    291         // error = exec( pathname , NULL , NULL );
    292 
    293         // if( error )
    294         // {
    295         //    printf("error: new process unable to exec <%s>\n", pathname );
    296         //    exit();
    297         // }
     288        error = exec( pathname , NULL , NULL );
     289
     290        if( error )
     291        {
     292            printf("  error: new process unable to exec <%s>\n", pathname );
     293            exit(0);
     294        }
    298295        }
    299296    else if ( pid < 0 )  // it is a failure reported to parent
    300297    {
    301         printf("error: unable to fork\n");
     298        printf("  error: unable to fork\n");
    302299    }
    303     else                 // it is a success reported to parent
    304     {
    305         printf("PARENT\n");
    306         exit(0);
    307     }
    308 
    309300}   // end cmd_load
    310301
     
    339330    else
    340331    {
    341                 printf("usage: ls [path]\n");
    342                 return;
    343         }
    344 
    345     printf("error: not implemented yet\n");
     332                printf("  usage: ls [path]\n");
     333                return;
     334        }
     335
     336    printf("  error: not implemented yet\n");
    346337/*
    347338        dir = opendir( path );
     
    361352        if (argc != 2)
    362353    {
    363                 printf("usage: mkdir pathname\n");
     354                printf("  usage: mkdir pathname\n");
    364355                return;
    365356        }
     
    367358    pathname = argv[1];
    368359
    369     printf("error: not implemented yet\n");
     360    printf("  error: not implemented yet\n");
    370361/*
    371362        if ( mkdir( path, 0x700) == -1 )
    372363    {
    373                 printf("error: cannot create directory %s\n", path);
     364                printf("  error: cannot create directory %s\n", path);
    374365        }
    375366*/
     
    386377        }
    387378
    388     printf("error: not implemented yet\n");
     379    printf("  error: not implemented yet\n");
    389380   
    390381/*
     
    392383        if (ret < 0)
    393384        {
    394                 printf("error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret );
     385                printf("  error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret );
    395386        }
    396387*/
     
    405396        if (argc != 1)
    406397    {
    407                 printf("usage: pwd\n");
     398                printf("  usage: pwd\n");
    408399                return;
    409400        }
     
    411402        if ( getcwd( buf , 1024 ) )
    412403    {
    413                 printf("error: unable to get current directory\n");
     404                printf("  error: unable to get current directory\n");
    414405        }
    415406    else
     
    426417        if (argc != 2)
    427418    {
    428                 printf("usage: rm pathname\n");
     419                printf("  usage: rm pathname\n");
    429420                return;
    430421        }
     
    432423        pathname = argv[1];
    433424
    434     printf("error: not implemented yet\n");
     425    printf("  error: not implemented yet\n");
    435426/*
    436427        if (remove(path) == -1)
    437428    {
    438                 printf("error: cannot remove %s\n", path);
     429                printf("  error: cannot remove %s\n", path);
    439430        }
    440431*/
     
    456447        if (argc != 3)
    457448    {
    458                 printf("usage: sched cxy lid\n");
     449                printf("  usage: sched cxy lid\n");
    459450                return;
    460451        }
     
    465456    if( get_sched( cxy , lid ) )
    466457    {
    467         printf("error: illegal arguments\n");
     458        printf("  error: illegal arguments\n");
    468459    }
    469460}
     
    584575        unsigned int state = NORMAL;
    585576
     577
    586578// @@@
    587 parse("load /bin/user/sort.elf");
     579// parse("load /bin/user/sort.elf");
    588580// @@@
    589 
    590581
    591582   
Note: See TracChangeset for help on using the changeset viewer.