runcon.c 573 B

12345678910111213141516171819202122232425262728
  1. /* runcon.c - Run command in specified security context
  2. *
  3. * Copyright 2015 The Android Open Source Project
  4. USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))
  5. config RUNCON
  6. bool "runcon"
  7. depends on TOYBOX_SELINUX
  8. default y
  9. help
  10. usage: runcon CONTEXT COMMAND [ARGS...]
  11. Run a command in a specified security context.
  12. */
  13. #define FOR_runcon
  14. #include "toys.h"
  15. void runcon_main(void)
  16. {
  17. char *context = *toys.optargs;
  18. if (setexeccon(context)) perror_exit("Could not set context to %s", context);
  19. toys.stacktop = 0;
  20. xexec(++toys.optargs);
  21. }