Example #1
0
void usage()
{
   mini_printf("gpm2-daemon: written by Nico Schottelius\n",1);
   mini_printf("\n",1);
   mini_printf("  -c <cconfig>: specify configuration directory\n",1);
   mini_printf("  -f:           fork into background after startup \n",1);
}
Example #2
0
void usage(char *banner, char *text)
{
    /*
     * print banner + error message
     */
    mini_printf(banner, 1);
    mini_printf(text, 1);
    _exit(1);
}
Example #3
0
void print_errno(char *msg)
{
    if(msg) {
        mini_printf(msg, FD_ERR);
        mini_printf(": ", FD_ERR);
    }
    mini_printf(strerror(errno), FD_ERR);
    mini_printf("\n", FD_ERR);
}
Example #4
0
void expand_param(running_machine &machine, int params, const char **param, char *outBuf){
    UINT64 values[MAX_COMMAND_PARAMS];
    for (int i = 1; i < params; i++) {
        if (!debug_command_parameter_number(machine, param[i], &values[i])) {
            return;
        }
    }
    mini_printf(machine, outBuf, param[0], params - 1, &values[1]);
}
/***********************************************************************
 * create a socket, when we recieved a signal
 */
int main(int argc, char **argv)
{
   struct sockaddr_un addr;
   struct pollfd plist;
   char  *initdir;

   list = NULL;            /* list of services is empty currently */
   initdir = CINIT_INIT;   /* default init dir */

   cpid = getpid();
   if(cpid != 1) {
      usage(MSG_USAGE,MSG_NOT_ONE);
   }

   set_signals(ACT_SERV);  /* set signal handlers */

   /* read args, profile support */
   while(argc > 1) {
      if( !strncmp(PROFILE, argv[argc-1], strlen(PROFILE)) ) {
         initdir = (char *) malloc(
                              strlen(CINIT_DIR) +
                              strlen(&argv[argc-1][strlen(PROFILE)]) + 2
                              );
         if(initdir == NULL) {
            panic();
         }
         strcpy(initdir,CINIT_DIR);
         strcat(initdir,SLASH);
         strcat(initdir,&argv[argc-1][strlen(PROFILE)]);
         break;
      }
      argc--;
   }

   /* tell the world we are there FIXME: do we really need three calls? */
   mini_printf(MSG_CINIT,1); mini_printf(initdir,1); mini_printf("\n",1);

   if( chdir(CINIT_INIT) == -1) {
      perror(MSG_CHDIR);
      panic();
   }

   /******************** TMPDIR  **********************/
   if( mount(C_TMPMOUNT,CINIT_TMNT,C_TMPFS,0,NULL) == -1 ) {
      perror(MSG_ERR_MOUNT);
      panic();
   }

   /******************** begin socket **********************/
   sock = socket(AF_UNIX,SOCK_STREAM,0); /* create socket */
   if( sock == -1 ) {
      perror(MSG_SOCKET);
      panic();
   }
   
   memset(&addr, 0, sizeof(addr) ); /* clear addr */
   strcpy(addr.sun_path, CINIT_SOCK);
   addr.sun_family = AF_UNIX;
   
   if(bind(sock,(struct sockaddr *)&addr,sizeof(addr)) == -1) {
      perror(MSG_BIND);
      panic();
   }
   
   /* start listening */
   if(listen(sock,SOCK_QUEUE) == -1) {
      perror(MSG_LISTEN);
      panic();
   }
   
   /* start init or profile */
   run_init_svc(initdir);
   
   /* free, if we malloc()ed before */
   if(initdir != CINIT_INIT) {
      free(initdir);
   }

   /* our life is polling a socket */
   plist.fd = sock;
   plist.events = POLLIN | POLLPRI;
   while(1) {
      if(poll(&plist, 1, -1) != -1) {
         if( (plist.revents & POLLIN)  == POLLIN ||
             (plist.revents & POLLPRI) == POLLPRI) {
            sigio(sock);
         }
      }
   }
}
Example #6
0
int main(int argc, char **argv)
{
   char *initdir = CINIT_INIT;  /* default init dir */

   /*
    * Is this really needed? pid_t cpid;
    * 
    * if(cpid != 1) { mini_printf(CINIT_VERSION,2); mini_printf(MSG_USAGE,2);
    * return 0; }
    */

   /* Bootup "logo" */
   mini_printf(MSG_BOOTING, 1); mini_printf(initdir, 1); mini_printf("\n", 1);

   /* Should we start a profile? */
   while(argc > 1) {
      if(!strncmp(PROFILE, argv[argc - 1], strlen(PROFILE))) {
         initdir = malloc(strlen(CINIT_SVCDIR) +
                          strlen(&argv[argc - 1][strlen(PROFILE)]) + 2);
         if(initdir == NULL) {
            panic();
         }
         strcpy(initdir, CINIT_SVCDIR);
         strcat(initdir, SLASH);
         strcat(initdir, &argv[argc - 1][strlen(PROFILE)]);
         break;
      }
      --argc;
   }

   /* no configuration? - panic! */
   if(chdir(initdir) == -1) {
      print_errno(initdir);
      panic();
   }

   /* initialize communication (IPC) */
   if(!cinit_ipc_init()) panic();

   /* Init signal handler */
   signal_init_map(sigstages, cinit_global_signals);
   set_signals(SIGSTAGE_DAEMON);

   /* build service dependency tree */
   if(!gen_svc_tree(initdir)) panic();

   /* unused now, free if allocated */
   if(strcmp(initdir, CINIT_INIT)) free(initdir);

   /* FIXME: what todo?
    * change to /, so applications have that as cwd, too Is that really
    * seneful? Does that help any application? If not, just for looking nice,
    * that's not a reason to enable it. if(chdir(SLASH) == -1) {
    * print_errno(SLASH); panic(); } 
    */

   /* the main startup routine */
   if(!tree_exec(deps_pending)) panic();

   /* listen to commands after startup */
   while(1) {
      /* react on service changes (=process exited) */
      if(svc_exited) svc_status_changed(deps_pending);

      /* handle the changes */
      if(deps_pending) svc_handle_pending(deps_pending);

      /* listen until we get a message or get interrupted */
      cinit_ipc_listen();

      /*
       * check dependency list: perhaps we need to restart something 
       */
      /*
       * implement in cinit-0.3pre14/5 
       */

      // tree_exec(deps_pending);
      // reuse tree_exec()?
      // if(dep) { svc_start() .. ?
   }

   return 0;
}
Example #7
0
File: main.c Project: telmich/cinit
int main(int argc, char **argv)
{
   char *initdir;
   key_t msg_key;
   int msq_id;

   initdir = CINIT_INIT;        /* default init dir */
   list = NULL;                 /* list of services is empty currently */
   cpid = getpid();             /* no comment */

   if(cpid != 1) {
      usage(CINIT_VERSION, MSG_USAGE);
   }

   /*
    * set signal handlers 
    */
   set_signals(ACT_SERV);

   /*
    * read arguments, profile support 
    */
   while(argc > 1) {
      if(!strncmp(PROFILE, argv[argc - 1], strlen(PROFILE))) {
         initdir = (char *) malloc(strlen(CINIT_DIR) +
                                   strlen(&argv[argc - 1][strlen(PROFILE)]) +
                                   2);
         if(initdir == NULL) {
            panic();
         }
         strcpy(initdir, CINIT_DIR);
         strcat(initdir, SLASH);
         strcat(initdir, &argv[argc - 1][strlen(PROFILE)]);
         break;
      }
      argc--;
   }

   /*
    * tell the world we are there FIXME: do we really need three calls? 
    */
   mini_printf(MSG_BOOTING, 1);
   mini_printf(initdir, 1);
   mini_printf("\n", 1);

   if(chdir(CINIT_INIT) == -1) {
      perror(MSG_CHDIR);
      panic();
   }

   /*
    * create message queues 
    */

   /*
    * start init or profile 
    */
   run_init_svc(initdir);

   /*
    * free, if we malloc()ed before 
    */
   if(initdir != CINIT_INIT) {
      free(initdir);
   }

   /*
    * wait until we recieved the signal to create the socket 
    */

   /*
    * our life is polling a socket 
    */
   plist.fd = sock;
   plist.events = POLLIN | POLLPRI;
   while(1) {
      if(poll(&plist, 1, -1) != -1) {
         if((plist.revents & POLLIN) == POLLIN ||
            (plist.revents & POLLPRI) == POLLPRI) {
            sigio(sock);
         }
      }
   }
}