Esempio n. 1
0
void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    // prevent logging too much
    if(error_log_limit(0)) return;

    log_date(stderr);

    va_start( args, fmt );
    if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name);
    else            fprintf(stderr, "%s: %s: ", prefix, program_name);
    vfprintf( stderr, fmt, args );
    va_end( args );

    if(errno) {
        char buf[1024];
        fprintf(stderr, " (errno %d, %s)\n", errno, strerror_r(errno, buf, 1023));
        errno = 0;
    }
    else
        fputc('\n', stderr);

    if(error_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_ERR,  fmt, args );
        va_end( args );
    }
}
Esempio n. 2
0
File: log.c Progetto: azuwis/mpd
static void
file_log_func(const gchar *log_domain,
	      G_GNUC_UNUSED GLogLevelFlags log_level,
	      const gchar *message, G_GNUC_UNUSED gpointer user_data)
{
	char *converted;

	if (log_level > log_threshold)
		return;

	if (log_charset != NULL) {
		converted = g_convert_with_fallback(message, -1,
						    log_charset, "utf-8",
						    NULL, NULL, NULL, NULL);
		if (converted != NULL)
			message = converted;
	} else
		converted = NULL;

	if (log_domain == NULL)
		log_domain = "";

	fprintf(stderr, "%s%s%s%.*s\n",
		stdout_mode ? "" : log_date(),
		log_domain, *log_domain == 0 ? "" : ": ",
		chomp_length(message), message);

	g_free(converted);
}
Esempio n. 3
0
/* funzione utilizzate per la creazione di semafori, memorie e code di messaggi.
 * ritorna 1 se tutte le risorse sono allocate correttamente, 0 altrimenti.  */
int server_start() {
	log_date(LOG_PATH, "(start) Avvio server");
	get_date(start_date);
	// Creazione di semafori, memorie e code di messaggi
	if ((semid = semget(SEMKEY, SEM_TOT, 0600 | IPC_CREAT)) == -1) errorlog(LOG_PATH, "Semafori non allocati");

	if ((shmid = shmget(SHMKEY, sizeof(repo), 0600 | IPC_CREAT)) == -1) errorlog(
			LOG_PATH, "Area di memoria Repository non allocata");

	if ((shmlog = shmget(BUFFER_SHMKEY, sizeof(buffer), 0600 | IPC_CREAT)) == -1) errorlog(
			LOG_PATH, "Area di memoria LOG non allocata");

	if ((shmls = shmget(LS_SHMKEY, sizeof(numlettori), 0600 | IPC_CREAT)) == -1) errorlog(
			LOG_PATH, "Area di memoria LETTORI/SCRITTORI non allocata");

	if ((shmauth = shmget(AUTH_SHMKEY, sizeof(auth), 0600 | IPC_CREAT)) == -1) errorlog(
			LOG_PATH, "Area di memoria AUTORIZZAZIONI non allocata");

	if ((shmpush = shmget(PUSH_SHMKEY, sizeof(push), 0600 | IPC_CREAT)) == -1) errorlog(
			LOG_PATH, "Area di memoria PUSH non allocata");

	if ((msgid = msgget(MSGKEY, IPC_CREAT | 0600)) == -1) errorlog(LOG_PATH,
			"Coda messaggi non allocata");

	// Controllo errori all'avvio */
	if (semid == -1 || shmid == -1 || shmlog == -1 || shmls == -1 || shmauth == -1
			|| shmpush == -1 || msgid == -1) server_stop();

	if (!setup()) {
		errorlog(LOG_PATH, "(start) File del repository iniziale non trovato");
		return 0;
	}
	return 1;
}
Esempio n. 4
0
File: log.c Progetto: 2-B/netdata
void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
	va_list args;

	log_date(stderr);

	va_start( args, fmt );
	if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name);
	else            fprintf(stderr, "%s: %s: ", prefix, program_name);
	vfprintf( stderr, fmt, args );
	va_end( args );

	if(errno) {
		char buf[200];
		char *s = strerror_r(errno, buf, 200);
		fprintf(stderr, " (errno %d, %s)\n", errno, s);
		errno = 0;
	}
	else fprintf(stderr, "\n");

	if(error_log_syslog) {
		va_start( args, fmt );
		vsyslog(LOG_ERR,  fmt, args );
		va_end( args );
	}
}
Esempio n. 5
0
File: log.c Progetto: 2-B/netdata
void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
	va_list args;

	log_date(stdout);
	va_start( args, fmt );
	fprintf(stdout, "DEBUG (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
	vfprintf( stdout, fmt, args );
	va_end( args );
	fprintf(stdout, "\n");

	if(output_log_syslog) {
		va_start( args, fmt );
		vsyslog(LOG_ERR,  fmt, args );
		va_end( args );
	}
}
Esempio n. 6
0
void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    log_date(stdout);
    va_start( args, fmt );
    printf("%s: DEBUG (%04lu@%-10.10s:%-15.15s): ", program_name, line, file, function);
    vprintf(fmt, args);
    va_end( args );
    putchar('\n');

    if(output_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_ERR,  fmt, args );
        va_end( args );
    }

    fflush(stdout);
}
Esempio n. 7
0
void log_access( const char *fmt, ... )
{
    va_list args;

    if(stdaccess) {
        log_date(stdaccess);

        va_start( args, fmt );
        vfprintf( stdaccess, fmt, args );
        va_end( args );
        fputc('\n', stdaccess);
    }

    if(access_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_INFO,  fmt, args );
        va_end( args );
    }
}
Esempio n. 8
0
ProtoReaderDriver::ProtoReaderDriver(std::string filename, int camID, size_t imageID)
    : m_first(true),
      m_camId(camID),
      m_reader( hal::Reader::Instance(filename,hal::Msg_Type_Camera) ) {
  m_reader.SetInitialImage(imageID);
  while( !ReadNextCameraMessage(m_nextMsg) ) {
    std::cout << "HAL: Initializing proto-reader..." << std::endl;
    usleep(100);
  }

  const hal::Header pbHdr = m_reader.GetHeader();
  time_t log_date((long)pbHdr.date());
  std::cout << "- Log dated " << ctime(&log_date);

  m_numChannels = m_nextMsg.image_size();
  for(size_t c=0; c < m_numChannels; ++c) {
    m_width.push_back(m_nextMsg.image(c).width());
    m_height.push_back(m_nextMsg.image(c).height());
  }
}
Esempio n. 9
0
File: log.c Progetto: 2-B/netdata
void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
	va_list args;

	log_date(stderr);

	va_start( args, fmt );
	if(debug_flags) fprintf(stderr, "INFO (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
	else            fprintf(stderr, "INFO: %s: ", program_name);
	vfprintf( stderr, fmt, args );
	va_end( args );

	fprintf(stderr, "\n");

	if(error_log_syslog) {
		va_start( args, fmt );
		vsyslog(LOG_INFO,  fmt, args );
		va_end( args );
	}
}
Esempio n. 10
0
/* Funzione utilizzata per allocare aree di memoria e settare il valore dei semafori  */
int setup() {
	log_date(LOG_PATH, "Settaggio parametri");

	// Allocazione aree di memoria
	rep = (repo *) shmat(shmid, NULL, 0);
	ls = (numlettori *) shmat(shmls, NULL, 0);
	aut = (auth *) shmat(shmauth, NULL, 0);
	pus = (push *) shmat(shmpush, NULL, 0);

	// Impostazione a 0 delle variabili contatori
	rep->n = 0;
	aut->n = 0;
	pus->n = 0;

	int po = 0;
	for(; po < SEM_TOT; po++)
		ls->n[po] = 0;

	// Settaggio seamfori
	semctl(semid, SEM_SERVER, SETVAL, MAX_SERVER - 1);
	semctl(semid, BUFFER_MUTEX, SETVAL, 1);
	semctl(semid, LS_SCRIVI, SETVAL, 1);
	semctl(semid, LS_MUTEX, SETVAL, 1);
	semctl(semid, AUTH_MUTEX, SETVAL, 1);
	semctl(semid, AUTH_SCRIVI, SETVAL, 1);
	semctl(semid, PUSH_MUTEX, SETVAL, 1);
	semctl(semid, PUSH_SCRIVI, SETVAL, 1);
	semctl(semid, QUEUE_SEM, SETVAL, QUEUE_MAX - 1);

	padre = getpid();

	writebuf("\n(start) Avvio del server completato: ID %d\n", padre);
	writebuf("\n(Aree di memora allocate)\nSEM: %d\nMSG: %d\nSHM: %d\nSHMLOG: %d\nSHMLS: %d\nSHMAUTH: %d\nSHMPUSH: %d\n\n",
			semid, msgid, shmid, shmlog, shmls, shmauth, shmpush);
	/* SIG_IGN al segnlae di terminazione dei figli
	 * i figli terminati non diventeranno zombie */
	signal(SIGCHLD, SIG_IGN);
	signal(SIGINT, server_stop);  // Forza lo spegnimento premendo ctrl + c
	// Lettura repository iniziale
	return read_repo(SERVER_INITIAL_REPO);
}
Esempio n. 11
0
File: log.c Progetto: 2-B/netdata
void log_access( const char *fmt, ... )
{
	va_list args;

	if(stdaccess) {
		log_date(stdaccess);

		va_start( args, fmt );
		vfprintf( stdaccess, fmt, args );
		va_end( args );
		fprintf( stdaccess, "\n");
#ifdef NETDATA_INTERNAL_CHECKS
		fflush( stdaccess );
#endif
	}

	if(access_log_syslog) {
		va_start( args, fmt );
		vsyslog(LOG_INFO,  fmt, args );
		va_end( args );
	}
}
Esempio n. 12
0
void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    // prevent logging too much
    if(error_log_limit(0)) return;

    log_date(stderr);

    va_start( args, fmt );
    if(debug_flags) fprintf(stderr, "%s: INFO: (%04lu@%-10.10s:%-15.15s):", program_name, line, file, function);
    else            fprintf(stderr, "%s: INFO: ", program_name);
    vfprintf( stderr, fmt, args );
    va_end( args );

    fputc('\n', stderr);

    if(error_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_INFO,  fmt, args );
        va_end( args );
    }
}
Esempio n. 13
0
void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    log_date(stderr);

    va_start( args, fmt );
    if(debug_flags) fprintf(stderr, "FATAL (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
    else            fprintf(stderr, "FATAL: %s: ", program_name);
    vfprintf( stderr, fmt, args );
    va_end( args );

    perror(" # ");
    fputc('\n', stderr);

    if(error_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_CRIT,  fmt, args );
        va_end( args );
    }

    netdata_cleanup_and_exit(1);
}
Esempio n. 14
0
int error_log_limit(int reset) {
    static time_t start = 0;
    static unsigned long counter = 0, prevented = 0;

    // do not throttle if the period is 0
    if(error_log_throttle_period == 0)
        return 0;

    // prevent all logs if the errors per period is 0
    if(error_log_errors_per_period == 0)
        return 1;

    time_t now = time(NULL);
    if(!start) start = now;

    if(reset) {
        if(prevented) {
            log_date(stderr);
            fprintf(stderr, "%s: Resetting logging for process '%s' (prevented %lu logs in the last %ld seconds).\n"
                    , program_name
                    , program_name
                    , prevented
                    , now - start
            );
        }

        start = now;
        counter = 0;
        prevented = 0;
    }

    // detect if we log too much
    counter++;

    if(now - start > error_log_throttle_period) {
        if(prevented) {
            log_date(stderr);
            fprintf(stderr, "%s: Resuming logging from process '%s' (prevented %lu logs in the last %ld seconds).\n"
                    , program_name
                    , program_name
                    , prevented
                    , error_log_throttle_period
            );
        }

        // restart the period accounting
        start = now;
        counter = 1;
        prevented = 0;

        // log this error
        return 0;
    }

    if(counter > error_log_errors_per_period) {
        if(!prevented) {
            log_date(stderr);
            fprintf(stderr, "%s: Too many logs (%lu logs in %ld seconds, threshold is set to %lu logs in %ld seconds). Preventing more logs from process '%s' for %ld seconds.\n"
                    , program_name
                    , counter
                    , now - start
                    , error_log_errors_per_period
                    , error_log_throttle_period
                    , program_name
                    , start + error_log_throttle_period - now);
        }

        prevented++;

        // prevent logging this error
        return 1;
    }

    return 0;
}
Esempio n. 15
0
int
main(int argc, char **argv)
{
    GListPtr lpc = NULL;
    gboolean process = TRUE;
    gboolean all_good = TRUE;
    enum transition_status graph_rc = -1;
    crm_graph_t *transition = NULL;
    ha_time_t *a_date = NULL;
    cib_t *cib_conn = NULL;

    xmlNode *cib_object = NULL;
    int argerr = 0;
    int flag;

    char *msg_buffer = NULL;
    gboolean optional = FALSE;
    pe_working_set_t data_set;

    const char *source = NULL;
    const char *xml_file = NULL;
    const char *dot_file = NULL;
    const char *graph_file = NULL;
    const char *input_file = NULL;
    const char *input_xml = NULL;

    /* disable glib's fancy allocators that can't be free'd */
    GMemVTable vtable;

    vtable.malloc = malloc;
    vtable.realloc = realloc;
    vtable.free = free;
    vtable.calloc = calloc;
    vtable.try_malloc = malloc;
    vtable.try_realloc = realloc;

    g_mem_set_vtable(&vtable);

    crm_log_init_quiet(NULL, LOG_CRIT, FALSE, FALSE, argc, argv);
    crm_set_options(NULL, "[-?Vv] -[Xxp] {other options}", long_options,
                    "Calculate the cluster's response to the supplied cluster state\n"
                    "\nSuperceeded by crm_simulate and likely to be removed in a future release\n\n");

    while (1) {
        int option_index = 0;

        flag = crm_get_option(argc, argv, &option_index);
        if (flag == -1)
            break;

        switch (flag) {
            case 'S':
                do_simulation = TRUE;
                break;
            case 'a':
                all_actions = TRUE;
                break;
            case 'w':
                inhibit_exit = TRUE;
                break;
            case 'X':
                /*use_stdin = TRUE;*/
                input_xml = optarg;
                break;
            case 's':
                show_scores = TRUE;
                break;
            case 'U':
                show_utilization = TRUE;
                break;
            case 'x':
                xml_file = optarg;
                break;
            case 'd':
                use_date = optarg;
                break;
            case 'D':
                dot_file = optarg;
                break;
            case 'G':
                graph_file = optarg;
                break;
            case 'I':
                input_file = optarg;
                break;
            case 'V':
                crm_bump_log_level();
                break;
            case 'L':
                USE_LIVE_CIB = TRUE;
                break;
            case '$':
            case '?':
                crm_help(flag, 0);
                break;
            default:
                fprintf(stderr, "Option -%c is not yet supported\n", flag);
                ++argerr;
                break;
        }
    }

    if (optind < argc) {
        printf("non-option ARGV-elements: ");
        while (optind < argc) {
            printf("%s ", argv[optind++]);
        }
        printf("\n");
    }

    if (optind > argc) {
        ++argerr;
    }

    if (argerr) {
        crm_err("%d errors in option parsing", argerr);
        crm_help('?', 1);
    }

    update_all_trace_data();    /* again, so we see which trace points got updated */

    if (USE_LIVE_CIB) {
        int rc = cib_ok;

        source = "live cib";
        cib_conn = cib_new();
        rc = cib_conn->cmds->signon(cib_conn, "ptest", cib_command);

        if (rc == cib_ok) {
            crm_info("Reading XML from: live cluster");
            cib_object = get_cib_copy(cib_conn);

        } else {
            fprintf(stderr, "Live CIB query failed: %s\n", cib_error2string(rc));
            return 3;
        }
        if (cib_object == NULL) {
            fprintf(stderr, "Live CIB query failed: empty result\n");
            return 3;
        }

    } else if (xml_file != NULL) {
        source = xml_file;
        cib_object = filename2xml(xml_file);

    } else if (use_stdin) {
        source = "stdin";
        cib_object = filename2xml(NULL);
    } else if (input_xml) {
        source = "input string";
        cib_object = string2xml(input_xml);
    }

    if (cib_object == NULL && source) {
        fprintf(stderr, "Could not parse configuration input from: %s\n", source);
        return 4;

    } else if (cib_object == NULL) {
        fprintf(stderr, "No configuration specified\n");
        crm_help('?', 1);
    }

    if (get_object_root(XML_CIB_TAG_STATUS, cib_object) == NULL) {
        create_xml_node(cib_object, XML_CIB_TAG_STATUS);
    }

    if (cli_config_update(&cib_object, NULL, FALSE) == FALSE) {
        free_xml(cib_object);
        return cib_STALE;
    }

    if (validate_xml(cib_object, NULL, FALSE) != TRUE) {
        free_xml(cib_object);
        return cib_dtd_validation;
    }

    if (input_file != NULL) {
        FILE *input_strm = fopen(input_file, "w");

        if (input_strm == NULL) {
            crm_perror(LOG_ERR, "Could not open %s for writing", input_file);
        } else {
            msg_buffer = dump_xml_formatted(cib_object);
            if (fprintf(input_strm, "%s\n", msg_buffer) < 0) {
                crm_perror(LOG_ERR, "Write to %s failed", input_file);
            }
            fflush(input_strm);
            fclose(input_strm);
            crm_free(msg_buffer);
        }
    }

    if (use_date != NULL) {
        a_date = parse_date(&use_date);
        log_date(LOG_WARNING, "Set fake 'now' to", a_date, ha_log_date | ha_log_time);
        log_date(LOG_WARNING, "Set fake 'now' to (localtime)",
                 a_date, ha_log_date | ha_log_time | ha_log_local);
    }

    set_working_set_defaults(&data_set);
    if (process) {
        if (show_scores && show_utilization) {
            fprintf(stdout, "Allocation scores and utilization information:\n");
        } else if (show_scores) {
            fprintf(stdout, "Allocation scores:\n");
        } else if (show_utilization) {
            fprintf(stdout, "Utilization information:\n");
        }
        do_calculations(&data_set, cib_object, a_date);
    }

    msg_buffer = dump_xml_formatted(data_set.graph);
    if (safe_str_eq(graph_file, "-")) {
        fprintf(stdout, "%s\n", msg_buffer);
        fflush(stdout);
    } else if (graph_file != NULL) {
        FILE *graph_strm = fopen(graph_file, "w");

        if (graph_strm == NULL) {
            crm_perror(LOG_ERR, "Could not open %s for writing", graph_file);
        } else {
            if (fprintf(graph_strm, "%s\n\n", msg_buffer) < 0) {
                crm_perror(LOG_ERR, "Write to %s failed", graph_file);
            }
            fflush(graph_strm);
            fclose(graph_strm);
        }
    }
    crm_free(msg_buffer);

    if (dot_file != NULL) {
        dot_strm = fopen(dot_file, "w");
        if (dot_strm == NULL) {
            crm_perror(LOG_ERR, "Could not open %s for writing", dot_file);
        }
    }

    if (dot_strm == NULL) {
        goto simulate;
    }

    init_dotfile();
    for (lpc = data_set.actions; lpc != NULL; lpc = lpc->next) {
        action_t *action = (action_t *) lpc->data;
        const char *style = "filled";
        const char *font = "black";
        const char *color = "black";
        const char *fill = NULL;
        char *action_name = create_action_name(action);

        crm_trace("Action %d: %p", action->id, action);

        if (is_set(action->flags, pe_action_pseudo)) {
            font = "orange";
        }

        style = "dashed";
        if (is_set(action->flags, pe_action_dumped)) {
            style = "bold";
            color = "green";

        } else if (action->rsc != NULL && is_not_set(action->rsc->flags, pe_rsc_managed)) {
            color = "purple";
            if (all_actions == FALSE) {
                goto dont_write;
            }

        } else if (is_set(action->flags, pe_action_optional)) {
            color = "blue";
            if (all_actions == FALSE) {
                goto dont_write;
            }

        } else {
            color = "red";
            CRM_CHECK(is_set(action->flags, pe_action_runnable) == FALSE,;
                );
        }

        set_bit_inplace(action->flags, pe_action_dumped);
        dot_write("\"%s\" [ style=%s color=\"%s\" fontcolor=\"%s\"  %s%s]",
                  action_name, style, color, font, fill ? "fillcolor=" : "", fill ? fill : "");
  dont_write:
        crm_free(action_name);
    }
Esempio n. 16
0
void
log_time_period(int log_level, ha_time_period_t * dtp, int flags)
{
    log_date(log_level, "Period start:", dtp->start, flags);
    log_date(log_level, "Period end:", dtp->end, flags);
}
Esempio n. 17
0
/* Funzione utilizzata per disallocare le risorse  */
void server_stop() {
	int notread = 1;
	//Stampa i messagggi in coda
	while (number_msges_in_queue(msgid) != 0) {
		msgrcv(msgid, &req, msgl, 0, 0);
		writebuf("(messaggio) %d - pid %d - todo: %d tip: %ld\n", notread++,
				req.pid, req.todo, req.tipo);
	}
	termina_push();  //Termino i push

	// Scrittura su file del buffer
	buffer *log;
	log = (buffer *) shmat(shmlog, NULL, 0);
	if (log->n > 0) writelog(LOG_PATH, log->text, "a");
	shmdt(log);

	// Salvo il repository attuale del server
	char mypack[MAX_STR + 5];int
	i = 0;
	char pidlog[25];
	sprintf(pidlog, "%s_%d.repo", LOG_PATH, padre);
	log_date(pidlog, "(shutdown) Salvataggio repository su file");
	for (; i < rep->n; i++) {
		sprintf(mypack, "%s %d\n", rep->lista[i].nome, rep->lista[i].ver);
		writelog(pidlog, mypack, "a");
	}
	
	shmdt(rep); shmdt(aut); shmdt(pus); shmdt(ls);
	
	// Rimozione risorse allocate
	if (semctl(semid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere semafori");
	if (shmctl(shmid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria Repository");
	if (shmctl(shmlog, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria LOG");
	if (shmctl(shmls, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria LETTORI/SCRITTORI");
	if (shmctl(shmauth, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria AUTORIZZAZIONI");
	if (shmctl(shmpush, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria PUSH");
	if (msgctl(msgid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere coda messaggi");

	//Statistiche
	log_date(LOG_PATH, "(stats) ");
	log_date(LOG_PATH, "(stats) %d richieste elaborate", counter_r);
	log_date(LOG_PATH, "(stats) %d richieste di download", counter_d);
	log_date(LOG_PATH, "(stats) %d richieste di upload", counter_u);
	log_date(LOG_PATH, "(stats) %d autorizzazioni client push", counter_p);
	log_date(LOG_PATH, "(stats) %d autorizzazioni client upload", counter_a);
	log_date(LOG_PATH, "(stats) Data di accensione\t --> %s", start_date);
	get_date(start_date);
	log_date(LOG_PATH, "(stats) Data di spegnimento\t --> %s", start_date);
	log_date(LOG_PATH, "(stats) ");

	log_date(LOG_PATH, "(shutdown) Spegnimento server completato");
	exit(0);
}
Esempio n. 18
0
int
main(int argc, char **argv)
{
    int argerr = 0;
    int flag;
    int index = 0;
    int print_options = 0;
    char *input_s = NULL;
    char *mutable_s = NULL;

    crm_log_cli_init("iso8601");
    crm_set_options(NULL, "command [output modifier] ", long_options,
                    "Display and parse ISO8601 dates and times");

    if (argc < 2) {
        argerr++;
    }

    while (1) {
        flag = crm_get_option(argc, argv, &index);
        if (flag == -1)
            break;

        switch (flag) {
            case 'V':
                crm_bump_log_level();
                break;
            case '?':
            case '$':
                crm_help(flag, 0);
                break;
            case 'n':
                command = flag;
                break;
            case 'd':
            case 'p':
            case 'D':
                command = flag;
                input_s = strdup(optarg);
                break;
            case 'W':
                print_options |= ha_date_weeks;
                break;
            case 'O':
                print_options |= ha_date_ordinal;
                break;
            case 'L':
                print_options |= ha_log_local;
                break;
        }
    }

    if (input_s == NULL && command != 'n') {
        crm_help('?', 1);
    }

    mutable_s = input_s;

    if (command == 'd') {
        ha_time_t *date_time = parse_date(&mutable_s);

        if (date_time == NULL) {
            fprintf(stderr, "Invalid date/time specified: %s\n", input_s);
            crm_help('?', 1);
        }
        log_date(-1, "parsed", date_time, print_options | ha_log_date | ha_log_time);

    } else if (command == 'p') {
        ha_time_period_t *interval = parse_time_period(&mutable_s);

        if (interval == NULL) {
            fprintf(stderr, "Invalid interval specified: %s\n", input_s);
            crm_help('?', 1);
        }
        log_time_period(-1, interval, print_options | ha_log_date | ha_log_time);

    } else if (command == 'D') {
        ha_time_t *duration = parse_time_duration(&mutable_s);

        if (duration == NULL) {
            fprintf(stderr, "Invalid duration specified: %s\n", input_s);
            crm_help('?', 1);
        }
        log_date(-1, "Duration", duration,
                 print_options | ha_log_date | ha_log_time | ha_log_local);

    } else if (command == 'n') {
        ha_time_t *now = new_ha_date(TRUE);

        if (now == NULL) {
            fprintf(stderr, "Internal error: couldnt determin 'now' !\n");
            crm_help('?', 1);
        }
        log_date(-1, "Current date/time", now, print_options | ha_log_date | ha_log_time);
    }

    return 0;
}