int my_fstat(int type, int fd, void *buf) { log_msg(MOD_MSG "fstat\n"); plash_libc_lock(); if(0 <= fd && fd < g_fds_size && g_fds[fd].fd_dir_obj) { /* Handle directory FDs specially: send a message. */ cap_t dir_obj = g_fds[fd].fd_dir_obj; region_t r = region_make(); cap_t fs_op_server; struct cap_args result; int rc = -1; log_fd(fd, "fstat on directory"); if(!buf) { __set_errno(EINVAL); goto exit; } if(libc_get_fs_op(&fs_op_server) < 0) goto exit; cap_call(fs_op_server, r, cap_args_dc(mk_int(r, METHOD_FSOP_DIR_FSTAT), mk_caps1(r, inc_ref(dir_obj))), &result); { seqf_t msg = flatten_reuse(r, result.data); int ok = 1; m_int_const(&ok, &msg, METHOD_R_FSOP_STAT); m_stat_info(&ok, &msg, type, buf); m_end(&ok, &msg); if(ok && result.fds.count == 0 && result.caps.size == 0) { rc = 0; goto exit; } } pl_args_free(&result); set_errno_from_reply(flatten_reuse(r, result.data)); exit: plash_libc_unlock(); region_free(r); return rc; } else { plash_libc_unlock(); /* Use the normal fstat system call. */ log_fd(fd, "normal fstat"); if(type == TYPE_STAT) { return kernel_fxstat(_STAT_VER, fd, (struct stat *) buf); } else if(type == TYPE_STAT64) { return kernel_fxstat64(_STAT_VER, fd, (struct stat64 *) buf); } else { /* Don't recognise ABI version requested. */ __set_errno(ENOSYS); return -1; } } }
void log_preamble(Config_t *cfg) { time_t t = get_starttime(); log_printf(0, "\n"); log_printf(0, "*****************************************************************\n"); log_printf(0, "Starting ibp_server on %s", ctime(&t)); log_printf(0, "*****************************************************************\n"); log_printf(0, "\n"); log_printf(0, "*********************Printing configuration file **********************\n\n"); print_config(log_fd(), cfg); log_printf(0, "*****************************************************************\n\n"); }
int main(int argc, char *argv[]) { signal(SIGCHLD, signal_sigchld); signal(SIGINT, signal_sigint); signal(SIGPIPE, signal_sigint); signal(SIGTERM, signal_sigint); signal(SIGTSTP, signal_sigint); signal(SIGHUP, signal_sigint); log_level(_LOG_DEBUG); log_msg("Start zoodis."); zoodis.keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; zoodis.zoo_stat = ZOO_STAT_NOT_CONNECTED; zoodis.zoo_timeout = DEFAULT_ZOO_TIMEOUT; zoodis.zoo_connect_wait_interval = DEFAULT_ZOO_CONNECT_WAIT_INTERVAL; zoodis.redis_port = DEFAULT_REDIS_PORT; zoodis.redis_ping_interval = DEFAULT_REDIS_PING_INTERVAL; zoodis.redis_pong_timeout_sec = DEFAULT_REDIS_PONG_TIMEOUT_SEC; zoodis.redis_pong_timeout_usec = DEFAULT_REDIS_PONG_TIMEOUT_USEC; zoodis.redis_max_fail_count = DEFAULT_REDIS_MAX_FAIL_COUNT; zoodis.pid_file = NULL; zoodis.redis_stat = REDIS_STAT_NONE; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {"log-level", required_argument, 0, 'l'}, {"pid-file", required_argument, 0, 'f'}, {"keepalive", no_argument, 0, 'k'}, {"keepalive-interval", required_argument, 0, 'i'}, {"redis-bin", required_argument, 0, 'b'}, {"redis-conf", required_argument, 0, 'c'}, {"redis-port", required_argument, 0, 'r'}, {"redis-ping-interval", required_argument, 0, 's'}, {"zoo-host", required_argument, 0, 'z'}, {"zoo-path", required_argument, 0, 'p'}, {"zoo-nodename", required_argument, 0, 'n'}, {"zoo-nodedata", required_argument, 0, 'd'}, {"zoo-timeout", required_argument, 0, 't'}, {0, 0, 0, 0} }; enum zoo_res zres; if(argc < 3) print_help(argv); while (1) { /* getopt_long stores the option index here. */ int option_index = 0; int opt; opt = getopt_long_only(argc, argv, "", long_options, &option_index); /* Detect the end of the options. */ if (opt == -1) break; switch (opt) { case 'h': print_help(argv); break; case 'v': print_version(argv); break; case 'l': set_logging(optarg); break; case 'k': zoodis.keepalive = 1; break; case 'f': zoodis.pid_file = check_pid_file(optarg); case 'i': zoodis.keepalive_interval = check_option_int(optarg, DEFAULT_KEEPALIVE_INTERVAL); break; case 'b': zoodis.redis_bin = check_redis_bin(optarg); break; case 'c': zoodis.redis_conf = check_redis_conf(optarg); break; case 'r': zoodis.redis_port = check_option_int(optarg, DEFAULT_REDIS_PORT); break; case 's': zoodis.redis_ping_interval = check_option_int(optarg, DEFAULT_REDIS_PING_INTERVAL); break; case 'z': zoodis.zoo_host = check_zoo_host(optarg); break; case 'p': zoodis.zoo_path = check_zoo_path(optarg); break; case 'n': zoodis.zoo_nodename = check_zoo_nodename(optarg); break; case 'd': zoodis.zoo_nodedata = check_zoo_nodedata(optarg); break; case 't': zoodis.zoo_timeout = check_option_int(optarg, DEFAULT_ZOO_TIMEOUT); break; default: exit_proc(-1); } } zoodis.zookeeper = check_zoo_options(&zoodis); if(zoodis.zoo_nodedata == NULL) zoodis.zoo_nodedata = mstr_alloc_dup(DEFAULT_ZOO_NODEDATA, strlen(DEFAULT_ZOO_NODEDATA)); check_redis_options(&zoodis); if(zoodis.zookeeper) { zoodis.zoo_nodepath = mstr_concat(3, zoodis.zoo_path->data, "/", zoodis.zoo_nodename->data); zu_set_log_level(log_level(0)); zu_set_log_stream(log_fd(stdout)); zres = zu_connect(&zoodis); if(zres != ZOO_RES_OK) { exit_proc(-1); } } // sleep(1); // while(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // if(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // { // log_warn("Zookeeper: is not connected yet."); // sleep(zoodis.zoo_connect_wait_interval); // } exec_redis(); redis_health(); return 0; }