static void setup() { client = ccnet_client_new (); if ( ccnet_client_load_confdir(client, CCNET_DIR) < 0 ) { fprintf (stderr, "Read config dir error\n"); exit(1); } event_init (); if (g_access (TEST_DIR "worktree", F_OK) != 0 && g_mkdir (TEST_DIR "worktree", 0777) < 0) { fprintf (stderr, "Failed to create worktree.\n"); exit (1); } seaf = seafile_session_new (SEAF_DIR, WORKTREE_DIR, client); if (!seaf) { fprintf (stderr, "Failed to create seafile session.\n"); exit (1); } seafile_session_prepare (seaf); }
int main (int argc, char **argv) { int c; char *config_dir = DEFAULT_CONFIG_DIR; char *seafile_dir = NULL; char *worktree_dir = NULL; char *logfile = NULL; const char *debug_str = NULL; int daemon_mode = 0; CcnetClient *client; char *ccnet_debug_level_str = "info"; char *seafile_debug_level_str = "debug"; #ifdef WIN32 argv = get_argv_utf8 (&argc); #endif while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != EOF) { switch (c) { case 'h': exit (1); break; case 'v': exit (1); break; case 'c': config_dir = optarg; break; case 'd': seafile_dir = g_strdup(optarg); break; case 'b': daemon_mode = 1; break; case 'D': debug_str = optarg; break; case 'w': worktree_dir = g_strdup(optarg); break; case 'l': logfile = g_strdup(optarg); break; case 'g': ccnet_debug_level_str = optarg; break; case 'G': seafile_debug_level_str = optarg; break; default: usage (); exit (1); } } argc -= optind; argv += optind; #ifndef WIN32 #ifndef __APPLE__ if (daemon_mode) daemon (1, 0); #endif #endif g_type_init (); #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init (NULL); #endif if (!debug_str) debug_str = g_getenv("SEAFILE_DEBUG"); seafile_debug_set_flags_string (debug_str); /* init ccnet */ client = ccnet_init (config_dir); if (!client) exit (1); register_processors (client); start_rpc_service (client); create_sync_rpc_clients (config_dir); appletrpc_client = ccnet_create_async_rpc_client (client, NULL, "applet-rpcserver"); /* init seafile */ if (seafile_dir == NULL) seafile_dir = g_build_filename (config_dir, "seafile-data", NULL); if (worktree_dir == NULL) worktree_dir = g_build_filename (g_get_home_dir(), "seafile", NULL); if (logfile == NULL) logfile = g_build_filename (config_dir, "logs", "seafile.log", NULL); seaf = seafile_session_new (seafile_dir, worktree_dir, client); if (!seaf) { fprintf (stderr, "Failed to create seafile session.\n"); exit (1); } seaf->ccnetrpc_client = ccnetrpc_client; seaf->appletrpc_client = appletrpc_client; if (seafile_log_init (logfile, ccnet_debug_level_str, seafile_debug_level_str) < 0) { fprintf (stderr, "Failed to init log.\n"); exit (1); } g_free (seafile_dir); g_free (worktree_dir); g_free (logfile); set_signal_handlers (seaf); seafile_session_prepare (seaf); seafile_session_start (seaf); seafile_session_config_set_string (seaf, "wktree", seaf->worktree_dir); ccnet_main (client); return 0; }
int main (int argc, char **argv) { int c; char *config_dir = DEFAULT_CONFIG_DIR; char *seafile_dir = NULL; char *worktree_dir = NULL; char *logfile = NULL; const char *debug_str = NULL; int daemon_mode = 0; CcnetClient *client; char *ccnet_debug_level_str = "info"; char *seafile_debug_level_str = "debug"; #ifdef WIN32 LoadLibraryA ("exchndl.dll"); argv = get_argv_utf8 (&argc); #endif while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != EOF) { switch (c) { case 'h': usage(); exit (1); break; case 'v': exit (1); break; case 'c': config_dir = optarg; break; case 'd': seafile_dir = g_strdup(optarg); break; case 'b': daemon_mode = 1; break; case 'D': debug_str = optarg; break; case 'w': worktree_dir = g_strdup(optarg); break; case 'l': logfile = g_strdup(optarg); break; case 'g': ccnet_debug_level_str = optarg; break; case 'G': seafile_debug_level_str = optarg; break; default: usage (); exit (1); } } argc -= optind; argv += optind; #ifndef WIN32 if (daemon_mode) { #ifndef __APPLE__ daemon (1, 0); #else /* __APPLE */ /* daemon is deprecated under APPLE * use fork() instead * */ switch (fork ()) { case -1: seaf_warning ("Failed to daemonize"); exit (-1); break; case 0: /* all good*/ break; default: /* kill origin process */ exit (0); } #endif /* __APPLE */ } #endif /* !WIN32 */ cdc_init (); #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif #if !GLIB_CHECK_VERSION(2, 31, 0) g_thread_init(NULL); #endif if (!debug_str) debug_str = g_getenv("SEAFILE_DEBUG"); seafile_debug_set_flags_string (debug_str); if (logfile == NULL) logfile = g_build_filename (config_dir, "logs", "seafile.log", NULL); if (seafile_log_init (logfile, ccnet_debug_level_str, seafile_debug_level_str) < 0) { seaf_warning ("Failed to init log.\n"); exit (1); } if (!bind_ccnet_service (config_dir)) { seaf_warning ("Failed to bind ccnet service\n"); exit (1); } /* init ccnet */ client = ccnet_init (config_dir); if (!client) exit (1); start_rpc_service (client); create_sync_rpc_clients (config_dir); appletrpc_client = ccnet_create_async_rpc_client (client, NULL, "applet-rpcserver"); /* init seafile */ if (seafile_dir == NULL) seafile_dir = g_build_filename (config_dir, "seafile-data", NULL); if (worktree_dir == NULL) worktree_dir = g_build_filename (g_get_home_dir(), "seafile", NULL); seaf = seafile_session_new (seafile_dir, worktree_dir, client); if (!seaf) { seaf_warning ("Failed to create seafile session.\n"); exit (1); } seaf->ccnetrpc_client = ccnetrpc_client; seaf->appletrpc_client = appletrpc_client; seaf_message ("starting seafile client "SEAFILE_CLIENT_VERSION"\n"); #if defined(SEAFILE_SOURCE_COMMIT_ID) seaf_message ("seafile source code version "SEAFILE_SOURCE_COMMIT_ID"\n"); #endif g_free (seafile_dir); g_free (worktree_dir); g_free (logfile); set_signal_handlers (seaf); seafile_session_prepare (seaf); seafile_session_start (seaf); seafile_session_config_set_string (seaf, "wktree", seaf->worktree_dir); ccnet_main (client); return 0; }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, "seafile"); if (argc == 1) { usage(); return 0; } if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Option parsing failed: %s\n", error->message); exit (1); } if (print_version) { show_version(); return 0; } if (!seaf_data_dir) { if (!ccnet_conf_dir) { ccnet_conf_dir = ccnet_expand_path(DEFAULT_CONFIG_DIR); if (!ccnet_conf_dir) { fprintf (stderr, "[ERROR] Failed to get ccnet conf dir\n"); return -1; } } seaf_data_dir = get_seaf_data_dir(ccnet_conf_dir); if (!seaf_data_dir) { fprintf (stderr, "[ERROR] Failed to get seafile data directory\n"); return -1; } if(!seaf_data_dir_is_valid()) { fprintf (stderr, "[ERROR] seafile data directory is not valid.\n"); return -1; } } printf ("[INFO] seafile data directory is %s\n", seaf_data_dir); g_type_init (); log_init(); if (!worktree_dir) worktree_dir = g_build_filename (g_get_home_dir(), "seafile", NULL); seaf = seafile_session_new(seaf_data_dir, worktree_dir, NULL); seafile_session_prepare(seaf); if (!seaf) { fprintf (stderr, "[ERROR] Failed to initialize\n"); return -1; } if (list_repos) { do_list_repos (); } if (validate_data) { if (do_validate_prepare() < 0) return -1; do_validate(); return 0; } if (destroy_repo_id) { if (seafile_is_running()) { fprintf (stderr, "seafile is running, close it and try again.\n"); return -1; } do_destroy_repo(destroy_repo_id); return 0; } cleanup (); return 0; }