/* * the following function is for client, * server/daemon process shouldn't call it. * Because this function may read incorrect setting from user specified * $USER or $HOME. */ gfarm_error_t gfarm_config_read(void) { gfarm_error_t e; char *home; FILE *config; int lineno, user_config_errno, rc_need_free;; static char gfarm_client_rc[] = GFARM_CLIENT_RC; char *rc; rc_need_free = 0; rc = getenv("GFARM_CONFIG_FILE"); if (rc == NULL) { /* * result of gfarm_get_local_homedir() should not be trusted. * (maybe forged) */ home = gfarm_get_local_homedir(); GFARM_MALLOC_ARRAY(rc, strlen(home) + 1 + sizeof(gfarm_client_rc)); if (rc == NULL) return (GFARM_ERR_NO_MEMORY); sprintf(rc, "%s/%s", home, gfarm_client_rc); rc_need_free = 1; } gfarm_init_user_map(); if ((config = fopen(rc, "r")) == NULL) { user_config_errno = errno; } else { user_config_errno = 0; e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error("%s: %d: %s", rc, lineno, gfarm_error_string(e)); if (rc_need_free) free(rc); return (e); } } if (rc_need_free) free(rc); if ((config = fopen(gfarm_config_file, "r")) == NULL) { if (user_config_errno != 0) return (GFARM_ERRMSG_CANNOT_OPEN_CONFIG); } else { e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error("%s: %d: %s", gfarm_config_file, lineno, gfarm_error_string(e)); return (e); } } gfarm_config_set_default_ports(); gfarm_config_set_default_misc(); return (GFARM_ERR_NO_ERROR); }
/* the following function is for server. */ gfarm_error_t gfarm_server_config_read(void) { gfarm_error_t e; int lineno; FILE *config; char *config_file = gfarm_config_get_filename(); gfarm_init_config(); if ((config = fopen(config_file, "r")) == NULL) { gflog_debug(GFARM_MSG_1000976, "open operation on server config file (%s) failed", config_file); return (GFARM_ERRMSG_CANNOT_OPEN_CONFIG); } e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_1000014, "%s: line %d: %s", config_file, lineno, gfarm_error_string(e)); return (e); } gfarm_config_set_default_ports(); gfarm_config_set_default_misc(); return (GFARM_ERR_NO_ERROR); }