#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/kdev_t.h>
#include <rsbac/types.h>
#include <rsbac/syscalls.h>
#include <rsbac/getname.h>
#include <rsbac/error.h>

int main(int argc, char ** argv)
{
  int res = 0;
  rsbac_pm_task_id_t task;
  char name[80];
  
  if (argc >= 3)
    {
      task=strtol(argv[1],0,0);
      printf("%s: executing %s with task %i\n", argv[0],argv[2],task);
      res = rsbac_pm_change_current_task(task);
      if(res)
        {
          if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
            printf("%s: error: %s\n", argv[0], strerror(-res));
          else
            {
              get_error_name(name,res);
              printf("%s: error: %s\n", argv[0], name);
            }
          exit(1);
        }
      res = execvp(argv[2],&argv[2]);
      if(res)
        {
          if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
            printf("%s: error: %s\n", argv[0], strerror(-res));
          else
            {
              get_error_name(name,res);
              printf("%s: error: %s\n", argv[0], name);
            }
        }
    }
  else
    {
      printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
      printf("Use: %s task-nr prog args\n", argv[0]);
      printf("This program will set rsbac_pm_current_task to task-nr and then\n");
      printf("execute prog via execvp()\n");
    }
    
  return (res);
}

