static int init_local_snapshot_directory(orte_sstore_central_app_snapshot_info_t *handle_info) { int ret, exit_status = ORTE_SUCCESS; mode_t my_mode = S_IRWXU; /* * Make the snapshot directory from the uniq_global_snapshot_name */ if(OPAL_SUCCESS != (ret = opal_os_dirpath_create(handle_info->local_location, my_mode)) ) { opal_show_help("help-orte-sstore-central.txt", "fail_path_create", true, ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), orte_process_info.nodename, handle_info->local_location); ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } /* * Open up the metadata file */ if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } /* * Add a timestamp and the PID of this process */ if( ORTE_SUCCESS != (ret = metadata_write_timestamp(handle_info)) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } if( ORTE_SUCCESS != (ret = metadata_write_int(handle_info, SSTORE_METADATA_LOCAL_PID_STR, (int)getpid())) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } if( ORTE_SUCCESS != (ret = metadata_close(handle_info)) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } cleanup: return exit_status; }
static int metadata_write_str(orte_sstore_central_global_snapshot_info_t * handle_info, char *key, char *value) { int ret, exit_status = ORTE_SUCCESS; /* Make sure the metadata file is open */ if( NULL == handle_info->metadata ) { if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } } fprintf(handle_info->metadata, "%s%s\n", key, value); cleanup: return exit_status; }
static int metadata_write_timestamp(orte_sstore_central_app_snapshot_info_t * handle_info) { int ret, exit_status = ORTE_SUCCESS; time_t timestamp; /* Make sure the metadata file is open */ if( NULL == handle_info->metadata ) { if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) { ORTE_ERROR_LOG(ret); exit_status = ret; goto cleanup; } } timestamp = time(NULL); fprintf(handle_info->metadata, "%s%s", SSTORE_METADATA_INTERNAL_TIME_STR, ctime(×tamp)); cleanup: return exit_status; }
int main(int argc, char **argv) { /* struct mpd_connection *conn = NULL; conn = mpd_connection_new(NULL, 0, 3000); if (conn == NULL) {printf("%s", "Out of memory"); return -1;} mpd_run_stop(conn); mpd_connection_free(conn); */ signal_setup(); memset(&config, 0, sizeof(config)); // set defaults config.buffer_start_fill = 220; config.port = 5002; char hostname[100]; gethostname(hostname, 100); config.apname = malloc(20 + 100); snprintf(config.apname, 20 + 100, "%s", hostname); // parse arguments into config int audio_arg = parse_options(argc, argv); // mDNS supports maximum of 63-character names (we append 13). if (strlen(config.apname) > 50) die("Supplied name too long (max 50 characters)"); if (config.daemonise) { daemon_init(); } if(ggshutdown) { if (kill(0, SIGTERM)) { printf("kill(0, SIGTERM))"); } die("shairport shutted down...!"); } printf("stop mpc:\n"); system("mpc stop"); printf("mpc stopped\n"); printf("Starting Shairport %s\n", version); log_setup(); config.output = audio_get_output(config.output_name); if (!config.output) { audio_ls_outputs(); die("Invalid audio output specified!"); } config.output->init(argc-audio_arg, argv+audio_arg); uint8_t ap_md5[16]; MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx, config.apname, strlen(config.apname)); MD5_Final(ap_md5, &ctx); memcpy(config.hw_addr, ap_md5, sizeof(config.hw_addr)); if (config.meta_dir) metadata_open(); rtsp_listen_loop(); // should not. shairport_shutdown(1); return 1; }