~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to text-utils/ul.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include <term.h>               /* for setupterm() */
47
47
#include <stdlib.h>             /* for getenv() */
48
48
#include <limits.h>             /* for INT_MAX */
 
49
#include <signal.h>             /* for signal() */
 
50
#include <err.h>
 
51
#include <errno.h>
 
52
 
49
53
#include "nls.h"
50
 
 
 
54
#include "xalloc.h"
51
55
#include "widechar.h"
52
56
 
53
57
#ifdef HAVE_WIDECHAR
75
79
void setmode(int newmode);
76
80
static void setcol(int newcol);
77
81
static void needcol(int col);
 
82
static void sig_handler(int signo);
78
83
 
79
84
#define IESC    '\033'
80
85
#define SO      '\016'
122
127
        bindtextdomain(PACKAGE, LOCALEDIR);
123
128
        textdomain(PACKAGE);
124
129
 
 
130
        signal(SIGINT, sig_handler);
 
131
        signal(SIGTERM, sig_handler);
 
132
 
125
133
        termtype = getenv("TERM");
126
134
        if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
127
135
                termtype = "lpr";
138
146
 
139
147
                default:
140
148
                        fprintf(stderr,
141
 
                                _("usage: %s [ -i ] [ -tTerm ] file...\n"),
142
 
                                argv[0]);
143
 
                        exit(1);
 
149
                                _("Usage: %s [ -i ] [ -tTerm ] file...\n"),
 
150
                                program_invocation_short_name);
 
151
                        return EXIT_FAILURE;
144
152
                }
145
153
        setupterm(termtype, 1, &ret);
146
154
        switch(ret) {
149
157
                break;
150
158
 
151
159
        default:
152
 
                fprintf(stderr,_("trouble reading terminfo"));
 
160
                warnx(_("trouble reading terminfo"));
153
161
                /* fall through to ... */
154
162
 
155
163
        case 0:
166
174
                filter(stdin);
167
175
        else for (; optind<argc; optind++) {
168
176
                f = fopen(argv[optind],"r");
169
 
                if (f == NULL) {
170
 
                        perror(argv[optind]);
171
 
                        exit(1);
172
 
                } else
173
 
                        filter(f);
 
177
                if (!f)
 
178
                        err(EXIT_FAILURE, _("%s: open failed"), argv[optind]);
 
179
                filter(f);
174
180
        }
175
181
        if (ferror(stdout) || fclose(stdout))
176
 
                return 1;
177
 
        return 0;
 
182
                return EXIT_FAILURE;
 
183
 
 
184
        return EXIT_SUCCESS;
178
185
}
179
186
 
180
187
void filter(FILE *f)
238
245
                        continue;
239
246
 
240
247
                default:
241
 
                        fprintf(stderr,
242
 
                                _("Unknown escape sequence in input: %o, %o\n"),
 
248
                        errx(EXIT_FAILURE,
 
249
                                _("unknown escape sequence in input: %o, %o"),
243
250
                                IESC, c);
244
 
                        exit(1);
 
251
                        break;
245
252
                }
246
253
                continue;
247
254
 
420
427
{
421
428
        if (obuf == NULL) {     /* First time. */
422
429
                obuflen = INITBUF;
423
 
                obuf = malloc(sizeof(struct CHAR) * obuflen);
424
 
                if (obuf == NULL) {
425
 
                        fprintf(stderr, _("Unable to allocate buffer.\n"));
426
 
                        exit(1);
427
 
                }
 
430
                obuf = xmalloc(sizeof(struct CHAR) * obuflen);
428
431
        }
429
432
 
430
433
        /* assumes NORMAL == 0 */
485
488
                ENTER_REVERSE = ENTER_STANDOUT;
486
489
        if (!EXIT_ATTRIBUTES && EXIT_STANDOUT)
487
490
                EXIT_ATTRIBUTES = EXIT_STANDOUT;
488
 
        
 
491
 
489
492
        /*
490
493
         * Note that we use REVERSE for the alternate character set,
491
494
         * not the as/ae capabilities.  This is because we are modelling
581
584
        /* If col >= obuflen, expand obuf until obuflen > col. */
582
585
        while (col >= obuflen) {
583
586
                /* Paranoid check for obuflen == INT_MAX. */
584
 
                if (obuflen == INT_MAX) {
585
 
                        fprintf(stderr,
586
 
                                _("Input line too long.\n"));
587
 
                        exit(1);
588
 
                }
 
587
                if (obuflen == INT_MAX)
 
588
                        errx(EXIT_FAILURE, _("Input line too long."));
589
589
 
590
590
                /* Similar paranoia: double only up to INT_MAX. */
591
591
                obuflen = ((INT_MAX / 2) < obuflen)
593
593
                        : obuflen * 2;
594
594
 
595
595
                /* Now we can try to expand obuf. */
596
 
                obuf = realloc(obuf, sizeof(struct CHAR) * obuflen);
597
 
                if (obuf == NULL) {
598
 
                        fprintf(stderr,
599
 
                                _("Out of memory when growing buffer.\n"));
600
 
                        exit(1);
601
 
                }
 
596
                obuf = xrealloc(obuf, sizeof(struct CHAR) * obuflen);
602
597
        }
603
598
}
 
599
 
 
600
static void sig_handler(int signo)
 
601
{
 
602
        _exit(EXIT_SUCCESS);
 
603
}
 
604