void actionBookmarkAdd(void *data) { DVDBookmark_t *bm; unsigned char id[16]; char *state = NULL; char volid[33]; int volid_type; char *disccomment = NULL; if(DVDGetDiscID(nav, id) != DVD_E_Ok) { NOTE("%s", "GetDiscID failed\n"); return; } if(DVDGetVolumeIdentifiers(nav, 0, &volid_type, volid, NULL) != DVD_E_Ok) { DNOTE("%s", "GetVolumeIdentifiers failed\n"); volid_type = 0; } if(DVDGetState(nav, &state) == DVD_E_Ok) { if((bm = DVDBookmarkOpen(id, NULL, 1)) == NULL) { if(errno != ENOENT) { NOTE("%s", "BookmarkOpen failed: "); perror(""); } free(state); return; } if(DVDBookmarkAdd(bm, state, NULL, NULL, NULL) == -1) { DNOTE("%s", "BookmarkAdd failed\n"); DVDBookmarkClose(bm); free(state); return; } free(state); if(volid_type != 0) { if(DVDBookmarkGetDiscComment(bm, &disccomment) != -1) { if((disccomment == NULL) || (disccomment[0] == '\0')) { if(DVDBookmarkSetDiscComment(bm, volid) == -1) { DNOTE("%s", "SetDiscComment failed\n"); } } if(disccomment) { free(disccomment); } } } if(DVDBookmarkSave(bm, 0) == -1) { NOTE("%s", "BookmarkSave failed\n"); } DVDBookmarkClose(bm); } }
//主上收到仲裁备节点信息变动 int mb_binfo_update(int voteid, char *data, int datalen) { WThread *wt = g_runtime->wthread; BackupInfo *binfo = wt->backup_info; BackupItem *bitem; //释放以前所有备节点得信息 while (binfo->item) { bitem = binfo->item; binfo->item = bitem->next; if (bitem->mbconn && bitem->mbconn->sock > 0) //bitem->mbconn->destroy((Conn *)bitem->mbconn); DNOTE("destroy mbconn\n"); mb_conn_destroy_delay((Conn *)bitem->mbconn); bitem->mbconn = NULL; bitem->state = STATE_NOWRITE; zz_free(bitem); } close(wt->backup_info->hbsock); event_del(&wt->backup_info->hbevt); event_del(&wt->backup_info->timer_check_evt); zz_free(wt->backup_info); master_init(voteid, data, datalen); return 0; }
int master_init(int voteid, char *data, int datalen) { int ret; WThread *wt = g_runtime->wthread; wt->clog = commitlog_create(); g_cf->role = ROLE_MASTER; wt->backup_info = (BackupInfo *)zz_malloc(sizeof(BackupInfo)); DNOTE("============I am the master\n"); if (wt->backup_info == NULL) { DERROR("malloc BackupInfo struct error\n"); MEMLINK_EXIT; } memset(wt->backup_info, 0x0, sizeof(BackupInfo)); BackupInfo *binfo = wt->backup_info; g_runtime->servernums = 1; g_runtime->voteid = voteid; binfo->timer_send = FALSE; int count = 0; char ip[16] = {0}; uint16_t port; DINFO("datalen : %d\n", datalen); while (count < datalen) { ret = unpack_votehost(data + count, ip, &port); DINFO("ip: %s port: %d\n", ip, port); count += ret; BackupItem *bitem = (BackupItem *)zz_malloc(sizeof(BackupItem)); if (bitem == NULL) { DERROR("malloc BackupItem struct error\n"); MEMLINK_EXIT; } memset(bitem, 0x0, sizeof(BackupItem)); strcpy(bitem->ip, ip); bitem->write_port = port; DINFO("backup ip, port: %s:%d\n", ip, port); bitem->next = binfo->item; binfo->item = bitem; g_runtime->servernums++; } master_create_heartbeat(wt); //初始化backupinfo结构 ret = master_connect_backup_all(wt); return 0; }
static void printAudioAttributes(DVDAudioAttributes_t *attr) { char *t_str; switch(attr->AudioFormat) { case DVD_AUDIO_FORMAT_AC3: t_str = "AC-3"; break; case DVD_AUDIO_FORMAT_MPEG1: t_str = "MPEG-1"; //MPEG-1 (or MPEG-2 without extension stream) break; case DVD_AUDIO_FORMAT_MPEG1_DRC: t_str = "MPEG-1 DRC"; break; case DVD_AUDIO_FORMAT_MPEG2: t_str = "MPEG-2"; // MPEG-2 with extension stream break; case DVD_AUDIO_FORMAT_MPEG2_DRC: t_str = "MPEG-2 DRC"; break; case DVD_AUDIO_FORMAT_LPCM: t_str = "LPCM"; break; case DVD_AUDIO_FORMAT_DTS: t_str = "DTS"; break; case DVD_AUDIO_FORMAT_SDDS: t_str = "SDDS"; break; case DVD_AUDIO_FORMAT_Other: default: t_str = "Other"; break; } DNOTE("%s", t_str); if(attr->AudioFormat == DVD_AUDIO_FORMAT_LPCM) { DNOTEC(" %d bits %d Hz", attr->SampleQuantization, attr->SampleFrequency); } DNOTEC(" %dch", attr->NumberOfChannels); if(attr->AudioType == DVD_AUDIO_TYPE_Language) { DNOTEC(" %c%c", attr->Language >> 8, attr->Language & 0xff); }
void mb_data_timeout(int fd, short event, void *arg) { WThread *wt = g_runtime->wthread; BackupInfo *binfo = wt->backup_info; int alive = 0; DNOTE("-------------------------------------------------binfo->succ: %d\n", binfo->succ); if (binfo->succ + 1 < g_runtime->servernums / 2 + 1) { BackupItem *bitem = binfo->item; while (bitem) { if (bitem->mbconn) alive++; bitem = bitem->next; } if (alive + 1 < g_runtime->servernums / 2 + 1) { Conn *conn = (Conn *)arg; conn_send_buffer_reply(conn, MEMLINK_ERR_NOWRITE, NULL, 0); wt->state = STATE_NOCONN; } } return; }
static void sig_handler_hup(const int sig) { DNOTE("====== SIGHUP handled ======\n"); //int master_sync_port = 0; //int role; int need_kill = 0; FILE *fp; int lineno = 0; int confrole = 0; fp = fopen(g_runtime->conffile, "r"); if (NULL == fp) { DERROR("open config file error: %s\n", g_runtime->conffile); } char buffer[2048]; while (1) { if (fgets(buffer, 2048, fp) == NULL) { //DINFO("config file read complete!\n"); break; } lineno ++; //DINFO("buffer: %s\n", buffer); if (buffer[0] == '#' || buffer[0] == '\r'|| buffer[0] =='\n') { // skip comment continue; } char *sp = strchr(buffer, '='); if (sp == NULL) { DERROR("config file error at line %d: %s\n", lineno, buffer); MEMLINK_EXIT; } char *end = sp - 1; while (end > buffer && isblank(*end)) { end--; } *(end + 1) = 0; char *start = sp + 1; while (isblank(*start)) { start++; } end = start; while (*end != 0) { if (*end == '\r' || *end == '\n') { end -= 1; while (end > start && isblank(*end)) { end--; } *(end + 1) = 0; break; } end += 1; } if (strcmp(buffer, "block_data_reduce") == 0) { g_cf->block_data_reduce = atof(start); } else if (strcmp(buffer, "block_clean_cond") == 0) { g_cf->block_clean_cond = atof(start); } else if (strcmp(buffer, "block_clean_start") == 0) { g_cf->block_clean_start = atoi(start); } else if (strcmp(buffer, "block_clean_num") == 0) { g_cf->block_clean_num = atoi(start); } else if (strcmp(buffer, "log_level") == 0) { g_cf->log_level = atoi(start); //logfile_create(g_cf->log_name, g_cf->log_level); g_log->loglevel = g_cf->log_level; } else if (strcmp(buffer, "timeout") == 0) { g_cf->timeout = atoi(start); } else if (strcmp(buffer, "sync_check_interval") == 0) { g_cf->sync_check_interval = atoi(start); } else if (strcmp(buffer, "role") == 0) { if (strcmp(start, "master") == 0) confrole = ROLE_MASTER; else if (strcmp(start, "slave") == 0) confrole = ROLE_SLAVE; else if (strcmp(start, "backup") == 0) confrole = ROLE_BACKUP; } else if(strcmp(buffer, "master_sync_host") == 0) { if (strcmp(g_cf->master_sync_host, start) != 0) { snprintf(g_cf->master_sync_host, IP_ADDR_MAX_LEN, "%s", start); need_kill = 1; } } else if (strcmp(buffer, "master_sync_port") == 0) { if (g_cf->master_sync_port != atoi(start)) { g_cf-> master_sync_port = atoi(start); need_kill = 1; } } } DINFO("role: %d, need_kill: %d\n", confrole, need_kill); if (g_cf->role == ROLE_SLAVE ) { //如果memlink作为从服务器 if (confrole == ROLE_MASTER) {//需要切换成主,杀掉从线程 //wait_thread_exit(g_runtime->slave->threadid); sslave_stop(g_runtime->slave); g_cf->role = ROLE_MASTER; DINFO("========slave to master\n"); } else if (confrole == ROLE_BACKUP) { //wait_thread_exit(g_runtime->slave->threadid); sslave_stop(g_runtime->slave); g_cf->role = ROLE_BACKUP; DINFO("========slave to backup\n"); } else if ((confrole == ROLE_SLAVE) && need_kill == 1) { //不需要切换,查看master_sync_host和master_sync_port是否改变 //从新启动从线程 //wait_thread_exit(g_runtime->slave->threadid); /*if (g_runtime->slave) { sslave_thread(g_runtime->slave); } else { g_runtime->slave = sslave_create(); }*/ sslave_go(g_runtime->slave); DINFO("=========restart slave thread\n"); } } else if ((g_cf->role == ROLE_MASTER || g_cf->role == ROLE_BACKUP) && confrole == ROLE_SLAVE) { //主切换成从, 只需启动从线程 /*if (g_runtime->slave) { sslave_thread(g_runtime->slave); } else { g_runtime->slave = sslave_create(); }*/ sslave_go(g_runtime->slave); g_cf->role = ROLE_SLAVE; DINFO("===========master to slave\n"); } fclose(fp); }
int main(int argc, char *argv[]) { int ret; struct rlimit rlim; char *conffile; if (argc == 2) { conffile = argv[1]; }else{ //conffile = "etc/memlink.conf"; usage(); return 0; } //DINFO("%s\n", MEMLINK_VERSION); //DINFO("config file: %s\n", conffile); myconfig_create(conffile); DNOTE("====== %s ======\n", MEMLINK_VERSION); //DNOTE("config file: %s\n", conffile); //DNOTE("data dir: %s\n", g_cf->datadir); if (g_cf->max_core) { struct rlimit rlim_new; if (getrlimit(RLIMIT_CORE, &rlim) == 0) { rlim_new.rlim_cur = rlim_new.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_CORE, &rlim_new)!= 0) { /* failed. try raising just to the old max */ rlim_new.rlim_cur = rlim_new.rlim_max = rlim.rlim_max; (void)setrlimit(RLIMIT_CORE, &rlim_new); } } if ((getrlimit(RLIMIT_CORE, &rlim) != 0) || rlim.rlim_cur == 0) { DERROR("failed to ensure corefile creation\n"); MEMLINK_EXIT; } } if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) { DERROR("failed to getrlimit number of files\n"); MEMLINK_EXIT; } else { int maxfiles = g_cf->max_conn + 20; if (rlim.rlim_cur < maxfiles) rlim.rlim_cur = maxfiles; if (rlim.rlim_max < rlim.rlim_cur) rlim.rlim_max = rlim.rlim_cur; if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) { DERROR("failed to set rlimit for open files. Try running as root or requesting smaller maxconns value.\n"); MEMLINK_EXIT; } } if (change_group_user(g_cf->user) < 0) { DERROR("change group user error!\n"); MEMLINK_EXIT; } signal_install(); if (g_cf->is_daemon) { ret = daemonize(g_cf->max_core, 0); if (ret == -1) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("daemon error! %s\n", errbuf); MEMLINK_EXIT; } } logfile_create(g_cf->log_name, g_cf->log_level); if (g_cf->log_error_name[0] != 0) { logfile_error_separate(g_log, g_cf->log_error_name); } if (g_cf->log_rotate_type == LOG_ROTATE_SIZE) { logfile_rotate_size(g_log, g_cf->log_size, g_cf->log_count); }else if (g_cf->log_rotate_type == LOG_ROTATE_TIME){ logfile_rotate_time(g_log, g_cf->log_time, g_cf->log_count); } DINFO("logfile ok!\n"); myconfig_print(g_cf); if (g_cf->sync_mode == MODE_MASTER_BACKUP) { master(argv[0], conffile); } else if (g_cf->sync_mode == MODE_MASTER_SLAVE) { if (g_cf->role == ROLE_MASTER) { master(argv[0], conffile); }else{ slave(argv[0], conffile); } } else { DERROR("sync_mode is error\n"); MEMLINK_EXIT; } return 0; }
void autosave_bookmark(void) { DVDBookmark_t *bm; unsigned char id[16]; char volid[33]; int volid_type; char *state = NULL; int n; if(bookmarks_autosave) { if(DVDGetDiscID(nav, id) != DVD_E_Ok) { NOTE("%s", "GetDiscID failed\n"); return; } if(DVDGetVolumeIdentifiers(nav, 0, &volid_type, volid, NULL) != DVD_E_Ok) { DNOTE("%s", "GetVolumeIdentifiers failed\n"); volid_type = 0; } if(DVDGetState(nav, &state) == DVD_E_Ok) { if((bm = DVDBookmarkOpen(id, NULL, 1)) == NULL) { if(errno != ENOENT) { NOTE("%s", "BookmarkOpen failed: "); perror(""); } free(state); return; } n = DVDBookmarkGetNr(bm); if(n == -1) { NOTE("%s", "DVDBookmarkGetNr failed\n"); } else if(n > 0) { for(n--; n >= 0; n--) { char *appinfo; if(DVDBookmarkGet(bm, n, NULL, NULL, "common", &appinfo) != -1) { if(appinfo) { if(!strcmp(appinfo, "autobookmark")) { if(DVDBookmarkRemove(bm, n) == -1) { NOTE("%s", "DVDBookmarkRemove failed\n"); } } free(appinfo); } } else { NOTE("%s", "DVDBookmarkGet failed\n"); } } } if(DVDBookmarkAdd(bm, state, NULL, "common", "autobookmark") == -1) { DNOTE("%s", "BookmarkAdd failed\n"); DVDBookmarkClose(bm); free(state); return; } free(state); if(volid_type != 0) { char *disccomment = NULL; if(DVDBookmarkGetDiscComment(bm, &disccomment) != -1) { if((disccomment == NULL) || (disccomment[0] == '\0')) { if(DVDBookmarkSetDiscComment(bm, volid) == -1) { DNOTE("%s", "SetDiscComment failed\n"); } } if(disccomment) { free(disccomment); } } } if(DVDBookmarkSave(bm, 0) == -1) { NOTE("%s", "BookmarkSave failed\n"); } DVDBookmarkClose(bm); } } }