int main (int argc, char *argv[]) { glusterfs_ctx_t *ctx = NULL; int ret = -1; ret = glusterfs_globals_init (); if (ret) return ret; ctx = glusterfs_ctx_get (); if (!ctx) return ENOMEM; ret = glusterfs_ctx_defaults_init (ctx); if (ret) goto out; ret = parse_cmdline (argc, argv, ctx); if (ret) goto out; ret = logging_init (ctx); if (ret) goto out; gf_proc_dump_init(); ret = create_fuse_mount (ctx); if (ret) goto out; ret = daemonize (ctx); if (ret) goto out; ret = glusterfs_volumes_init (ctx); if (ret) goto out; ret = event_dispatch (ctx->event_pool); out: // glusterfs_ctx_destroy (ctx); return ret; }
static int logging_init (void) { glusterfs_ctx_t *ctx; char log_file[PATH_MAX]; int ret = -1; ctx = glusterfs_ctx_new (); if (!ctx) { fprintf (stderr, "glusterfs_ctx_new failed\n"); goto out; } ret = glusterfs_globals_init (ctx); if (ret) { fprintf (stderr, "glusterfs_globals_init failed\n"); goto out; } THIS->ctx = ctx; xlator_mem_acct_init (THIS, gf_common_mt_end); snprintf (log_file, PATH_MAX, "%s/umountd.log", DEFAULT_LOG_FILE_DIRECTORY); ret = gf_log_init (ctx, log_file, "umountd"); if (ret) { fprintf (stderr, "gf_log_init failed\n"); goto out; } if (signal (SIGHUP, *log_rotate) == SIG_ERR) { gf_log ("umountd", GF_LOG_ERROR, "signal () failed"); goto out; } ret = 0; out: return ret; }
int main (int argc, char **argv) { int ret = -1; char *evas = NULL; struct invocable *i = NULL; char *b = NULL; char *sargv = NULL; #ifdef USE_LIBGLUSTERFS glusterfs_ctx_t *ctx = NULL; ctx = glusterfs_ctx_new (); if (!ctx) return ENOMEM; if (glusterfs_globals_init (ctx)) return 1; THIS->ctx = ctx; ret = default_mem_acct_init (THIS); if (ret) { fprintf (stderr, "internal error: mem accounting failed\n"); return 1; } #endif evas = getenv (_GLUSTERD_CALLED_); if (evas && strcmp (evas, "1") == 0) /* OK, we know glusterd called us, no need to look for further config *...although this conclusion should not inherit to our children */ unsetenv (_GLUSTERD_CALLED_); else { /* we regard all gsyncd invocations unsafe * that do not come from glusterd and * therefore restrict it */ restricted = 1; if (!getenv (_GSYNCD_DISPATCHED_)) { evas = getenv ("SSH_ORIGINAL_COMMAND"); if (evas) sargv = evas; else { evas = getenv ("SHELL"); if (evas && strcmp (basename (evas), "gsyncd") == 0 && argc == 3 && strcmp (argv[1], "-c") == 0) sargv = argv[2]; } } } if (!(sargv && restricted)) return invoke_gsyncd (argc, argv); argc = str2argv (sargv, &argv); if (argc == -1 || setenv (_GSYNCD_DISPATCHED_, "1", 1) == -1) { fprintf (stderr, "internal error\n"); return 1; } b = basename (argv[0]); for (i = invocables; i->name; i++) { if (strcmp (b, i->name) == 0) return i->invoker (argc, argv); } fprintf (stderr, "invoking %s in restricted SSH session is not allowed\n", b); free(argv); return 1; }