int main(int argc, char *argv[]){ if ( argc == 2 ){ time_t start, stop; clock_t ticks; time(&start); FILE *log = init_log(argv[1]); printf("%s : Log activated\n", curdate()); generate_triplets(log, argv[1]); if ( !fork() ){ if ( !fork() ){ get_column( init_log("g-col1"), 1, 0 ); }else{ get_column( init_log("g-col2"), 2, 0 ); // this is the lighter one!! // I'm gonna re-use this process to generate the hash of the triplets insertTrip(); } return 0; }else{ if ( !fork()) { get_column( init_log("g-col3"), 3, 1 ); return 0; } while (1) { int status; pid_t done = wait(&status); if (done == -1) { if (errno == ECHILD) break; // no more child processes } else { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { exit(1); } } } time(&stop); printf("Finished in about %.3f seconds. \n\n", difftime(stop, start)); fprintf(log, "Finished in about %.3f seconds. \n\n", difftime(stop, start)); } fclose(log); }else{ puts("USAGE: ./run rdf-file.ttl"); } return 0; }
int log_event(char *acct, uxds_acct_t type, uxds_tool_t op, char *text) { static uxds_authz_t auth; char *blurb = NULL; char *oper = NULL; char *admin = NULL; switch (type) { case USER: blurb = "POSIX USER"; break; case GROUP: blurb = "POSIX GROUP"; break; case SUDOER: blurb = "SUDOER"; break; default: break; } switch (op) { case ADD: oper = "ADD"; break; case DEL: oper = "DELETE"; break; case MOD: oper = "MODIFY"; break; default: break; } #ifdef HAVE_LDAP_SASL_GSSAPI if (auth.username == NULL) admin = strdup(get_krbname(auth, FALSE)); else admin = strdup(auth.username); #else admin = strtok(auth.binddn, ","); #endif /* HAVE_LDAP_SASL_GSSAPI */ FILE *fp; fp = fopen(UXDS_LOG, "a"); file_chkerr(fp); fprintf(fp, "%s - Change attempted by: ** %s **\n - %s Account %s of %s %s\n", curdate(), admin, blurb, oper, acct, text); if (fflush(fp)) { fprintf(stderr, "log file was not properly fflush()d\n"); return 1; } fclose(fp); if (admin) free(admin); return 0; }
int main(int argc, char** argv) { DB_CFG cfg; char szSql[BUFSIZ] = ""; char szFileName[BUFSIZ] = ""; char szHeader[BUFSIZ] = ""; memset( &cfg, 0, sizeof(DB_CFG) ); if ( rd_conf(&cfg) ) { printf("rd_conf error\n"); return -1; } MYSQL *pDbm = mysql_init(NULL); if (NULL == pDbm) { printf("mysql_init error\n"); return -1; } pDbm = mysql_real_connect(pDbm, cfg.szHostIP, cfg.szUser, cfg.szPasswd, cfg.szDatabase, cfg.unPort, NULL, 0); if (NULL == pDbm) { printf("mysql_real_connect error\n"); return -1; } // Create cvs file. time_t time_now = time(0); struct tm* ptm_now = localtime( &time_now ); sprintf(szFileName, "《问鼎》统计%02d月%02d日.csv", ptm_now->tm_mon + 1, ptm_now->tm_mday); FILE* fp = fopen(szFileName, "w"); if (NULL == fp) { printf("open file error\n"); return -1; } sprintf(szSql, "set names 'latin1'"); if ( mysql_query(pDbm, szSql) ) { printf("mysql_query error\n"); return -1; } printf("New client character set: %s\n", mysql_character_set_name(pDbm)); sprintf(szHeader, "激活帐号数,总角色数\n"); sprintf(szSql, "select count(distinct(account)), count(*) from hddb.user \ where (account between 'test001001' and 'test005000') \ or (account between 'test002001' and 'test002434') \ or (account between 'test003703' and 'test003811')"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } sprintf(szHeader, "\n\n新增角色数\n"); sprintf(szSql, "select count(*) from hddb.user where create_time \ between (curdate()-1)*1000000 and curdate()*1000000"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } sprintf(szHeader, "\n\n登录角色数,登录帐号数\n"); sprintf(szSql, "select count(*), count(distinct(account)) from hddb.user where \ last_login_time between (curdate()-1)*1000000 and curdate()*1000000"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } sprintf(szHeader, "\n\n等级段分布\n人数,等级段\n"); sprintf(szSql, "select count(*), 5*floor(level/5) as lv_stage from hddb.user \ where (account between 'test001001' and 'test005000') \ or (account between 'test002001' and 'test002434') \ or (account between 'test003703' and 'test003811') \ group by lv_stage order by lv_stage desc"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } sprintf(szHeader, "\n\n等级排名(前50)\n角色,帐号,等级\n"); sprintf(szSql, "select name, account, level from hddb.user \ where (account between 'test001001' and 'test005000') \ or (account between 'test002001' and 'test002434') \ or (account between 'test003703' and 'test003811') \ order by level desc limit 50"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } sprintf(szHeader, "\n\n金钱排名(前50)\n角色,帐号,金钱\n"); sprintf(szSql, "select name, account, money from hddb.user \ where (account between 'test001001' and 'test005000') \ or (account between 'test002001' and 'test002434') \ or (account between 'test003703' and 'test003811') \ order by money desc limit 50;"); if ( mysql2csv(fp, szHeader, szSql, pDbm) ) { printf("data query or write error\n"); return -1; } fclose(fp); fp = NULL; mysql_close(pDbm); //getchar(); return 0; }