From: franklahm <fra...@us...> - 2009-03-31 11:40:35
|
Update of /cvsroot/netatalk/netatalk/etc/cnid_dbd In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20333/etc/cnid_dbd Modified Files: cnid_metad.c main.c Log Message: Implement runtime logging config option to cnid dbd backend. See #2721956. New option: -l <logconfig>. cnid_metad passed that to cnid_dbd ! Fixed: 0 is a valid fd (in logger.c) ! Added logger API documentation in logger.h. Modified Files: etc/afpd/afp_options.c etc/cnid_dbd/cnid_metad.c etc/cnid_dbd/main.c include/atalk/logger.h libatalk/util/logger.c libatalk/util/test/logger_test.c Index: cnid_metad.c =================================================================== RCS file: /cvsroot/netatalk/netatalk/etc/cnid_dbd/cnid_metad.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** cnid_metad.c 6 Mar 2009 13:05:52 -0000 1.5 --- cnid_metad.c 31 Mar 2009 11:40:26 -0000 1.6 *************** *** 117,120 **** --- 117,123 ---- static struct server srv[MAXSRV +1]; + /* Default logging config: log to syslog with level log_debug */ + static char *logconfig = "default log_debug"; + static struct server *test_usockfn(char *dir, char *fn _U_) { *************** *** 281,288 **** */ LOG(log_error, logtype_cnid, "try with -d %s", up->name); ! ret = execlp(dbdpn, dbdpn, "-d", dbdir, buf1, buf2, NULL); } else { ! ret = execlp(dbdpn, dbdpn, dbdir, buf1, buf2, NULL); } if (ret < 0) { --- 284,291 ---- */ LOG(log_error, logtype_cnid, "try with -d %s", up->name); ! ret = execlp(dbdpn, dbdpn, "-d", dbdir, buf1, buf2, logconfig, NULL); } else { ! ret = execlp(dbdpn, dbdpn, dbdir, buf1, buf2, logconfig, NULL); } if (ret < 0) { *************** *** 391,395 **** set_processname("cnid_metad"); ! while (( cc = getopt( argc, argv, "ds:p:h:u:g:")) != -1 ) { switch (cc) { case 'd': --- 394,398 ---- set_processname("cnid_metad"); ! while (( cc = getopt( argc, argv, "ds:p:h:u:g:l:")) != -1 ) { switch (cc) { case 'd': *************** *** 419,422 **** --- 422,428 ---- dbdpn = strdup(optarg); break; + case 'l': + logconfig = strdup(optarg); + break; default: err++; *************** *** 424,428 **** } } ! if (err) { LOG(log_error, logtype_cnid, "main: bad arguments"); --- 430,436 ---- } } ! ! setuplog(logconfig); ! if (err) { LOG(log_error, logtype_cnid, "main: bad arguments"); Index: main.c =================================================================== RCS file: /cvsroot/netatalk/netatalk/etc/cnid_dbd/main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.c 28 Apr 2005 20:49:48 -0000 1.2 --- main.c 31 Mar 2009 11:40:26 -0000 1.3 *************** *** 55,59 **** { sigset_t set; ! sigemptyset(&set); sigaddset(&set, SIGINT); --- 55,59 ---- { sigset_t set; ! sigemptyset(&set); sigaddset(&set, SIGINT); *************** *** 66,81 **** } ! /* ! The dbd_XXX and comm_XXX functions all obey the same protocol for return values: ! ! 1: Success, if transactions are used commit. ! 0: Failure, but we continue to serve requests. If transactions are used abort/rollback. ! -1: Fatal error, either from the database or from the socket. Abort the transaction if applicable ! (which might fail as well) and then exit. We always try to notify the client process about the outcome, the result field of the cnid_dbd_rply structure contains further details. ! */ static int loop(struct db_param *dbp) --- 66,81 ---- } ! /* ! The dbd_XXX and comm_XXX functions all obey the same protocol for return values: ! ! 1: Success, if transactions are used commit. ! 0: Failure, but we continue to serve requests. If transactions are used abort/rollback. ! -1: Fatal error, either from the database or from the socket. Abort the transaction if applicable ! (which might fail as well) and then exit. We always try to notify the client process about the outcome, the result field of the cnid_dbd_rply structure contains further details. ! */ static int loop(struct db_param *dbp) *************** *** 95,101 **** if (dbp->nosync) checkp_flags = DB_FORCE; ! else checkp_flags = 0; ! rqst.name = namebuf; --- 95,101 ---- if (dbp->nosync) checkp_flags = DB_FORCE; ! else checkp_flags = 0; ! rqst.name = namebuf; *************** *** 105,109 **** now = time(NULL); ! if (count > dbp->flush_frequency || now > time_next_flush) { #ifdef CNID_BACKEND_DBD_TXN --- 105,109 ---- now = time(NULL); ! if (count > dbp->flush_frequency || now > time_next_flush) { #ifdef CNID_BACKEND_DBD_TXN *************** *** 123,140 **** if (exit_sig) return 0; ! if (dbp->idle_timeout && comm_nbe() <= 0 && (now - time_last_rqst) > dbp->idle_timeout) ! return 0; ! continue; } /* We got a request */ ! time_last_rqst = now; count++; ! #ifdef CNID_BACKEND_DBD_TXN ! if (dbif_txn_begin() < 0) return -1; #endif /* CNID_BACKEND_DBD_TXN */ ! memset(&rply, 0, sizeof(rply)); switch(rqst.op) { /* ret gets set here */ --- 123,140 ---- if (exit_sig) return 0; ! if (dbp->idle_timeout && comm_nbe() <= 0 && (now - time_last_rqst) > dbp->idle_timeout) ! return 0; ! continue; } /* We got a request */ ! time_last_rqst = now; count++; ! #ifdef CNID_BACKEND_DBD_TXN ! if (dbif_txn_begin() < 0) return -1; #endif /* CNID_BACKEND_DBD_TXN */ ! memset(&rply, 0, sizeof(rply)); switch(rqst.op) { /* ret gets set here */ *************** *** 142,146 **** case CNID_DBD_OP_CLOSE: /* open/close are noops for now. */ ! rply.namelen = 0; ret = 1; break; --- 142,146 ---- case CNID_DBD_OP_CLOSE: /* open/close are noops for now. */ ! rply.namelen = 0; ret = 1; break; *************** *** 173,177 **** ret = -1; break; ! } if ((cret = comm_snd(&rply)) < 0 || ret < 0) { --- 173,177 ---- ret = -1; break; ! } if ((cret = comm_snd(&rply)) < 0 || ret < 0) { *************** *** 183,190 **** #ifdef CNID_BACKEND_DBD_TXN if (ret == 0 || cret == 0) { ! if (dbif_txn_abort() < 0) return -1; } else { ! if (dbif_txn_commit() < 0) return -1; } --- 183,190 ---- #ifdef CNID_BACKEND_DBD_TXN if (ret == 0 || cret == 0) { ! if (dbif_txn_abort() < 0) return -1; } else { ! if (dbif_txn_commit() < 0) return -1; } *************** *** 202,206 **** exit(1); } ! if (stat(".", &st) < 0) { LOG(log_error, logtype_cnid, "error in stat for %s: %s", dir, strerror(errno)); --- 202,206 ---- exit(1); } ! if (stat(".", &st) < 0) { LOG(log_error, logtype_cnid, "error in stat for %s: %s", dir, strerror(errno)); *************** *** 223,230 **** if ((lockfd = open(LOCKFILENAME, O_RDWR | O_CREAT, 0644)) < 0) { ! LOG(log_error, logtype_cnid, "main: error opening lockfile: %s", strerror(errno)); ! exit(1); } ! lock.l_start = 0; lock.l_whence = SEEK_SET; --- 223,230 ---- if ((lockfd = open(LOCKFILENAME, O_RDWR | O_CREAT, 0644)) < 0) { ! LOG(log_error, logtype_cnid, "main: error opening lockfile: %s", strerror(errno)); ! exit(1); } ! lock.l_start = 0; lock.l_whence = SEEK_SET; *************** *** 233,244 **** if (fcntl(lockfd, F_SETLK, &lock) < 0) { ! if (errno == EACCES || errno == EAGAIN) { ! exit(0); ! } else { ! LOG(log_error, logtype_cnid, "main: fcntl F_WRLCK lockfile: %s", strerror(errno)); ! exit(1); ! } } ! return lockfd; } --- 233,244 ---- if (fcntl(lockfd, F_SETLK, &lock) < 0) { ! if (errno == EACCES || errno == EAGAIN) { ! exit(0); ! } else { ! LOG(log_error, logtype_cnid, "main: fcntl F_WRLCK lockfile: %s", strerror(errno)); ! exit(1); ! } } ! return lockfd; } *************** *** 286,295 **** int ret; int lockfd, ctrlfd, clntfd; ! char *dir; ! set_processname("cnid_dbd"); ! syslog_setup(log_debug, logtype_default, logoption_ndelay | logoption_pid, logfacility_daemon); ! ! if (argc != 4) { LOG(log_error, logtype_cnid, "main: not enough arguments"); exit(1); --- 286,294 ---- int ret; int lockfd, ctrlfd, clntfd; ! char *dir, *logconfig; ! set_processname("cnid_dbd"); ! ! if (argc != 5) { LOG(log_error, logtype_cnid, "main: not enough arguments"); exit(1); *************** *** 299,313 **** ctrlfd = atoi(argv[2]); clntfd = atoi(argv[3]); switch_to_user(dir); ! /* Before we do anything else, check if there is an instance of cnid_dbd running already and silently exit if yes. */ lockfd = get_lock(); ! LOG(log_info, logtype_cnid, "Startup, DB dir %s", dir); ! set_signal(); ! /* SIGINT and SIGTERM are always off, unless we get a return code of 0 from comm_rcv (no requests for one second, see above in loop()). That means we --- 298,314 ---- ctrlfd = atoi(argv[2]); clntfd = atoi(argv[3]); + logconfig = strdup(argv[4]); + setuplog(logconfig); switch_to_user(dir); ! /* Before we do anything else, check if there is an instance of cnid_dbd running already and silently exit if yes. */ lockfd = get_lock(); ! LOG(log_info, logtype_cnid, "Startup, DB dir %s", dir); ! set_signal(); ! /* SIGINT and SIGTERM are always off, unless we get a return code of 0 from comm_rcv (no requests for one second, see above in loop()). That means we *************** *** 319,332 **** if (dbif_env_init(dbp) < 0) ! exit(2); /* FIXME: same exit code as failure for dbif_open() */ ! #ifdef CNID_BACKEND_DBD_TXN if (dbif_txn_begin() < 0) ! exit(6); #endif ! if (dbif_open(dbp, 0) < 0) { #ifdef CNID_BACKEND_DBD_TXN ! dbif_txn_abort(); #endif dbif_close(); --- 320,333 ---- if (dbif_env_init(dbp) < 0) ! exit(2); /* FIXME: same exit code as failure for dbif_open() */ ! #ifdef CNID_BACKEND_DBD_TXN if (dbif_txn_begin() < 0) ! exit(6); #endif ! if (dbif_open(dbp, 0) < 0) { #ifdef CNID_BACKEND_DBD_TXN ! dbif_txn_abort(); #endif dbif_close(); *************** *** 341,351 **** } dbif_closedb(); ! LOG(log_info, logtype_cnid, "main: re-opening, secondaries will be rebuilt. This may take some time"); if (dbif_open(dbp, 1) < 0) { ! LOG(log_info, logtype_cnid, "main: re-opening databases failed"); dbif_close(); exit(2); } ! LOG(log_info, logtype_cnid, "main: rebuilt done"); } #endif --- 342,352 ---- } dbif_closedb(); ! LOG(log_info, logtype_cnid, "main: re-opening, secondaries will be rebuilt. This may take some time"); if (dbif_open(dbp, 1) < 0) { ! LOG(log_info, logtype_cnid, "main: re-opening databases failed"); dbif_close(); exit(2); } ! LOG(log_info, logtype_cnid, "main: rebuilt done"); } #endif *************** *** 353,357 **** if (dbd_stamp() < 0) { #ifdef CNID_BACKEND_DBD_TXN ! dbif_txn_abort(); #endif dbif_close(); --- 354,358 ---- if (dbd_stamp() < 0) { #ifdef CNID_BACKEND_DBD_TXN ! dbif_txn_abort(); #endif dbif_close(); *************** *** 360,364 **** #ifdef CNID_BACKEND_DBD_TXN if (dbif_txn_commit() < 0) ! exit(6); #endif --- 361,365 ---- #ifdef CNID_BACKEND_DBD_TXN if (dbif_txn_commit() < 0) ! exit(6); #endif *************** *** 380,393 **** if (dbif_close() < 0) err++; ! free_lock(lockfd); ! if (err) exit(4); else if (exit_sig) ! LOG(log_info, logtype_cnid, "main: Exiting on signal %i", exit_sig); else ! LOG(log_info, logtype_cnid, "main: Idle timeout, exiting"); ! return 0; } --- 381,394 ---- if (dbif_close() < 0) err++; ! free_lock(lockfd); ! if (err) exit(4); else if (exit_sig) ! LOG(log_info, logtype_cnid, "main: Exiting on signal %i", exit_sig); else ! LOG(log_info, logtype_cnid, "main: Idle timeout, exiting"); ! return 0; } |