コード例 #1
0
cf_void SetProcessDaemon()
{
    cf_int i,fd0,fd1,fd2;
    pid_t pid;
    struct rlimit rl;

    cf_umask(0);
    if(cf_getrlimit(RLIMIT_NOFILE,&rl)<0)
    {
        printf("Can't get file limit! errno=%d.file:%s,function:%s,line:%d.\n",
               cf_int(errno),__FILE__,__PRETTY_FUNCTION__,__LINE__);
        cf_exit(1);
    }
    if ((pid=cf_fork())<0)
    {
        printf("Can't fork! errno=%d.file:%s,function:%s,line:%d.\n",cf_int(errno),
               __FILE__,__PRETTY_FUNCTION__,__LINE__);
        cf_exit(1);
    }
    else if(pid != 0) // parent will exit normally.
    {
        cf_exit(0);
    }

    cf_setsid();

    if ((pid=cf_fork())<0)
    {
        printf("Can't fork!! errno=%d.file:%s,function:%s,line:%d.\n",cf_int(errno),
               __FILE__,__PRETTY_FUNCTION__,__LINE__);
        exit(1);
    }
    else if (pid!=0)
    {
        cf_exit(0);
    }

    if (cf_chdir("/tmp")<0)
    {
        printf("Can't change directory to /tmp! errno=%d.file:%s,function:%s,line:%d.\n",
               cf_int(errno),__FILE__,__PRETTY_FUNCTION__,__LINE__);
        cf_exit(1);
    }

    if (rl.rlim_max == RLIM_INFINITY)
        rl.rlim_max =1024;
    for (i=0; i < cf_int(rl.rlim_max); i++)
        cf_close(i);

    fd0 =cf_open("/dev/null",O_RDWR,0);
    fd1 =cf_dup(0);
    fd2 =cf_dup(0);
}
コード例 #2
0
ファイル: config.c プロジェクト: lackofentropy/isolate
void cf_entry(char *key, char *val)
{
  if (!strcmp(key, "box_root"))
    cf_box_root = cf_string(val);
  else if (!strcmp(key, "cg_root"))
    cf_cg_root = cf_string(val);
  else if (!strcmp(key, "first_uid"))
    cf_first_uid = cf_int(val);
  else if (!strcmp(key, "first_gid"))
    cf_first_gid = cf_int(val);
  else if (!strcmp(key, "num_boxes"))
    cf_num_boxes = cf_int(val);
  else
    cf_err("Unknown configuration item");
}
コード例 #3
0
ファイル: encoding.c プロジェクト: rgburke/wed
static void en_ascii_char_info(CharInfo *char_info, CharInfoProperties cip,
                               const BufferPos *pos, const HashMap *config,
                               uchar c)
{
    assert(c < 128);

    char_info->is_valid = 1;
    char_info->byte_length = 1;

    if (cip & CIP_SCREEN_LENGTH) {
        char_info->is_printable = 1;

        if (c == '\n') {
            char_info->screen_length = 0;
        } else if (c == '\r' &&
                   *pos->file_format == FF_WINDOWS &&
                   gb_get_at(pos->data, pos->offset + 1) == '\n') {
            char_info->screen_length = 0;
        } else if (c == '\t') {
            size_t tabwidth = cf_int(config, CV_TABWIDTH);
            char_info->screen_length =
                tabwidth - ((pos->col_no - 1) % tabwidth);
        } else if (c < 32 || c == 127) {
            char_info->screen_length = 2;
            char_info->is_printable = 0;
        } else {
            char_info->screen_length = 1;
        }
    }
}
コード例 #4
0
static void
cf_entry_compound(char *key, char *subkey, char *val)
{
  if (strncmp(key, "box", 3))
    cf_err("Unknown configuration section");
  int box_id = cf_int(key + 3);
  struct cf_per_box *c = cf_per_box(box_id);

  if (!strcmp(subkey, "cpus"))
    c->cpus = cf_string(val);
  else if (!strcmp(subkey, "mems"))
    c->mems = cf_string(val);
  else
    cf_err("Unknown per-box configuration item");
}