Beispiel #1
0
/* This function will check the last reboot status. If the reboot is HARD reboot or due to 
   power failure, it will send the last stored logs to the upload queue*/
void check_last_reboot(void)
{
	FILE *fp;
	char status[50], file_path[FILE_PATH_LENGTH], time_buf[50], cmd[250];
	memset(status, 0, sizeof(status));
	memset(file_path, 0, sizeof(file_path));
	memset(time_buf, 0, sizeof(time_buf));

	DEBUG("%s : checking last reboot status...\n", __func__);
	fp = fopen(SYSTEM_REBOOT_STATUS_FILE, "r");
	if(fp == NULL)
	{
		ERROR("%s : Unable to open file \"%s\". Returning...\n", __func__, SYSTEM_REBOOT_STATUS_FILE);
		return;
	}
	fscanf(fp, "%s", status);
	fclose(fp);

	if(file_is_present(SYSTEM_SERVER_LOG_FILE) == FAIL)
	{
		ERROR("%s : returning...\n", __func__);
		return;
	}

	get_time_string(time_buf);
	if(!strcmp(status, "system_server_test"))
	{
		DEBUG("%s : Last reboot was not normal... Sending the last system_server_test logs to upload queue...\n", __func__);
		sprintf(file_path, "%stest_%s.log", SYSTEM_LOG_PATH, time_buf);
		sprintf(cmd, "cp %s %s", SYSTEM_SERVER_LOG_FILE, file_path);
		system(cmd);

		sprintf(cmd, "echo 0>%s",SYSTEM_SERVER_LOG_FILE);
		system(cmd);

		enqueue_upload_file_list(LOG_FILE, file_path);
	}
	else if(!strcmp(status, "system_server"))
	{
		DEBUG("%s : Last reboot was not normal... Sending the last system_server logs to upload queue...\n", __func__);
		sprintf(file_path, "%ssystem_%s.log", SYSTEM_LOG_PATH, time_buf);
		sprintf(cmd, "cp %s %s", SYSTEM_SERVER_LOG_FILE, file_path);
		system(cmd);

		sprintf(cmd, "echo 0>%s",SYSTEM_SERVER_LOG_FILE);
		system(cmd);

		enqueue_upload_file_list(LOG_FILE, file_path);
	}
	else
	{
		DEBUG("%s : Last reboot was normal...\n", __func__);
	}
	return;
}
Beispiel #2
0
void log_handler(int signo)
{
	char status[50], file_path[FILE_PATH_LENGTH], time_buf[50], cmd[250];
	DEBUG("%s : Recieved signal %d. Managing log...\n", __func__, signo);
	alarm(SYSTEM_SERVER_LOG_INTERVAL);

	if(file_is_present(SYSTEM_SERVER_LOG_FILE) == FAIL)
	{
		ERROR("%s : returning...\n", __func__);
		return;
	}

	get_time_string(time_buf);
	sprintf(file_path, "%ssystem_%s.log", SYSTEM_LOG_PATH, time_buf);
	sprintf(cmd, "cp %s %s", SYSTEM_SERVER_LOG_FILE, file_path);
	system(cmd);

	sprintf(cmd, "echo 0>%s",SYSTEM_SERVER_LOG_FILE);
	system(cmd);

	enqueue_upload_file_list(LOG_FILE, file_path);
	return;
}
Beispiel #3
0
void update_files_from_archive(int number_of_argument, char** files) {
	int i = first_argument_position;
	FILE* archive = fopen(files[i], "r+");
	errno = 0;

	if(archive != NULL && errno == 0) {
		erase_ending_null_block(archive, files[i]);
		fclose(archive);
		archive = NULL;
		errno = 0;
		i++;
	}
	else
		goto error;

	if(VERBOSE_FLAG)
		printf("Mise à jour de fichier(s) de l'archive '%s' en cours...\n", 
											files[first_argument_position]);

	do {
		archive = fopen(files[first_argument_position], "r+");

		if(archive != NULL && errno == 0) {
			errno = 0;
			FILE_HEADER new_file_header;
			build_ustar_header_from_file(&new_file_header, files[i]);

			int file_position = file_is_present(new_file_header.name, 
												new_file_header.prefix,
												archive);

			if(file_position != -1) {
				fseek(archive, file_position, SEEK_SET);

				FILE_HEADER current_file_header;
				build_ustar_header_from_archive(&current_file_header,
												archive);

				if( atoi(current_file_header.mtime) <
					atoi(new_file_header.mtime) ) {
					FILE* new_file = fopen(files[i], "r");

					if(new_file != NULL && errno == 0) {
						delete_file(file_position, archive, 
											files[first_argument_position]);

						if(archive != NULL) {
							fseek(archive, 0, SEEK_END);
							add_file(&new_file_header, new_file, archive);
						}
						else
							goto error;

						fclose(new_file);
						new_file = NULL;

						if(VERBOSE_FLAG)
							printf("'%s' a été mis à jour.\n", files[i]);
					}
					else {
						fprintf(stderr, "%s '%s' : %s\n", OPENING_ERR, 
												files[i], strerror(errno));
						fprintf(stderr, "%s '%s'\n", UPDATE_ERR, files[i]);
					}
				}
				else
					if(VERBOSE_FLAG)
						printf("'%s' est déjà à jour.\n", files[i]);
			}
			else
				fprintf(stderr, "%s: %s\n", FILE_NOT_FOUND_ERR, files[i]);
		}
		else
			goto error;

		i++;

		if(i == number_of_argument)
			write_null_block(archive);

		fclose(archive);
		archive = NULL;
	} while(i < number_of_argument);

// Here is a jump in case of an error during opening the archive
error:
	// Avoid a wrong error display at the end of the function
	if(i != number_of_argument)
		fprintf(stderr, "%s '%s' : %s\n", OPENING_ERR, files[i],
															strerror(errno));
}