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

« back to all changes in this revision

Viewing changes to sys-utils/setarch.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <stdio.h>
31
31
#include <string.h>
32
32
#include <stdlib.h>
33
 
#include <errno.h>
34
 
#include <error.h>
35
33
#include <getopt.h>
36
34
#include <limits.h>
37
35
#include <sys/utsname.h>
38
36
#include "nls.h"
 
37
#include "c.h"
39
38
 
40
39
#define set_pers(pers) ((long)syscall(SYS_personality, pers))
41
40
 
42
 
/* Option --4gb has no equivalent short option, use a non-character as a
43
 
   pseudo short option. */
44
 
#define OPT_4GB (CHAR_MAX+1)
 
41
/* Options without equivalent short options */
 
42
enum {
 
43
        OPT_4GB         = CHAR_MAX + 1,
 
44
        OPT_UNAME26
 
45
};
45
46
 
46
47
#define turn_on(_flag, _opts) \
47
48
        do { \
51
52
        } while(0)
52
53
 
53
54
 
 
55
#if !HAVE_DECL_UNAME26
 
56
# define UNAME26                 0x0020000
 
57
#endif
54
58
#if !HAVE_DECL_ADDR_NO_RANDOMIZE
55
59
# define ADDR_NO_RANDOMIZE       0x0040000
56
60
#endif
84
88
 
85
89
/* Options --3gb and --4gb are for compatibitity with an old Debian setarch
86
90
   implementation. */
87
 
struct option longopts[] =
 
91
static const struct option longopts[] =
88
92
{
89
93
    { "help",               0, 0, 'h' },
90
94
    { "verbose",            0, 0, 'v' },
99
103
    { "sticky-timeouts",    0, 0, 'T' },
100
104
    { "3gb",                0, 0, '3' },
101
105
    { "4gb",                0, 0, OPT_4GB },
 
106
    { "uname-2.6",          0, 0, OPT_UNAME26 },
102
107
    { NULL,                 0, 0, 0 }
103
108
};
104
109
 
128
133
   " -3, --3gb                limits the used address space to a maximum of 3 GB\n"
129
134
   "     --4gb                ignored (for backward compatibility only)\n"));
130
135
 
 
136
   printf(_(
 
137
   "     --uname-2.6          turns on UNAME26\n"));
 
138
 
131
139
  printf(_("\nFor more information see setarch(8).\n"));
132
140
  exit(EXIT_SUCCESS);
133
141
}
149
157
{
150
158
  struct utsname un;
151
159
  int i;
152
 
  unsigned long pers_value, res;
 
160
  unsigned long pers_value;
153
161
 
154
162
  struct {
155
163
    int perval;
212
220
        break;
213
221
 
214
222
  if(transitions[i].perval < 0)
215
 
    error(EXIT_FAILURE, 0, _("%s: Unrecognized architecture"), pers);
 
223
    errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers);
216
224
 
217
225
  pers_value = transitions[i].perval | options;
218
 
  res = set_pers(pers_value);
219
 
  if(res == -EINVAL)
 
226
  if (set_pers(pers_value) == -EINVAL)
220
227
    return 1;
221
228
 
222
229
  uname(&un);
228
235
           && strcmp(un.machine, "i586")
229
236
           && strcmp(un.machine, "i686")
230
237
           && strcmp(un.machine, "athlon")))
231
 
      error(EXIT_FAILURE, 0, _("%s: Unrecognized architecture"), pers);
 
238
      errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers);
232
239
  }
233
240
 
234
241
  return 0;
262
269
  #if defined(__sparc64__) || defined(__sparc__)
263
270
   if (!strcmp(p, "sparc32bash")) {
264
271
       if (set_arch(p, 0L))
265
 
           error(EXIT_FAILURE, errno, _("Failed to set personality to %s"), p);
 
272
           err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
266
273
       execl("/bin/bash", NULL);
267
 
       error(EXIT_FAILURE, errno, "/bin/bash");
 
274
       err(EXIT_FAILURE, "/bin/bash");
268
275
   }
269
276
  #endif
270
277
 
308
315
        break;
309
316
    case OPT_4GB:          /* just ignore this one */
310
317
      break;
 
318
    case OPT_UNAME26:
 
319
        turn_on(UNAME26, options);
 
320
        break;
311
321
    }
312
322
  }
313
323
 
315
325
  argv += optind;
316
326
 
317
327
  if (set_arch(p, options))
318
 
    error(EXIT_FAILURE, errno, _("Failed to set personality to %s"), p);
 
328
    err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
319
329
 
320
330
  if (!argc) {
321
331
    execl("/bin/sh", "-sh", NULL);
322
 
    error(EXIT_FAILURE, errno, "/bin/sh");
 
332
    err(EXIT_FAILURE, "/bin/sh");
323
333
  }
324
334
 
325
335
  execvp(argv[0], argv);
326
 
  error(EXIT_FAILURE, errno, "%s", argv[0]);
 
336
  err(EXIT_FAILURE, "%s", argv[0]);
327
337
  return EXIT_FAILURE;
328
338
}