Exemplo n.º 1
0
void test_syscall(int syscall) {

	//clear_log();
	do_intercept(syscall, 0);
	do_as_guest("./test_full nonroot %d", syscall, 0);
	do_start(syscall, -2, -EINVAL);
	do_start(syscall, 0, 0);
	do_stop(syscall, 0, 0);
	do_start(syscall, 1, 0);
	do_as_guest("./test_full stop %d 1 %d", syscall, -EPERM);
	do_stop(syscall, 1, 0);
	do_as_guest("./test_full start %d -1 %d", syscall, 0);
	do_stop(syscall, last_child, -EINVAL);
	do_release(syscall, 0);

	puts("----- START OF test_PASS -----");
	test_PASS(syscall);
	puts("----- END OF test_PASS -----");
	puts("----- START OF test_A -----");
	test_A(syscall);
	puts("----- END OF test_A -----");
	puts("----- START OF test_B -----");
	test_B(syscall, TRUE);
	puts("----- END OF test_B -----");
	puts("----- START OF test_CDE ----");
	test_CDE(syscall);
	puts("----- END OF test_CDE ----");
}
Exemplo n.º 2
0
int main(int argc, char **argv) {

	srand(time(NULL));

	if (argc > 1 && strcmp(argv[1], "intercept") == 0)
		return do_intercept(atoi(argv[2]), atoi(argv[3]));

	if (argc > 1 && strcmp(argv[1], "release") == 0)
		return do_release(atoi(argv[2]), atoi(argv[3]));

	if (argc > 1 && strcmp(argv[1], "start") == 0)
		return do_start(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));

	if (argc > 1 && strcmp(argv[1], "stop") == 0)
		return do_stop(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));

	if (argc > 1 && strcmp(argv[1], "monitor") == 0)
		return test_monitor(atoi(argv[2]), TRUE);

	if (argc > 1 && strcmp(argv[1], "nonroot") == 0)
		return do_nonroot(atoi(argv[2]));

	struct sigaction sa;
	sa.sa_flags = SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sa.sa_sigaction = on_quit;
	if (sigaction(SIGQUIT, &sa, NULL) == -1)
		perror("Cannot register signal handler");

	test("insmod interceptor.ko %s", "", system("insmod interceptor.ko") == 0);
	test("bad MY_SYSCALL args%s", "",  vsyscall_arg(MY_CUSTOM_SYSCALL, 3, 100, 0, 0) == -EINVAL);
	do_intercept(MY_CUSTOM_SYSCALL, -EINVAL);
	do_release(MY_CUSTOM_SYSCALL, -EINVAL);
	do_intercept(-1, -EINVAL);
	do_release(-1, -EINVAL);
	do_intercept(__NR_exit, 0);
	do_release(__NR_exit, 0);

	test_syscall(SYS_open);
	/* The above line of code tests SYS_open.
	   Feel free to add more tests here for other system calls,
	   once you get everything to work; check Linux documentation
	   for other syscall number definitions.  */

	do_intercept(SYS_open, 0);
	do_start(SYS_open, -1, 0);
	test_monitor(SYS_open, TRUE);
	test("rmmod interceptor.ko %s", "", system("rmmod interceptor") == 0);
	test_monitor(SYS_open, FALSE);
	return 0;
}
Exemplo n.º 3
0
int do_nonroot(int syscall) {
	do_intercept(syscall, -EPERM);
	do_release(syscall, -EPERM);
	do_start(syscall, 0, -EPERM);
	do_stop(syscall, 0, -EPERM);
	do_start(syscall, 1, -EPERM);
	do_stop(syscall, 1, -EPERM);
	do_start(syscall, getpid(), 0);
	do_start(syscall, getpid(), -EBUSY);
	do_monitor(syscall);
	do_stop(syscall, getpid(), 0);
	do_stop(syscall, getpid(), -EINVAL);
	return 0;
}
Exemplo n.º 4
0
/*
 * This is an in-fix recursive function called before s is started to
 * stop every service that depends on s, in reverse order *or* after s
 * was started to start again every service that depends on s. The
 * action parametere controls if this function should start or stop
 * the procceses that depends on s.
 * @param s A Service_T object
 * @param action An action to do on the dependant services
 */
static void do_depend(Service_T s, const char *action) {

  Service_T child;
  
  ASSERT(s);

  for(child= servicelist; child; child= child->next) {
    
    if(child->dependantlist) {

      Dependant_T d;
    
      for(d= child->dependantlist; d; d= d->next) {

	if(IS(d->dependant, s->name)) {
	
	  if(IS(action, "start"))
	    do_start(child);
          else if(IS(action, "monitor"))
	    do_monitor(child);
	
	  do_depend(child, action);
	
	  if(IS(action, "stop"))
	    do_stop(child);
          else if(IS(action, "unmonitor"))
	    do_unmonitor(child);

	  break;

	}
      }
    }
  }
}
Exemplo n.º 5
0
Arquivo: control.c Projeto: hafiz/yoke
/*
 * This is an in-fix recursive function called before s is started to
 * stop every service that depends on s, in reverse order *or* after s
 * was started to start again every service that depends on s. The
 * action parametere controls if this function should start or stop
 * the procceses that depends on s.
 * @param s A Service_T object
 * @param action An action to do on the dependant services
 */
static void do_depend(Service_T s, int action) {
  Service_T child;
  
  ASSERT(s);

  for (child = servicelist; child; child = child->next) {
    if (child->dependantlist) {
      Dependant_T d;
    
      for (d = child->dependantlist; d; d = d->next) {
	if (IS(d->dependant, s->name)) {
	  if (action == ACTION_START)
	    do_start(child);
          else if (action == ACTION_MONITOR)
	    do_monitor(child);
	  do_depend(child, action);
	  if (action == ACTION_STOP)
	    do_stop(child);
          else if (action == ACTION_UNMONITOR)
	    do_unmonitor(child);
	  break;
	}
      }
    }
  }
}
Exemplo n.º 6
0
Arquivo: control.c Projeto: hafiz/yoke
/*
 * This is a post- fix recursive function for starting every service
 * that s depends on before starting s.
 * @param s A Service_T object
 */
static void do_start(Service_T s) {
  ASSERT(s);

  if (s->visited)
    return;
  
  s->visited = TRUE;
  
  if (s->dependantlist) {
    Dependant_T d;
    
    for (d = s->dependantlist; d; d = d->next ) {
      Service_T parent = Util_getService(d->dependant);
      ASSERT(parent);
      do_start(parent);
    }
  }
  
  if (s->start && (s->type!=TYPE_PROCESS || !Util_isProcessRunning(s))) {
    LogInfo("'%s' start: %s\n", s->name, s->start->arg[0]);
    spawn(s, s->start, NULL);
    /* We only wait for a process type, other service types does not have a pid file to watch */
    if (s->type == TYPE_PROCESS)
      wait_start(s);
  }
  Util_monitorSet(s);
}
Exemplo n.º 7
0
/*
void bluetooth(void) {
  unsigned int redata,Ddata,choice;
  if(identityset==1)
  {
    redatah=LPLD_UART_GetChar(UART4);
    if(redatah==255)
    {
      identityset=0;
    }
  }
  
  if(identityset==2)
  {
    identityset=0;
    redata=LPLD_UART_GetChar(UART4)+redatah*256;
    choice=redata/4096;
    redata=redata%4096;
    Ddata=redata/256*100+redata/16%16*10+redata%16;
    
    switch(choice)
    {        
    case 0:  turnleft_time_set=Ddata*10;break;
    case 1:  testvalue1=Ddata;break;//将想要实时修改的全局变量替换掉null 在串口调试助手中  
    case 2:  PID_KP=Ddata;break;//输入四位的十六进制字符串 当做十进制的输入就可以了
    case 3:  testvalue3=Ddata;break;//第一个数位你想要改变的变量对应编号
    case 4:  testvalue4=Ddata;break;
    case 5:  testvalue5=Ddata;break;
    case 6:  haoswitch=Ddata;break;
    //case 7:  kd1=Ddata;break;
    //case 8:  kd2=Ddata;break;
    //case 9:  kd3=Ddata;break;
    //case 10:  kd4=Ddata;break;
    //case 11:  kd5=Ddata;break;
    //case 12:  kd6=Ddata;break;
    //case 13:  jiuzheng=Ddata;break;
    //case 14:  null=Ddata;break;
    //case 15:  null=Ddata;break;
    default : break;
    }
    
  }
  identityset++;
}

void sendblue(int a,int b)
{
  char sendbluedata[2];
  
  sendbluedata[0]=a*16+b/256;
  
  sendbluedata[1]=b%256;  
  LPLD_UART_PutCharArr(UART4,(char*)sendbluedata,2);
}

*/
void do_control(void)
{
	switch (routechoice) {
	case C_AHEAD:
		do_goahead();		break;
	case C_GETCORNER:
		do_getcorner();		break;
	case C_LEFT:
		do_turnleft();		break;
	case C_RIGHT:
		do_turnright();		break;
	case C_STOP:
		do_stop();			break;
	case C_AROUND:
		do_turnaround();	break;
	case C_BREAK:
		do_break();			break;
	case C_START:
		do_start(); 		break;
	case C_LETSWIN:
		do_letswin(); 		break;
	default:
		do_stop();
  }
}
Exemplo n.º 8
0
int VMDTracker::start(const SensorConfig *config) {
  set_scale(config->getscale());
  set_offset(config->getoffset());
  set_right_rot(config->getright_rot());
  set_left_rot(config->getleft_rot());
  return do_start(config);
}
Exemplo n.º 9
0
void test_syscall(int syscall) {

	//clear_log();
	do_intercept(syscall, 0);
	do_intercept(syscall, -EBUSY);
	do_as_guest("./test_full nonroot %d", syscall, 0);
	do_start(syscall, -2, -EINVAL);
	do_start(syscall, 0, 0);
	do_stop(syscall, 0, 0);
	do_start(syscall, 1, 0);
	do_as_guest("./test_full stop %d 1 %d", syscall, -EPERM);
	do_stop(syscall, 1, 0);
	do_as_guest("./test_full start %d -1 %d", syscall, 0);
	do_stop(syscall, last_child, -EINVAL);
	do_release(syscall, 0);
}
Exemplo n.º 10
0
int incexc_send_client(struct config *conf, struct cntr *p1cntr)
{
	if(do_start("incexc", "incexc ok")
	  || do_sends(conf)
	  || do_finish("incexc end", "incexc end ok"))
		return -1;
	return 0;
}
Exemplo n.º 11
0
void main(int argc, char *argv[]) {

	/* Initialise some variables */
	symboltable = NULL;
	current_line = 1;
	lineptr = linebuf;

	/* Process any command line arguments */
	do_commandline(argc, argv);

	/* Display the welcome screen */
	do_start();

	/* Open any requested file */
	if (filename != NULL) {
		file = fopen(filename, "r");
		if (!file) {
			fprintf(stderr,"jsparse: Could not open file requested file \"%s\"\n", filename);
			exit(1);
		}
		/* yyin is the file handle for yacc */
		yyin = file;
	}

	/* Build in predefined symbols */
	do_predefined();

	/* Start parsing */
	do {
		yyparse();
	}
	while (!feof(yyin));

	current_line--;

	/* Report any unreported errors if we received at least one line of code */
	if (current_line > 0) {
		report_errors();
	}

	/* Display summary statistics */

	printf("\n%d line", current_line);
	if (current_line != 1) printf("s");
	printf(" processed. %d Error", numerrors);
	if (numerrors != 1) printf("s");
	printf(", ");

/*	if (warnings_flag || !(warnings_flag || errors_flag)) {*/
	if (warnings_flag) {
		printf("%d Warning", numwarnings);
		if (numwarnings != 1) printf("s");
		printf(".\n\n");
	} else {
		printf("Warnings disabled.\n\n");
	}
}
Exemplo n.º 12
0
/* note this test is run after all processes have been intercepted*/
int do_nonroot(int syscall) {
	do_intercept(syscall, -EPERM);
	do_release(syscall, -EPERM);
	do_start(syscall, 0, -EPERM);
	do_stop(syscall, 0, -EPERM);
	do_start(syscall, 1, -EPERM);
	do_stop(syscall, 1, -EPERM);
	do_start(syscall, getpid(), 0);
	do_start(syscall, getpid(), -EBUSY);
	test_monitor(syscall, TRUE);
	do_stop(syscall, getpid(), 0);
	do_stop(syscall, getpid(), -EINVAL);

	puts("----- START OF test_B -----");
	test_B(syscall, FALSE);
	puts("----- END OF test_B -----");

	return 0;
}
Exemplo n.º 13
0
void test_B(int syscall, int iamroot) {
#define subtestroot(s) printf((s" as %s\n"), (iamroot)?"root":"nonroot")

	subtestroot("EPERM: intercept");
	do_intercept(syscall, iamroot ? 0 : -EPERM);
	subtestroot("EPERM: monitor self");
	do_start(syscall, -1, 0);
	do_stop(syscall, -1, 0);
	subtestroot("EPERM: monitor all processes");
	do_start(syscall, 0, iamroot ? 0 : -EPERM);
	do_stop(syscall, 0, iamroot ? 0 : -EPERM);
	subtestroot("EPERM: monitor init process");
	do_start(syscall, 1, iamroot ? 0 : -EPERM);
	do_stop(syscall, 1, iamroot ? 0 : -EPERM);
	subtestroot("EPERM: release");
	do_release(syscall, iamroot ? 0 : -EPERM);

#undef subtestroot
}
Exemplo n.º 14
0
int coopth_start(int tid, coopth_func_t func, void *arg)
{
    struct coopth_t *thr;
    int err;
    check_tid(tid);
    thr = &coopthreads[tid];
    assert(thr->tid == tid);
    err = do_start(thr, ST(RUNNING), func, arg);
    if (err)
	return err;
    return 0;
}
Exemplo n.º 15
0
int
main(int argc, char **argv)
{
    perf_base_attr.read_format = 
        PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING |
        PERF_FORMAT_GROUP;

    argp_parse (&argp, argc, argv,
                ARGP_IN_ORDER,
                0,
                NULL);

    if (perf_ctrs.head) {
        perf_ctrs.head->attr.disabled = 1;
        perf_ctrs.head->attr.enable_on_exec = 1;
    }

    for (int i = 0; i < num_processes; i++) {
	bench_process_t *p = processes + i;

        /* Setup log redirection */
        if (log_base || quiet) {
            char name[1024];

            if (!quiet)
                snprintf(name, sizeof(name), "%s.%i.stdout", log_base, i);
            else 
                snprintf(name, sizeof(name), "/dev/null");
            p->stdout = fopen(name, "w");
            EXPECT_ERRNO(p->stdout);

            if (split_logs) {
                snprintf(name, sizeof(name), "%s.%i.stderr", log_base, i);
                p->stderr = fopen(name, "w");
                EXPECT_ERRNO(p->stderr);
            } else
                p->stderr = p->stdout;
        } else {
            p->stdout = NULL;
            p->stderr = NULL;
        }

        /* Create a private copy of the counter configuration for each
         * target */
        for (ctr_t *cur = perf_ctrs.head; cur; cur = cur->next) {
            ctr_t *c = ctr_create(&cur->attr);
            assert(c);
            ctrs_add(&p->ctrs, c);
        }
    }

    return do_start();
}
Exemplo n.º 16
0
void test_A(int syscall) {
	// test negative syscall number
	do_intercept(-1, -EINVAL);
	do_release(-1, -EINVAL);
	do_start(-1, -1, -EINVAL);
	do_stop(-1, -1, -EINVAL);
	// test the last syscall
	do_intercept(MAX_SYSCALLS - 1, 0);
	do_start(MAX_SYSCALLS - 1, -1, 0);
	do_stop(MAX_SYSCALLS - 1, -1, 0);
	do_release(MAX_SYSCALLS - 1, 0);
	// test greater than NR_syscalls
	do_intercept(MAX_SYSCALLS, -EINVAL);
	do_release(MAX_SYSCALLS, -EINVAL);
	do_start(MAX_SYSCALLS, -1, -EINVAL);
	do_stop(MAX_SYSCALLS, -1, -EINVAL);
	do_intercept(MAX_SYSCALLS + 1, -EINVAL);
	do_release(MAX_SYSCALLS + 1, -EINVAL);
	do_start(MAX_SYSCALLS + 1, -1, -EINVAL);
	do_stop(MAX_SYSCALLS + 1, -1, -EINVAL);
	// test MY_CUSTOM_SYSCALL
	do_intercept(MY_CUSTOM_SYSCALL, -EINVAL);
	do_release(MY_CUSTOM_SYSCALL, -EINVAL);
	do_start(MY_CUSTOM_SYSCALL, -1, -EINVAL);
	do_stop(MY_CUSTOM_SYSCALL, -1, -EINVAL);

	// test on pids
	do_intercept(syscall, 0);
	do_start(syscall, -2, -EINVAL);
	do_stop(syscall, -2, -EINVAL);
	do_release(syscall, 0);
}
Exemplo n.º 17
0
int coopth_start_sleeping(int tid, coopth_func_t func, void *arg)
{
    struct coopth_t *thr;
    int err;
    check_tid(tid);
    thr = &coopthreads[tid];
    assert(thr->tid == tid);
    err = do_start(thr, ST(SLEEPING), func, arg);
    if (err)
	return err;
    if (thr->sleeph.pre)
	thr->sleeph.pre(thr->tid);
    return 0;
}
Exemplo n.º 18
0
/**
 * gpp_worker_start:
 * @self: A #GPPWorker that will start handling requests.
 *
 * This will make @self start handling requests.
 *
 * Returns: %TRUE if @self could be started, %FALSE if it was already.
 */
gboolean
gpp_worker_start (GPPWorker *self)
{
  GPPWorkerPrivate *priv = GET_PRIV (self);
  GPPWorkerClass *klass = GPP_WORKER_GET_CLASS (self);
  if (priv->frontend_source)
    return FALSE;

  if (!klass->handle_request)
    return FALSE;

  do_start (self);

  return TRUE;
}
Exemplo n.º 19
0
int
do_pass_remort_test(struct creature *ch)
{
    int i;

    // Wipe thier skills
    for (i = 1; i <= MAX_SKILLS; i++)
        SET_SKILL(ch, i, 0);

    do_start(ch, false);

    REMOVE_BIT(PRF_FLAGS(ch),
        PRF_NOPROJECT | PRF_ROOMFLAGS | PRF_HOLYLIGHT | PRF_NOHASSLE |
        PRF_LOG1 | PRF_LOG2 | PRF_NOWIZ);

    REMOVE_BIT(PLR_FLAGS(ch), PLR_HALT | PLR_INVSTART | PLR_MORTALIZED |
        PLR_OLCGOD);

    GET_INVIS_LVL(ch) = 0;
    GET_COND(ch, DRUNK) = 0;
    GET_COND(ch, FULL) = 0;
    GET_COND(ch, THIRST) = 0;

    // Give em another gen
    if (GET_REMORT_GEN(ch) == 10)
        account_set_quest_points(ch->account, ch->account->quest_points + 1);
    else
        GET_REMORT_GEN(ch)++;

    // At gen 1 they enter the world of pk, like it or not
    if (GET_REMORT_GEN(ch) >= 1 && RAW_REPUTATION_OF(ch) <= 0)
        gain_reputation(ch, 5);
    // Whack thier remort invis
    GET_WIMP_LEV(ch) = 0;       // wimpy
    GET_TOT_DAM(ch) = 0;        // cyborg damage

    // Tell everyone that they remorted
    char *msg = tmp_sprintf("%s completed gen %d remort test",
        GET_NAME(ch), GET_REMORT_GEN(ch));
    mudlog(LVL_IMMORT, BRF, false, "%s", msg);

    REMOVE_BIT(ch->in_room->room_flags, ROOM_NORECALL);

    // Save the char and its implants but not its eq
    creature_remort(ch);

    return 1;
}
Exemplo n.º 20
0
int main(int argc, char **argv) {

	srand(time(NULL));

	if (argc>1 && strcmp(argv[1], "intercept") == 0) 
		return do_intercept(atoi(argv[2]), atoi(argv[3]));

	if (argc>1 && strcmp(argv[1], "release") == 0)
		return do_release(atoi(argv[2]), atoi(argv[3]));

	if (argc>1 && strcmp(argv[1], "start") == 0)
		return do_start(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));

	if (argc>1 && strcmp(argv[1], "stop") == 0)
		return do_stop(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));

	if (argc>1 && strcmp(argv[1], "monitor") == 0)
		return do_monitor(atoi(argv[2]));

	if (argc>1 && strcmp(argv[1], "nonroot") == 0)
		return do_nonroot(atoi(argv[2]));

	test("insmod interceptor.ko %s", "", system("insmod interceptor.ko") == 0);
	test("bad MY_SYSCALL args%s", "",  vsyscall_arg(MY_CUSTOM_SYSCALL, 3, 100, 0, 0) == -EINVAL);
	do_intercept(MY_CUSTOM_SYSCALL, -EINVAL);
	do_release(MY_CUSTOM_SYSCALL, -EINVAL);
	do_intercept(-1, -EINVAL);
	do_release(-1, -EINVAL);
	do_intercept(__NR_exit, 0);
	do_release(__NR_exit, 0);

	test_syscall(SYS_open);
    /* The above line of code tests SYS_open.
     * Feel free to add more tests here for other system calls, 
     * once you get everything to work; check Linux documentation
     * for other syscall number definitions. 
     */
    test_syscall(SYS_write);
    test_syscall(SYS_read);

	test("rmmod interceptor.ko %s", "", system("rmmod interceptor") == 0);
	return 0;
}
Exemplo n.º 21
0
/*
 * This is a post- fix recursive function for starting every service
 * that s depends on before starting s.
 * @param s A Service_T object
 */
static void do_start(Service_T s) {

  ASSERT(s);

  if(s->visited)
    return;
  
  s->visited= TRUE;
  
  if(s->dependantlist) {
    
    Dependant_T d;
    
    for(d= s->dependantlist; d; d= d->next ) {
      
      Service_T parent= get_service(d->dependant);
      ASSERT(parent);
      do_start(parent);
      
    }

  }
  
  if(s->start && (s->type!=TYPE_PROCESS || !is_process_running(s))) {
    int status;
    pthread_t thread;

    log("start: (%s) %s\n", s->name, s->start->arg[0]);
    spawn(s, s->start, "Started");
    if(s->type==TYPE_PROCESS) {
      /* We only wait for a process type, other service types does not
       * have a pid file to watch */
      status= pthread_create(&thread, NULL, wait_start, s);
      if(status != 0) {
	log("Warning: Failed to create the start controller thread. "
	    "Thread error -- %s.\n", strerror(status));
      }
    }
  }

  monitor_set(s);

}
Exemplo n.º 22
0
void JamomaTimeConstraint::start()
{
  if (mRunning)
    throw runtime_error("time constraint is running");
  
  // set clock duration using maximal duration
  setDuration(mDurationMax);
  
  // start all jamoma time processes
  for (const auto& timeProcess : timeProcesses())
  {
    JamomaTimeProcess* t = dynamic_cast<JamomaTimeProcess*>(timeProcess.get());
    if(t)
      t->start();
  }
  
  // launch the clock
  do_start();
}
Exemplo n.º 23
0
void
PingusMenu::on_click(MenuButton* button)
{
  if (button == start_button)
  {
    do_start("worldmaps/tutorial.worldmap");
  }
  else if (button == quit_button)
  {
    do_quit();
  }
  else if (button == editor_button)
  {
    do_edit();
  }
  else if (button == contrib_button)
  {
    ScreenManager::instance()->push_screen(std::make_shared<LevelMenu>());
  }
  else if (button == options_button)
  {
    ScreenManager::instance()->push_screen(std::make_shared<OptionMenu>());
  }
}
Exemplo n.º 24
0
	/// Stats generating the workload
	public: void start()
	{
		do_start();
	}
Exemplo n.º 25
0
int
main(int argc, char *argv[])
{
	char	*subcmd;
	int	cmdnum;
	int	cmd_index = 0;
	int	rc = SUCCESS;

	(void) setlocale(LC_ALL, "");

#if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	cryptodebug_init(basename(argv[0]));

	if (argc < REQ_ARG_CNT) {
		usage();
		return (ERROR_USAGE);
	}

	/* get the subcommand index */
	cmd_index = 0;
	subcmd = argv[1];
	cmdnum = sizeof (cmd_table)/sizeof (cmd_table[0]);

	while ((cmd_index < cmdnum) &&
	    (strcmp(subcmd, cmd_table[cmd_index]) != 0)) {
		cmd_index++;
	}
	if (cmd_index >= cmdnum) {
		usage();
		return (ERROR_USAGE);
	}

	/* do the subcommand */
	switch (cmd_index) {
	case CRYPTO_LIST:
		rc = do_list(argc, argv);
		break;
	case CRYPTO_DISABLE:
		rc = do_disable(argc, argv);
		break;
	case CRYPTO_ENABLE:
		rc = do_enable(argc, argv);
		break;
	case CRYPTO_INSTALL:
		rc = do_install(argc, argv);
		break;
	case CRYPTO_UNINSTALL:
		rc = do_uninstall(argc, argv);
		break;
	case CRYPTO_UNLOAD:
		rc = do_unload(argc, argv);
		break;
	case CRYPTO_REFRESH:
		rc = do_refresh(argc);
		break;
	case CRYPTO_START:
		rc = do_start(argc);
		break;
	case CRYPTO_STOP:
		rc = do_stop(argc);
		break;
	case CRYPTO_HELP:
		usage();
		rc = SUCCESS;
		break;
	default: /* should not come here */
		usage();
		rc = ERROR_USAGE;
		break;
	}
	return (rc);
}
Exemplo n.º 26
0
void test_CDE(int syscall) {
	//C -EINVAL
	subtest("Cannot de-intercept a system call that has not been intercepted yet.");
	do_release(syscall, -EINVAL);
	subtest("Cannot stop monitoring a pid for a syscall that has not been intercepted.");
	do_stop(syscall, -1, -EINVAL);
	do_stop(syscall, 0, -EINVAL);
	subtest("Cannot start monitoring a pid for that has not been intercepted yet.");
	do_start(syscall, -1, -EINVAL);
	do_start(syscall, 0, -EINVAL);

	do_intercept(syscall, 0);

	subtest("Cannot start monitoring a pid that is invalid.");
	do_start(syscall, 1234567, -EINVAL);
	do_start(syscall, -2, -EINVAL);
	subtest("Cannot stop monitoring for a pid that is not being monitored.");
	do_stop(syscall, 0, -EINVAL);
	do_stop(syscall, -1, -EINVAL);
	subtest("Cannot stop monitoring for a pid that is blacklisted.");
	do_start(syscall, 0, 0);
	do_stop(syscall, -1, 0);
	do_stop(syscall, -1, -EINVAL);
	do_stop(syscall, 0, 0);
	subtest("EINVAL: stop all -> stop all");
	do_start(syscall, 0, 0);
	do_stop(syscall, 0, 0);
	do_stop(syscall, 0, -EINVAL);
	subtest("EINVAL: start one pid -> stop the same pid -> stop all");
	do_start(syscall, -1, 0);
	do_stop(syscall, -1, 0);
	do_stop(syscall, 0, -EINVAL);


	do_release(syscall, 0);

	//D -EBUSY
	do_intercept(syscall, 0);

	subtest("EBUSY: intercepting a system call that is already intercepted");
	do_intercept(syscall, -EBUSY);
	subtest("EBUSY: monitoring a pid that is being whitelisted");
	do_start(syscall, -1, 0);
	do_start(syscall, -1, -EBUSY);
	do_stop(syscall, -1, 0);
	subtest("EBUSY: monitoring a pid that is being monitored globally");
	do_start(syscall, 0, 0);
	do_start(syscall, -1, -EBUSY);
	do_stop(syscall, 0, 0);
	subtest("EBUSY: monitoring all pids when all pids are being monitored");
	do_start(syscall, 0, 0);
	do_start(syscall, 0, -EBUSY);
	do_stop(syscall, 0, 0);
	subtest("OK: monitoring all pids when some pids are being monitored");
	do_start(syscall, -1, 0);
	do_start(syscall, 0, 0);
	do_stop(syscall, -1, 0);
	do_stop(syscall, 0, 0);
	//E -ENOMEM
	//If a pid cannot be added to a monitored list, due to no memory being available, an -ENOMEM error code should be returned.
	// int child;
	// int res = 0;
	// while (!res) {
	// 	switch (child = fork()) {
	// 	case -1://error
	// 		assert(0);
	// 	case 0: //child
	// 		pause();
	// 	default: //parent
	// 		res = vsyscall_arg(MY_CUSTOM_SYSCALL, 3, REQUEST_START_MONITORING, syscall, child);
	// 		// printf("start monitoring %d: %d\n", child, res);
	// 		break;
	// 	}
	// }
	// test("%d no memory", syscall, res == -ENOMEM);
	// signal(SIGQUIT, SIG_IGN);
	// kill(-getpid(), SIGQUIT);

	do_release(syscall, 0);
}
Exemplo n.º 27
0
/**
 * gst_buffer_pool_set_active:
 * @pool: a #GstBufferPool
 * @active: the new active state
 *
 * Control the active state of @pool. When the pool is active, new calls to
 * gst_buffer_pool_acquire_buffer() will return with GST_FLOW_FLUSHING.
 *
 * Activating the bufferpool will preallocate all resources in the pool based on
 * the configuration of the pool.
 *
 * Deactivating will free the resources again when there are no outstanding
 * buffers. When there are outstanding buffers, they will be freed as soon as
 * they are all returned to the pool.
 *
 * Returns: %FALSE when the pool was not configured or when preallocation of the
 * buffers failed.
 */
gboolean
gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
{
  gboolean res = TRUE;
  GstBufferPoolPrivate *priv;

  g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);

  GST_LOG_OBJECT (pool, "active %d", active);

  priv = pool->priv;

  GST_BUFFER_POOL_LOCK (pool);
  /* just return if we are already in the right state */
  if (priv->active == active)
    goto was_ok;

  /* we need to be configured */
  if (!priv->configured)
    goto not_configured;

  if (active) {
    if (!do_start (pool))
      goto start_failed;

    /* unset the flushing state now */
    gst_poll_read_control (priv->poll);
    g_atomic_int_set (&pool->flushing, 0);
  } else {
    gint outstanding;

    /* set to flushing first */
    g_atomic_int_set (&pool->flushing, 1);
    gst_poll_write_control (priv->poll);

    /* when all buffers are in the pool, free them. Else they will be
     * freed when they are released */
    outstanding = g_atomic_int_get (&priv->outstanding);
    GST_LOG_OBJECT (pool, "outstanding buffers %d", outstanding);
    if (outstanding == 0) {
      if (!do_stop (pool))
        goto stop_failed;
    }
  }
  priv->active = active;
  GST_BUFFER_POOL_UNLOCK (pool);

  return res;

was_ok:
  {
    GST_DEBUG_OBJECT (pool, "pool was in the right state");
    GST_BUFFER_POOL_UNLOCK (pool);
    return TRUE;
  }
not_configured:
  {
    GST_ERROR_OBJECT (pool, "pool was not configured");
    GST_BUFFER_POOL_UNLOCK (pool);
    return FALSE;
  }
start_failed:
  {
    GST_ERROR_OBJECT (pool, "start failed");
    GST_BUFFER_POOL_UNLOCK (pool);
    return FALSE;
  }
stop_failed:
  {
    GST_WARNING_OBJECT (pool, "stop failed");
    GST_BUFFER_POOL_UNLOCK (pool);
    return FALSE;
  }
}
Exemplo n.º 28
0
void test_PASS(int syscall) {
	int child;

	subtest("intercept");
	do_intercept(syscall, 0);
	do_release(syscall, 0);

	subtest("monitor");
	do_intercept(syscall, 0);
	test_monitor(syscall, FALSE);
	do_start(syscall, -1, 0);
	test_monitor(syscall, TRUE);
	do_stop(syscall, -1, 0);
	test_monitor(syscall, FALSE);
	do_release(syscall, 0);

	subtest("monitor & kill monitored process");
	do_intercept(syscall, 0);
	switch (child = fork()) {
	case -1:
		assert(0);
	case 0:
		// monitor the child process then exit
		do_start(syscall, -1, 0);
		test_monitor(syscall, TRUE);
		exit(0);
	default:
		waitpid(child, NULL, 0);
		// child should have been unmonitored automatically
		// there is no way to start process with specific pid...
		do_start(syscall, child, -EINVAL);
		do_stop(syscall, child, -EINVAL);
	}
	do_release(syscall, 0);

	subtest("monitor all pids");
	do_intercept(syscall, 0);
	test_monitor2(syscall, FALSE, FALSE);
	do_start(syscall, 0, 0);
	test_monitor2(syscall, TRUE, TRUE);

	subtest("stop monitor current pid");
	do_stop(syscall, -1, 0);
	test_monitor2(syscall, FALSE, TRUE);

	subtest("monitor all -> stop one -> monitor all");
	do_start(syscall, 0, 0);
	do_stop(syscall, -1, 0);
	do_start(syscall, 0, 0);
	do_stop(syscall, 0, 0);

	subtest("monitor one -> stop all");
	do_start(syscall, -1, 0);
	do_stop(syscall, 0, 0);

	subtest("monitor all -> stop one -> stop all");
	do_start(syscall, 0, 0);
	do_stop(syscall, -1, 0);
	do_stop(syscall, 0, 0);

	subtest("reset");
	do_start(syscall, -1, 0);
	test_monitor2(syscall, TRUE, FALSE);
	do_stop(syscall, 0, 0);
	test_monitor2(syscall, FALSE, FALSE);
	do_release(syscall, 0);
}
Exemplo n.º 29
0
static void do_action(int action, struct cardstate *cs,
		      struct bc_state *bcs,
		      struct at_state_t **p_at_state, char **pp_command,
		      int *p_genresp, int *p_resp_code,
		      struct event_t *ev)
{
	struct at_state_t *at_state = *p_at_state;
	struct bc_state *bcs2;
	unsigned long flags;

	int channel;

	unsigned char *s, *e;
	int i;
	unsigned long val;

	switch (action) {
	case ACT_NOTHING:
		break;
	case ACT_TIMEOUT:
		at_state->waiting = 1;
		break;
	case ACT_INIT:
		cs->at_state.pending_commands &= ~PC_INIT;
		cs->cur_at_seq = SEQ_NONE;
		cs->mode = M_UNIMODEM;
		spin_lock_irqsave(&cs->lock, flags);
		if (!cs->cidmode) {
			spin_unlock_irqrestore(&cs->lock, flags);
			gigaset_free_channels(cs);
			cs->mstate = MS_READY;
			break;
		}
		spin_unlock_irqrestore(&cs->lock, flags);
		cs->at_state.pending_commands |= PC_CIDMODE;
		gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE");
		cs->commands_pending = 1;
		break;
	case ACT_FAILINIT:
		dev_warn(cs->dev, "Could not initialize the device.\n");
		cs->dle = 0;
		init_failed(cs, M_UNKNOWN);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_CONFIGMODE:
		init_failed(cs, M_CONFIG);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_SETDLE1:
		cs->dle = 1;
		/* cs->inbuf[0].inputstate |= INS_command | INS_DLE_command; */
		cs->inbuf[0].inputstate &=
			~(INS_command | INS_DLE_command);
		break;
	case ACT_SETDLE0:
		cs->dle = 0;
		cs->inbuf[0].inputstate =
			(cs->inbuf[0].inputstate & ~INS_DLE_command)
			| INS_command;
		break;
	case ACT_CMODESET:
		if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
			gigaset_free_channels(cs);
			cs->mstate = MS_READY;
		}
		cs->mode = M_CID;
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_UMODESET:
		cs->mode = M_UNIMODEM;
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_FAILCMODE:
		cs->cur_at_seq = SEQ_NONE;
		if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
			init_failed(cs, M_UNKNOWN);
			break;
		}
		if (reinit_and_retry(cs, -1) < 0)
			schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILUMODE:
		cs->cur_at_seq = SEQ_NONE;
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_HUPMODEM:
		/* send "+++" (hangup in unimodem mode) */
		if (cs->connected) {
			struct cmdbuf_t *cb;

			cb = kmalloc(sizeof(struct cmdbuf_t) + 3, GFP_ATOMIC);
			if (!cb) {
				dev_err(cs->dev, "%s: out of memory\n",
					__func__);
				return;
			}
			memcpy(cb->buf, "+++", 3);
			cb->len = 3;
			cb->offset = 0;
			cb->next = NULL;
			cb->wake_tasklet = NULL;
			cs->ops->write_cmd(cs, cb);
		}
		break;
	case ACT_RING:
		/* get fresh AT state structure for new CID */
		at_state = get_free_channel(cs, ev->parameter);
		if (!at_state) {
			dev_warn(cs->dev,
				 "RING ignored: could not allocate channel structure\n");
			break;
		}

		/* initialize AT state structure
		 * note that bcs may be NULL if no B channel is free
		 */
		at_state->ConState = 700;
		for (i = 0; i < STR_NUM; ++i) {
			kfree(at_state->str_var[i]);
			at_state->str_var[i] = NULL;
		}
		at_state->int_var[VAR_ZCTP] = -1;

		spin_lock_irqsave(&cs->lock, flags);
		at_state->timer_expires = RING_TIMEOUT;
		at_state->timer_active = 1;
		spin_unlock_irqrestore(&cs->lock, flags);
		break;
	case ACT_ICALL:
		handle_icall(cs, bcs, at_state);
		break;
	case ACT_FAILSDOWN:
		dev_warn(cs->dev, "Could not shut down the device.\n");
		/* fall through */
	case ACT_FAKESDOWN:
	case ACT_SDOWN:
		cs->cur_at_seq = SEQ_NONE;
		finish_shutdown(cs);
		break;
	case ACT_CONNECT:
		if (cs->onechannel) {
			at_state->pending_commands |= PC_DLE1;
			cs->commands_pending = 1;
			break;
		}
		bcs->chstate |= CHS_D_UP;
		gigaset_isdn_connD(bcs);
		cs->ops->init_bchannel(bcs);
		break;
	case ACT_DLE1:
		cs->cur_at_seq = SEQ_NONE;
		bcs = cs->bcs + cs->curchannel;

		bcs->chstate |= CHS_D_UP;
		gigaset_isdn_connD(bcs);
		cs->ops->init_bchannel(bcs);
		break;
	case ACT_FAKEHUP:
		at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
		/* fall through */
	case ACT_DISCONNECT:
		cs->cur_at_seq = SEQ_NONE;
		at_state->cid = -1;
		if (!bcs) {
			disconnect_nobc(p_at_state, cs);
		} else if (cs->onechannel && cs->dle) {
			/* Check for other open channels not needed:
			 * DLE only used for M10x with one B channel.
			 */
			at_state->pending_commands |= PC_DLE0;
			cs->commands_pending = 1;
		} else {
			disconnect_bc(at_state, cs, bcs);
		}
		break;
	case ACT_FAKEDLE0:
		at_state->int_var[VAR_ZDLE] = 0;
		cs->dle = 0;
		/* fall through */
	case ACT_DLE0:
		cs->cur_at_seq = SEQ_NONE;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		break;
	case ACT_ABORTHUP:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev, "Could not hang up.\n");
		at_state->cid = -1;
		if (!bcs)
			disconnect_nobc(p_at_state, cs);
		else if (cs->onechannel)
			at_state->pending_commands |= PC_DLE0;
		else
			disconnect_bc(at_state, cs, bcs);
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILDLE0:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev, "Error leaving DLE mode.\n");
		cs->dle = 0;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILDLE1:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev,
			 "Could not enter DLE mode. Trying to hang up.\n");
		channel = cs->curchannel;
		cs->bcs[channel].at_state.pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;

	case ACT_CID: /* got cid; start dialing */
		cs->cur_at_seq = SEQ_NONE;
		channel = cs->curchannel;
		if (ev->parameter > 0 && ev->parameter <= 65535) {
			cs->bcs[channel].at_state.cid = ev->parameter;
			cs->bcs[channel].at_state.pending_commands |=
				PC_DIAL;
			cs->commands_pending = 1;
			break;
		}
		/* bad cid: fall through */
	case ACT_FAILCID:
		cs->cur_at_seq = SEQ_NONE;
		channel = cs->curchannel;
		if (reinit_and_retry(cs, channel) < 0) {
			dev_warn(cs->dev,
				 "Could not get a call ID. Cannot dial.\n");
			bcs2 = cs->bcs + channel;
			disconnect_bc(&bcs2->at_state, cs, bcs2);
		}
		break;
	case ACT_ABORTCID:
		cs->cur_at_seq = SEQ_NONE;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		break;

	case ACT_DIALING:
	case ACT_ACCEPTED:
		cs->cur_at_seq = SEQ_NONE;
		break;

	case ACT_ABORTACCEPT:	/* hangup/error/timeout during ICALL procssng */
		if (bcs)
			disconnect_bc(at_state, cs, bcs);
		else
			disconnect_nobc(p_at_state, cs);
		break;

	case ACT_ABORTDIAL:	/* error/timeout during dial preparation */
		cs->cur_at_seq = SEQ_NONE;
		at_state->pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;

	case ACT_REMOTEREJECT:	/* DISCONNECT_IND after dialling */
	case ACT_CONNTIMEOUT:	/* timeout waiting for ZSAU=ACTIVE */
	case ACT_REMOTEHUP:	/* DISCONNECT_IND with established connection */
		at_state->pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;
	case ACT_GETSTRING: /* warning: RING, ZDLE, ...
			       are not handled properly anymore */
		at_state->getstring = 1;
		break;
	case ACT_SETVER:
		if (!ev->ptr) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		s = ev->ptr;

		if (!strcmp(s, "OK")) {
			/* OK without version string: assume old response */
			*p_genresp = 1;
			*p_resp_code = RSP_NONE;
			break;
		}

		for (i = 0; i < 4; ++i) {
			val = simple_strtoul(s, (char **) &e, 10);
			if (val > INT_MAX || e == s)
				break;
			if (i == 3) {
				if (*e)
					break;
			} else if (*e != '.')
				break;
			else
				s = e + 1;
			cs->fwver[i] = val;
		}
		if (i != 4) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		cs->gotfwver = 0;
		break;
	case ACT_GOTVER:
		if (cs->gotfwver == 0) {
			cs->gotfwver = 1;
			gig_dbg(DEBUG_EVENT,
				"firmware version %02d.%03d.%02d.%02d",
				cs->fwver[0], cs->fwver[1],
				cs->fwver[2], cs->fwver[3]);
			break;
		}
		/* fall through */
	case ACT_FAILVER:
		cs->gotfwver = -1;
		dev_err(cs->dev, "could not read firmware version.\n");
		break;
	case ACT_ERROR:
		gig_dbg(DEBUG_ANY, "%s: ERROR response in ConState %d",
			__func__, at_state->ConState);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_DEBUG:
		gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d",
			__func__, ev->type, at_state->ConState);
		break;
	case ACT_WARN:
		dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n",
			 __func__, ev->type, at_state->ConState);
		break;
	case ACT_ZCAU:
		dev_warn(cs->dev, "cause code %04x in connection state %d.\n",
			 ev->parameter, at_state->ConState);
		break;

	/* events from the LL */

	case ACT_DIAL:
		if (!ev->ptr) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		start_dial(at_state, ev->ptr, ev->parameter);
		break;
	case ACT_ACCEPT:
		start_accept(at_state);
		break;
	case ACT_HUP:
		at_state->pending_commands |= PC_HUP;
		gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP");
		cs->commands_pending = 1;
		break;

	/* hotplug events */

	case ACT_STOP:
		do_stop(cs);
		break;
	case ACT_START:
		do_start(cs);
		break;

	/* events from the interface */

	case ACT_IF_LOCK:
		cs->cmd_result = ev->parameter ? do_lock(cs) : do_unlock(cs);
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;
	case ACT_IF_VER:
		if (ev->parameter != 0)
			cs->cmd_result = -EINVAL;
		else if (cs->gotfwver != 1) {
			cs->cmd_result = -ENOENT;
		} else {
			memcpy(ev->arg, cs->fwver, sizeof cs->fwver);
			cs->cmd_result = 0;
		}
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;

	/* events from the proc file system */

	case ACT_PROC_CIDMODE:
		spin_lock_irqsave(&cs->lock, flags);
		if (ev->parameter != cs->cidmode) {
			cs->cidmode = ev->parameter;
			if (ev->parameter) {
				cs->at_state.pending_commands |= PC_CIDMODE;
				gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE");
			} else {
				cs->at_state.pending_commands |= PC_UMMODE;
				gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE");
			}
			cs->commands_pending = 1;
		}
		spin_unlock_irqrestore(&cs->lock, flags);
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;

	/* events from the hardware drivers */

	case ACT_NOTIFY_BC_DOWN:
		bchannel_down(bcs);
		break;
	case ACT_NOTIFY_BC_UP:
		bchannel_up(bcs);
		break;
	case ACT_SHUTDOWN:
		do_shutdown(cs);
		break;


	default:
		if (action >= ACT_CMD && action < ACT_CMD + AT_NUM) {
			*pp_command = at_state->bcs->commands[action - ACT_CMD];
			if (!*pp_command) {
				*p_genresp = 1;
				*p_resp_code = RSP_NULL;
			}
		} else
			dev_err(cs->dev, "%s: action==%d!\n", __func__, action);
	}
}
Exemplo n.º 30
0
static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
{
	int sd;
	struct init_request rq;

	sd = accept(w->fd, NULL, NULL);
	if (sd < 0) {
		_pe("Failed serving API request");
		return;
	}

	while (1) {
		int result = 0;
		ssize_t len;

		len = read(sd, &rq, sizeof(rq));
		if (len <= 0) {
			if (-1 == len) {
				if (EINTR == errno)
					continue;

				if (EAGAIN == errno)
					break;

				_e("Failed reading initctl request, error %d: %s", errno, strerror(errno));
			}

			break;
		}

		if (rq.magic != INIT_MAGIC || len != sizeof(rq)) {
			_e("Invalid initctl request.");
			break;
		}

		switch (rq.cmd) {
		case INIT_CMD_RUNLVL:
			switch (rq.runlevel) {
			case '0':
				_d("Halting system (SIGUSR2)");
				do_shutdown(SIGUSR2);
				break;

			case 's':
			case 'S':
				_d("Cannot enter bootstrap after boot ...");
				rq.runlevel = '1';
				/* Fall through to regular processing */

			case '1'...'5':
			case '7'...'9':
				_d("Setting new runlevel %c", rq.runlevel);
				service_runlevel(rq.runlevel - '0');
				break;

			case '6':
				_d("Rebooting system (SIGUSR1)");
				do_shutdown(SIGUSR1);
				break;

			default:
				_d("Unsupported runlevel: %d", rq.runlevel);
				break;
			}
			break;

		case INIT_CMD_DEBUG:
			debug = !debug;
			if (debug)
				silent = 0;
			else
				silent = quiet ? 1 : SILENT_MODE;
			break;

		case INIT_CMD_RELOAD: /* 'init q' and 'initctl reload' */
			service_reload_dynamic();
			break;

		case INIT_CMD_START_SVC:
			result = do_start(rq.data, sizeof(rq.data));
			break;

		case INIT_CMD_STOP_SVC:
			result = do_pause(rq.data, sizeof(rq.data));
			break;

		case INIT_CMD_RESTART_SVC:
			result = do_restart(rq.data, sizeof(rq.data));
			break;

#ifndef INETD_DISABLED
		case INIT_CMD_QUERY_INETD:
			result = do_query_inetd(rq.data, sizeof(rq.data));
			break;
#endif

		case INIT_CMD_EMIT:
			result = do_handle_emit(rq.data, sizeof(rq.data));
			break;

		case INIT_CMD_GET_RUNLEVEL:
			rq.runlevel = runlevel;
			result = 0;
			break;

		case INIT_CMD_ACK:
			_d("Client failed reading ACK.");
			goto leave;

		default:
			_d("Unsupported cmd: %d", rq.cmd);
			break;
		}

		if (result)
			rq.cmd = INIT_CMD_NACK;
		else
			rq.cmd = INIT_CMD_ACK;
		len = write(sd, &rq, sizeof(rq));
		if (len != sizeof(rq))
			_d("Failed sending ACK/NACK back to client.");
	}

leave:
	close(sd);
}