int main(int argc, char **argv) { interface(argc, argv); /* Make sure that the current projection is not lat/long */ if ((G_projection() == PROJECTION_LL)) G_fatal_error(_("Lat/Long locations are not supported by this module")); open_files(); process(); close_down(); if (mparam == FEATURE) { write_cols(); write_cats(); } return 0; }
Script::~Script() { close_down(); }
int main (int argc, char *argv[]) { UserInterface *ui = NULL; GstEngine *engine = NULL; ClutterActor *video_texture; GstElement *sink; gboolean ok, fullscreen = FALSE; gint ret = 0; guint c, index, pos = 0; gchar *fileuri, *uri; gchar *file_list[argc]; GOptionContext *context; if (!g_thread_supported ()) g_thread_init (NULL); context = g_option_context_new ("<media file> - Play movie files"); ok = process_args (argc, argv, file_list, &fullscreen, context); if (!ok) goto quit; config_load (); // User Interface ui = g_new0 (UserInterface, 1); ui->fullscreen = fullscreen; video_texture = clutter_texture_new (); clutter_gst_init (&argc, &argv); // Gstreamer engine = g_new0 (GstEngine, 1); ui->engine = engine; sink = clutter_gst_video_sink_new (CLUTTER_TEXTURE (video_texture)); ok = engine_init (engine, sink); if (!ok) goto quit; ui->texture = video_texture; gst_bus_add_watch (engine->bus, bus_call, ui); gst_object_unref (engine->bus); if (gst_uri_is_valid (file_list[0])) uri = g_strdup (file_list[0]); else { fileuri = clean_uri (file_list[0]); uri = g_strdup_printf ("file://%s", fileuri); } engine_load_uri (engine, uri); interface_load_uri (ui, uri); load_user_interface (ui); change_state (engine, "Paused"); change_state (engine, "Playing"); clutter_main (); close_down (ui, engine); quit: g_option_context_free (context); return ret; }
/* snappy's main function */ int main (int argc, char *argv[]) { UserInterface *ui = NULL; GstEngine *engine = NULL; ClutterActor *video_texture; GstElement *sink; gboolean ok, blind = FALSE, fullscreen = FALSE, hide = FALSE, loop = FALSE; gboolean secret = FALSE, tags = FALSE; gint ret = 0; guint c, index, pos = 0; gchar *uri; gchar *suburi = NULL; gchar *version_str; GList *uri_list; GOptionContext *context; gchar *data_dir; #ifdef ENABLE_DBUS SnappyMP *mp_obj = NULL; #endif /* Try to find the path for our resources in case snappy was relocated */ data_dir = g_strdup(SNAPPY_DATA_DIR); if (!g_file_test(data_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { gchar *root_dir; #ifdef G_OS_WIN32 root_dir = g_win32_get_package_installation_directory_of_module(NULL); #elif !defined(G_OS_UNIX) gchar *exec_path; gchar *bin_dir; exec_path = g_file_read_link("/proc/self/exe", NULL); bin_dir = g_path_get_dirname(exec_path); root_dir = g_build_filename(bin_dir, "..", NULL); g_free(exec_path); g_free(bin_dir); #else root_dir = NULL; #endif if (root_dir != NULL) { data_dir = g_build_filename(root_dir, "share", "snappy", NULL); g_free(root_dir); } } if (!g_thread_supported ()) g_thread_init (NULL); context = g_option_context_new ("<media file> - Play movie files"); /* Process command arguments */ uri_list = process_args (argc, argv, &blind, &fullscreen, &hide, &loop, &secret, &suburi, &tags, context); if (uri_list == NULL) goto quit; /* User Interface */ ui = g_new (UserInterface, 1); ui->uri_list = uri_list; ui->blind = blind; ui->fullscreen = fullscreen; ui->hide = hide; ui->tags = tags; ui->data_dir = data_dir; interface_init (ui); video_texture = clutter_texture_new (); clutter_gst_init (&argc, &argv); version_str = gst_version_string (); GST_DEBUG_CATEGORY_INIT (_snappy_gst_debug, "snappy", 0, "snappy media player"); GST_DEBUG ("Initialised %s", version_str); /* Gstreamer engine */ engine = g_new (GstEngine, 1); sink = gst_element_factory_make ("autocluttersink", "cluttersink"); if (sink == NULL) { GST_DEBUG ("autocluttersink not found, falling back to cluttersink\n"); sink = gst_element_factory_make ("cluttersink", "cluttersink"); } g_object_set (G_OBJECT (sink), "texture", CLUTTER_TEXTURE (video_texture), NULL); ok = engine_init (engine, sink); if (!ok) goto quit; engine->secret = secret; engine->loop = loop; ui->engine = engine; ui->texture = video_texture; gst_bus_add_watch (engine->bus, bus_call, ui); gst_object_unref (engine->bus); /* Get uri to load */ uri = g_list_first (uri_list)->data; /* Load engine and start interface */ engine_load_uri (engine, uri); interface_start (ui, uri); /* Load subtitle file if available */ if (suburi != NULL) { suburi = clean_uri (suburi); set_subtitle_uri (engine, suburi); } /* Start playing */ change_state (engine, "Paused"); change_state (engine, "Playing"); #ifdef ENABLE_DBUS /* Start MPRIS Dbus object */ mp_obj = g_new (SnappyMP, 1); mp_obj->engine = engine; mp_obj->ui = ui; load_dlna (mp_obj); #endif /* Main loop */ clutter_main (); /* Close snappy */ close_down (ui, engine); #ifdef ENABLE_DBUS close_dlna (mp_obj); #endif quit: g_list_free (uri_list); g_option_context_free (context); return ret; }
/* snappy's main function */ int main (int argc, char *argv[]) { UserInterface *ui = NULL; GstEngine *engine = NULL; ClutterActor *video_texture; ClutterGstVideoSink *sink; gboolean ok, blind = FALSE, fullscreen = FALSE, hide = FALSE, loop = FALSE; gboolean secret = FALSE, tags = FALSE; gint ret = 0; gchar *uri = NULL; gchar *suburi = NULL; GList *uri_list; GOptionContext *context; gchar *data_dir; ClutterInitError ci_err; #ifdef ENABLE_DBUS SnappyMP *mp_obj = NULL; #endif context = g_option_context_new ("<media file> - Play movie files"); clutter_set_windowing_backend (CLUTTER_WINDOWING_X11); ci_err = gtk_clutter_init (&argc, &argv); if (ci_err != CLUTTER_INIT_SUCCESS) goto quit; /* Try to find the path for our resources in case snappy was relocated */ data_dir = g_strdup (SNAPPY_DATA_DIR); if (!g_file_test (data_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { gchar *root_dir; #ifdef G_OS_WIN32 root_dir = g_win32_get_package_installation_directory_of_module (NULL); #elif !defined(G_OS_UNIX) gchar *exec_path; gchar *bin_dir; exec_path = g_file_read_link ("/proc/self/exe", NULL); bin_dir = g_path_get_dirname (exec_path); root_dir = g_build_filename (bin_dir, "..", NULL); g_free (exec_path); g_free (bin_dir); #else root_dir = NULL; #endif if (root_dir != NULL) { data_dir = g_build_filename (root_dir, "share", "snappy", NULL); g_free (root_dir); } } /* Process command arguments */ uri_list = process_args (argc, argv, &blind, &fullscreen, &hide, &loop, &secret, &suburi, &tags, context); gst_init (&argc, &argv); clutter_gst_init (NULL, NULL); /* User Interface */ ui = g_new (UserInterface, 1); ui->uri_list = uri_list; ui->blind = blind; ui->fullscreen = fullscreen; ui->hide = hide; ui->tags = tags; ui->data_dir = data_dir; interface_init (ui); /* Gstreamer engine */ engine = g_new (GstEngine, 1); sink = clutter_gst_video_sink_new (); if (sink == NULL) { g_print ("ERROR: Failed to create clutter-gst sink element\n"); return FALSE; } video_texture = g_object_new (CLUTTER_TYPE_ACTOR, "content", g_object_new (CLUTTER_GST_TYPE_CONTENT, "sink", sink, NULL), "name", "texture", NULL); ok = engine_init (engine, sink); if (!ok) goto quit; engine->secret = secret; engine->loop = loop; ui->engine = engine; ui->texture = video_texture; gst_bus_add_watch (engine->bus, bus_call, ui); gst_object_unref (engine->bus); /* Get uri to load */ if (uri_list) { uri = g_list_first (uri_list)->data; /* based on video filename we can guess subtitle file (.srt files only) */ if (NULL == suburi) { gchar suburi_path_guessing[1024]; //buffer gchar *uri_no_extension = strip_filename_extension (uri); sprintf (suburi_path_guessing, "%s.srt", uri_no_extension); /* subtitle file exists, defaults for it */ if (g_file_test (g_filename_from_uri (suburi_path_guessing, NULL, NULL), G_FILE_TEST_EXISTS)) suburi = suburi_path_guessing; } } /* Load engine and start interface */ engine_load_uri (engine, uri); interface_start (ui, uri); /* Load subtitle file if available */ if (suburi != NULL) { suburi = clean_uri (suburi); set_subtitle_uri (engine, suburi); } /* Start playing if we have a URI to play */ if (uri) { change_state (engine, "Paused"); change_state (engine, "Playing"); } #ifdef ENABLE_DBUS /* Start MPRIS Dbus object */ mp_obj = g_new (SnappyMP, 1); mp_obj->engine = engine; mp_obj->ui = ui; load_dlna (mp_obj); #endif /* Main loop */ gtk_main (); /* Close snappy */ close_down (ui, engine); #ifdef ENABLE_DBUS close_dlna (mp_obj); #endif quit: g_list_free (uri_list); g_option_context_free (context); return ret; }
int main(int argc, char *argv[]) { struct sigaction sa; struct rlimit limit; int i, c, rc; int opt_foreground = 0, opt_allow_links = 0; enum startup_state opt_startup = startup_enable; extern char *optarg; extern int optind; struct ev_loop *loop; struct ev_io netlink_watcher; struct ev_signal sigterm_watcher; struct ev_signal sighup_watcher; struct ev_signal sigusr1_watcher; struct ev_signal sigusr2_watcher; struct ev_signal sigchld_watcher; /* Get params && set mode */ while ((c = getopt(argc, argv, "flns:")) != -1) { switch (c) { case 'f': opt_foreground = 1; break; case 'l': opt_allow_links=1; break; case 'n': do_fork = 0; break; case 's': for (i=0; i<startup_INVALID; i++) { if (strncmp(optarg, startup_states[i], strlen(optarg)) == 0) { opt_startup = i; break; } } if (i == startup_INVALID) { fprintf(stderr, "unknown startup mode '%s'\n", optarg); usage(); } break; default: usage(); } } /* check for trailing command line following options */ if (optind < argc) { usage(); } if (opt_allow_links) set_allow_links(1); if (opt_foreground) { config.daemonize = D_FOREGROUND; set_aumessage_mode(MSG_STDERR, DBG_YES); } else { config.daemonize = D_BACKGROUND; set_aumessage_mode(MSG_SYSLOG, DBG_NO); (void) umask( umask( 077 ) | 022 ); } #ifndef DEBUG /* Make sure we are root */ if (getuid() != 0) { fprintf(stderr, "You must be root to run this program.\n"); return 4; } #endif /* Register sighandlers */ sa.sa_flags = 0 ; sigemptyset( &sa.sa_mask ) ; /* Ignore all signals by default */ sa.sa_handler = SIG_IGN; for (i=1; i<NSIG; i++) sigaction( i, &sa, NULL ); atexit(clean_exit); /* Raise the rlimits in case we're being started from a shell * with restrictions. Not a fatal error. */ limit.rlim_cur = RLIM_INFINITY; limit.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &limit); setrlimit(RLIMIT_CPU, &limit); /* Load the Configuration File */ if (load_config(&config, TEST_AUDITD)) return 6; if (config.priority_boost != 0) { errno = 0; rc = nice((int)-config.priority_boost); if (rc == -1 && errno) { audit_msg(LOG_ERR, "Cannot change priority (%s)", strerror(errno)); return 1; } } /* Daemonize or stay in foreground for debugging */ if (config.daemonize == D_BACKGROUND) { if (become_daemon() != 0) { audit_msg(LOG_ERR, "Cannot daemonize (%s)", strerror(errno)); tell_parent(FAILURE); return 1; } openlog("auditd", LOG_PID, LOG_DAEMON); } /* Init netlink */ if ((fd = audit_open()) < 0) { audit_msg(LOG_ERR, "Cannot open netlink audit socket"); tell_parent(FAILURE); return 1; } /* Init the event handler thread */ write_pid_file(); if (init_event(&config)) { if (pidfile) unlink(pidfile); tell_parent(FAILURE); return 1; } if (init_dispatcher(&config)) { if (pidfile) unlink(pidfile); tell_parent(FAILURE); return 1; } /* Get machine name ready for use */ if (resolve_node(&config)) { if (pidfile) unlink(pidfile); tell_parent(FAILURE); return 1; } /* Write message to log that we are alive */ { struct utsname ubuf; char start[DEFAULT_BUF_SZ]; const char *fmt = audit_lookup_format((int)config.log_format); if (fmt == NULL) fmt = "UNKNOWN"; if (uname(&ubuf) != 0) { if (pidfile) unlink(pidfile); tell_parent(FAILURE); return 1; } if (getsubj(subj)) snprintf(start, sizeof(start), "auditd start, ver=%s format=%s " "kernel=%.56s auid=%u pid=%d subj=%s res=success", VERSION, fmt, ubuf.release, audit_getloginuid(), getpid(), subj); else snprintf(start, sizeof(start), "auditd start, ver=%s format=%s " "kernel=%.56s auid=%u pid=%d res=success", VERSION, fmt, ubuf.release, audit_getloginuid(), getpid()); if (send_audit_event(AUDIT_DAEMON_START, start)) { audit_msg(LOG_ERR, "Cannot send start message"); if (pidfile) unlink(pidfile); shutdown_dispatcher(); tell_parent(FAILURE); return 1; } } /* Tell kernel not to kill us */ avoid_oom_killer(); /* let config manager init */ init_config_manager(); if (opt_startup != startup_nochange && (audit_is_enabled(fd) < 2) && audit_set_enabled(fd, (int)opt_startup) < 0) { char emsg[DEFAULT_BUF_SZ]; if (*subj) snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d subj=%s res=failed", audit_getloginuid(), getpid(), subj); else snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d res=failed", audit_getloginuid(), getpid()); stop = 1; send_audit_event(AUDIT_DAEMON_ABORT, emsg); audit_msg(LOG_ERR, "Unable to set initial audit startup state to '%s', exiting", startup_states[opt_startup]); close_down(); if (pidfile) unlink(pidfile); shutdown_dispatcher(); tell_parent(FAILURE); return 1; } /* Tell the kernel we are alive */ if (audit_set_pid(fd, getpid(), WAIT_YES) < 0) { char emsg[DEFAULT_BUF_SZ]; if (*subj) snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d subj=%s res=failed", audit_getloginuid(), getpid(), subj); else snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d res=failed", audit_getloginuid(), getpid()); stop = 1; send_audit_event(AUDIT_DAEMON_ABORT, emsg); audit_msg(LOG_ERR, "Unable to set audit pid, exiting"); close_down(); if (pidfile) unlink(pidfile); shutdown_dispatcher(); tell_parent(FAILURE); return 1; } /* Depending on value of opt_startup (-s) set initial audit state */ loop = ev_default_loop (EVFLAG_NOENV); ev_io_init (&netlink_watcher, netlink_handler, fd, EV_READ); ev_io_start (loop, &netlink_watcher); ev_signal_init (&sigterm_watcher, term_handler, SIGTERM); ev_signal_start (loop, &sigterm_watcher); ev_signal_init (&sighup_watcher, hup_handler, SIGHUP); ev_signal_start (loop, &sighup_watcher); ev_signal_init (&sigusr1_watcher, user1_handler, SIGUSR1); ev_signal_start (loop, &sigusr1_watcher); ev_signal_init (&sigusr2_watcher, user2_handler, SIGUSR2); ev_signal_start (loop, &sigusr2_watcher); ev_signal_init (&sigchld_watcher, child_handler, SIGCHLD); ev_signal_start (loop, &sigchld_watcher); if (auditd_tcp_listen_init (loop, &config)) { char emsg[DEFAULT_BUF_SZ]; if (*subj) snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d subj=%s res=failed", audit_getloginuid(), getpid(), subj); else snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d res=failed", audit_getloginuid(), getpid()); stop = 1; send_audit_event(AUDIT_DAEMON_ABORT, emsg); tell_parent(FAILURE); } else { /* Now tell parent that everything went OK */ tell_parent(SUCCESS); audit_msg(LOG_NOTICE, "Init complete, auditd %s listening for events (startup state %s)", VERSION, startup_states[opt_startup]); } /* Parent should be gone by now... */ if (do_fork) close(init_pipe[1]); // Init complete, start event loop if (!stop) ev_loop (loop, 0); auditd_tcp_listen_uninit (loop, &config); // Tear down IO watchers Part 1 ev_signal_stop (loop, &sighup_watcher); ev_signal_stop (loop, &sigusr1_watcher); ev_signal_stop (loop, &sigusr2_watcher); ev_signal_stop (loop, &sigterm_watcher); /* Write message to log that we are going down */ rc = audit_request_signal_info(fd); if (rc > 0) { struct audit_reply trep; rc = get_reply(fd, &trep, rc); if (rc > 0) { char txt[MAX_AUDIT_MESSAGE_LENGTH]; snprintf(txt, sizeof(txt), "auditd normal halt, sending auid=%u " "pid=%d subj=%s res=success", trep.signal_info->uid, trep.signal_info->pid, trep.signal_info->ctx); send_audit_event(AUDIT_DAEMON_END, txt); } } if (rc <= 0) send_audit_event(AUDIT_DAEMON_END, "auditd normal halt, sending auid=? " "pid=? subj=? res=success"); free(rep); // Tear down IO watchers Part 2 ev_io_stop (loop, &netlink_watcher); // Give DAEMON_END event a little time to be sent in case // of remote logging usleep(10000); // 10 milliseconds shutdown_dispatcher(); // Tear down IO watchers Part 3 ev_signal_stop (loop, &sigchld_watcher); close_down(); free_config(&config); ev_default_destroy(); return 0; }
static void netlink_handler(struct ev_loop *loop, struct ev_io *io, int revents) { if (rep == NULL) { if ((rep = malloc(sizeof(*rep))) == NULL) { char emsg[DEFAULT_BUF_SZ]; if (*subj) snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d subj=%s res=failed", audit_getloginuid(), getpid(), subj); else snprintf(emsg, sizeof(emsg), "auditd error halt, auid=%u pid=%d res=failed", audit_getloginuid(), getpid()); EV_STOP (); send_audit_event(AUDIT_DAEMON_ABORT, emsg); audit_msg(LOG_ERR, "Cannot allocate audit reply, exiting"); close_down(); if (pidfile) unlink(pidfile); shutdown_dispatcher(); return; } } if (audit_get_reply(fd, &rep->reply, GET_REPLY_NONBLOCKING, 0) > 0) { switch (rep->reply.type) { /* For now dont process these */ case NLMSG_NOOP: case NLMSG_DONE: case NLMSG_ERROR: case AUDIT_GET: /* Or these */ case AUDIT_LIST_RULES: case AUDIT_FIRST_DAEMON...AUDIT_LAST_DAEMON: break; case AUDIT_SIGNAL_INFO: if (hup_info_requested) { audit_msg(LOG_DEBUG, "HUP detected, starting config manager"); if (start_config_manager(rep)) { send_audit_event( AUDIT_DAEMON_CONFIG, "auditd error getting hup info - no change," " sending auid=? pid=? subj=? res=failed"); } rep = NULL; hup_info_requested = 0; } else if (usr1_info_requested) { char usr1[MAX_AUDIT_MESSAGE_LENGTH]; if (rep->reply.len == 24) { snprintf(usr1, sizeof(usr1), "auditd sending auid=? pid=? subj=?"); } else { snprintf(usr1, sizeof(usr1), "auditd sending auid=%u pid=%d subj=%s", rep->reply.signal_info->uid, rep->reply.signal_info->pid, rep->reply.signal_info->ctx); } send_audit_event(AUDIT_DAEMON_ROTATE, usr1); usr1_info_requested = 0; } else if (usr2_info_requested) { char usr2[MAX_AUDIT_MESSAGE_LENGTH]; if (rep->reply.len == 24) { snprintf(usr2, sizeof(usr2), "auditd resuming logging, " "sending auid=? pid=? subj=? " "res=success"); } else { snprintf(usr2, sizeof(usr2), "auditd resuming logging, " "sending auid=%u pid=%d subj=%s res=success", rep->reply.signal_info->uid, rep->reply.signal_info->pid, rep->reply.signal_info->ctx); } resume_logging(); send_audit_event(AUDIT_DAEMON_RESUME, usr2); usr2_info_requested = 0; } break; default: distribute_event(rep); rep = NULL; break; } } else { if (errno == EFBIG) {