Ignore:
Timestamp:
Jul 12, 2011, 11:52:39 AM (14 years ago)
Author:
bird
Message:

kmkbuiltins: More specific error messages (solaris EINTR).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/rm.c

    r2464 r2466  
    3939#endif /* not lint */
    4040#include <sys/cdefs.h>
    41 //__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.47 2004/04/06 20:06:50 markm Exp $");
     41/*__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.47 2004/04/06 20:06:50 markm Exp $");*/
    4242#endif
    4343
     
    287287        }
    288288        while ((p = fts_read(fts)) != NULL) {
     289                const char *operation = "chflags";
    289290                switch (p->fts_info) {
    290291                case FTS_DNR:
    291292                        if (!fflag || p->fts_errno != ENOENT) {
    292                                 fprintf(stderr, "%s: %s: %s" CUR_LINE() "\n",
     293                                fprintf(stderr, "fts: %s: %s: %s" CUR_LINE() "\n",
    293294                                        argv0, p->fts_path, strerror(p->fts_errno));
    294295                                eval = 1;
     
    297298                case FTS_ERR:
    298299                        fts_close(fts);
    299                         return errx(1, "%s: %s " CUR_LINE(), p->fts_path, strerror(p->fts_errno));
     300                        return errx(1, "fts: %s: %s " CUR_LINE(), p->fts_path, strerror(p->fts_errno));
    300301                case FTS_NS:
    301302                        /*
     
    306307                                break;
    307308                        if (!fflag || p->fts_errno != ENOENT) {
    308                                 fprintf(stderr, "%s: %s: %s " CUR_LINE() "\n",
    309                                         argv0, p->fts_path, strerror(p->fts_errno), __LINE__);
     309                                fprintf(stderr, "fts: %s: %s: %s " CUR_LINE() "\n",
     310                                        argv0, p->fts_path, strerror(p->fts_errno));
    310311                                eval = 1;
    311312                        }
     
    370371                                        continue;
    371372                                }
     373                                operation = "mkdir";
    372374                                break;
    373375
     
    381383                                        continue;
    382384                                }
     385                                operation = "undelete";
    383386                                break;
    384387#endif
     
    410413                                        continue;
    411414                                }
     415                                operation = "unlink";
     416                                break;
    412417                        }
    413418                }
     
    415420err:
    416421#endif
    417                 fprintf(stderr, "%s: %s: %s " CUR_LINE() "\n", argv0, p->fts_path, strerror(errno));
     422                fprintf(stderr, "%s: %s: %s: %s " CUR_LINE() "\n", operation, argv0, p->fts_path, strerror(errno));
    418423                eval = 1;
    419424        }
     
    447452         */
    448453        while ((f = *argv++) != NULL) {
     454                const char *operation = "?";
    449455                /* Assume if can't stat the file, can't unlink it. */
    450456                if (lstat(f, &sb)) {
     
    457463#endif
    458464                                if (!fflag || errno != ENOENT) {
    459                                         fprintf(stderr, "%s: %s: %s " CUR_LINE() "\n", argv0, f, strerror(errno));
     465                                        fprintf(stderr, "lstat: %s: %s: %s " CUR_LINE() "\n", argv0, f, strerror(errno));
    460466                                        eval = 1;
    461467                                }
     
    485491#endif
    486492                if (rval == 0) {
    487                         if (S_ISWHT(sb.st_mode))
     493                        if (S_ISWHT(sb.st_mode)) {
    488494                                rval = undelete(f);
    489                         else if (S_ISDIR(sb.st_mode))
     495                                operation = "undelete";
     496                        } else if (S_ISDIR(sb.st_mode)) {
    490497                                rval = rmdir(f);
    491                         else {
     498                                operation = "rmdir";
     499                        } else {
    492500                                if (Pflag)
    493501                                        if (!rm_overwrite(f, &sb))
     
    500508                                }
    501509#endif
     510                                operation = "unlink";
    502511                        }
    503512                }
    504513                if (rval && (!fflag || errno != ENOENT)) {
    505                         fprintf(stderr, "%s: %s: %s" CUR_LINE() "\n", argv0, f, strerror(errno));
     514                        fprintf(stderr, "%s: %s: %s: %s" CUR_LINE() "\n", operation, argv0, f, strerror(errno));
    506515                        eval = 1;
    507516                }
     
    533542        int bsize, fd, wlen;
    534543        char *buf = NULL;
     544        const char *operation = "lstat";
    535545
    536546        fd = -1;
     
    542552        if (!S_ISREG(sbp->st_mode))
    543553                return (1);
     554        operation = "open";
    544555        if ((fd = open(file, O_WRONLY, 0)) == -1)
    545556                goto err;
     
    557568
    558569#define PASS(byte) {                                                    \
     570        operation = "write";                                            \
    559571        memset(buf, byte, bsize);                                       \
    560572        for (len = sbp->st_size; len > 0; len -= wlen) {                \
     
    565577}
    566578        PASS(0xff);
     579        operation = "fsync/lseek";
    567580        if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
    568581                goto err;
    569582        PASS(0x00);
     583        operation = "fsync/lseek";
    570584        if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
    571585                goto err;
     
    575589                return (1);
    576590        }
     591        operation = "fsync/close";
    577592
    578593err:    eval = 1;
     
    581596        if (fd != -1)
    582597                close(fd);
    583         fprintf(stderr, "%s: %s: %s" CUR_LINE() "\n", argv0, file, strerror(errno));
     598        fprintf(stderr, "%s: %s: %s: %s" CUR_LINE() "\n", operation, argv0, file, strerror(errno));
    584599        return (0);
    585600}
Note: See TracChangeset for help on using the changeset viewer.