aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/runcon.c
blob: bf13442e4acd738e1fe6af358734b8412edeb49d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* runcon.c - Run command in specified security context
 *
 * Copyright 2015 The Android Open Source Project

USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))

config RUNCON
  bool "runcon"
  depends on TOYBOX_SELINUX
  default n
  help
    usage: runcon CONTEXT COMMAND [ARGS...]

    Run a command in a specified security context.
*/

#define FOR_runcon
#include "toys.h"

void runcon_main(void)
{
  char *context = *toys.optargs;

  if (setexeccon(context))
    error_exit("Could not set context to %s: %s", context, strerror(errno));

  toys.optargs++;
  xexec(toys.optargs);
}