コード例 #1
0
ファイル: flog.c プロジェクト: lpeano/qm_databse
void flog ( int level, char *message, ...) {
	va_list ap;
	char buffer[1000];

	memset(buffer,0,1000);

	if ( fd_log < 0 ) {
		fd_log = 0;
		stream_log=fdopen(fd_log,"a+");
	}
	if ( level <= log_level ) 
	{
		stream_log=fdopen(fd_log,"a+");
		va_start(ap,message);
		//vfprintf(stream_log,message,ap);
		vsnprintf(buffer,1000,message,ap);
		if( level <0 )
		       	fprintf(stream_log," [ %s ] - [ %s ] : %s\n",get_file_time(),"LOG_ERROR",buffer);
		else
			fprintf(stream_log," [ %s ] - [ %s ] : %s\n",get_file_time(),decoded_level[level-1],buffer);
		va_end(ap);
		fflush(stream_log);

	}
}
コード例 #2
0
ファイル: FileInfoHandler.cpp プロジェクト: flyfaster/toysrc
void PrivateFileInfoHandler::do_read(PtrTcpConnection tcp_connection)
{
    if (total_bytes_read < 4)
    {
        tcp_connection->do_read(boost::asio::buffer(buffer_.data()+total_bytes_read, 4-total_bytes_read));
        return;
    }
    // then read file name
    if (filename_length<=0)
    {
        memcpy(&filename_length, buffer_.data(), sizeof(filename_length));
    }
    if (filename_length + 4 > total_bytes_read)
        tcp_connection->do_read(boost::asio::buffer(buffer_.data()+total_bytes_read, filename_length+4-total_bytes_read));
    else
    {
        // file name is available
        FileInfo file_info;
        memset(&file_info, 0, sizeof(file_info));
        buffer_[filename_length+4] = 0;
        file_name = buffer_.data() + 4;
        int ret = get_file_time(file_name.c_str(), file_info);
        // get CRC32
        ret = get_crc(file_name.c_str(), file_info.crc32);
        memcpy(buffer_.data(), &file_info, sizeof(file_info));
        do_write(tcp_connection);
    }

}
コード例 #3
0
ファイル: crashreport.c プロジェクト: RanadeepPolavarapu/IRCd
void crash_report_header(FILE *reportfd, char *coredump)
{
	char buf[512];
	time_t t;
	
	fprintf(reportfd, "== UNREALIRCD CRASH REPORT ==\n"
	                  "\n"
	                  "SYSTEM INFORMATION:\n");
	
	fprintf(reportfd, "UnrealIRCd version: %s\n", VERSIONONLY);
#if defined(__VERSION__)
	fprintf(reportfd, "          Compiler: %s\n", __VERSION__);
#endif
	
	fprintf(reportfd, "  Operating System: %s\n", MYOSNAME);

	
	fprintf(reportfd, "Using core file: %s\n", coredump);
	
	t = get_file_time(coredump);
	if (t != 0)
	{
		fprintf(reportfd, "Crash date/time: %s\n", myctime(t) ? myctime(t) : "???");
		fprintf(reportfd, " Crash secs ago: %ld\n",
			(long)(time(NULL) - t));
	} else {
		fprintf(reportfd, "Crash date/time: UNKNOWN\n");
		fprintf(reportfd, " Crash secs ago: UNKNOWN\n");
	}
	
	fprintf(reportfd, "\n");
}
コード例 #4
0
ファイル: uws_http.c プロジェクト: codesaler/uws
static void
printfile(const char *path, pConnInfo conn_info)
{
    char *mod_time_str ;
    char *file_mod_time = get_file_time(path);
    if((mod_time_str = get_header_param("If-Modified-Since", conn_info->request_header))) {
        if(!is_expire(mod_time_str, file_mod_time)) {
            conn_info->status_code = 304;
            send_error_response(conn_info);
            return;
        }
    }

    FILE* file = fopen(path, "r");
    fseek(file, 0, SEEK_END);
    header_body.content_len = ftell(file);
    rewind(file);

    add_header_param("Last-Modified", file_mod_time, conn_info->response_header);
    uws_free(file_mod_time);

    header_body.content = (char*) uws_malloc (header_body.content_len * sizeof(char));
    size_t read_size = fread(header_body.content, sizeof(char), header_body.content_len, file);
    fclose(file);

}
コード例 #5
0
ファイル: crashreport.c プロジェクト: RanadeepPolavarapu/IRCd
/** Checks if the binary is newer than the coredump.
 * If that's the case (1) then the core dump is likely not very usable.
 */
int corefile_vs_binary_mismatch(char *coredump)
{
#ifndef _WIN32
	time_t core, binary;
	char fname[512];
	
	snprintf(fname, sizeof(fname), "%s/unrealircd", BINDIR);
	
	core = get_file_time(coredump);
	binary = get_file_time(fname);
	
	if (!core || !binary)
		return 0; /* don't know then */
	
	if (binary > core)
		return 1; /* yup, mismatch ;/ */
	
	return 0; /* GOOD! */
#else
	return 0; /* guess we don't check this on Windows? Or will we check UnrealIRCd.exe... hmm.. yeah maybe good idea */
#endif
}
コード例 #6
0
ファイル: winbox.cpp プロジェクト: trumanzhao/misc
void winbox::load_script()
{
	m_entry_time  = get_file_time(g_entry);

	if (luaL_dofile(m_lvm, g_entry) != 0)
	{
		const char* err = lua_tostring(m_lvm, -1);
		if (err)
		{
			log_err(err);
		}
	}
}
コード例 #7
0
ファイル: wtplib.c プロジェクト: imatix/Xitami-25
qbyte
wtp_signature (
    const char *filename)               /*  Name of executable program       */
{
    static char
        signature [30];

    /*  Signature is XXXXXXXX-XXXXXXXX-XXXXXXXX  (hash-size-time)            */
    /*  then passed through 32-bit CRC calculation.                          */
    sprintf (signature, "%08lX-%08lX-%08lX",
                         strhash (filename),
                         get_file_size (filename),
                         get_file_time (filename));

    return (calculate_crc ((byte *) signature, strlen (signature)));
}
コード例 #8
0
ファイル: winbox.cpp プロジェクト: trumanzhao/misc
void winbox::on_timer()
{
	m_frame++;
	time_t filetime = get_file_time(g_entry);
	if (filetime != m_entry_time)
	{
		m_entry_time = filetime;
		load_script();
	}

	InvalidateRect(m_hwnd, nullptr, false);

	std::string err;
	lua_guard g(m_lvm);
	lua_call_object_function(err, m_lvm, this, "on_timer");
	log_err(err.c_str());
}
コード例 #9
0
ファイル: crashreport.c プロジェクト: RanadeepPolavarapu/IRCd
void report_crash(void)
{
	char *coredump, *fname;
	int crashed_secs_ago;

	if (!running_interactive() && (report_pref != REPORT_AUTO))
		exit(0); /* don't bother if we run through cron or something similar */

	coredump = find_best_coredump();
	if (!coredump)
		return; /* no crashes */

	crashed_secs_ago = time(NULL) - get_file_time(coredump);
	if (crashed_secs_ago > 86400*7)
		return; /* stop bothering about it after a while */

	fname = generate_crash_report(coredump);
	
	if (!fname)
		return;
		
#ifndef _WIN32
	printf("The IRCd has been started now (and is running), but it did crash %d seconds ago.\n", crashed_secs_ago);
	printf("Crash report generated in: %s\n\n", fname);
		
	if (report_pref == REPORT_NEVER)
	{
		printf("Crash report will not be sent to UnrealIRCd Team.\n\n");
		printf("Feel free to read the report at %s and if you change your mind you can submit it anyway at https://bugs.unrealircd.org/\n", fname);
	} else
	if (report_pref == REPORT_ASK)
	{
		char answerbuf[64], *answer;
		printf("May I send a crash report to the UnrealIRCd developers?\n");
		printf("Crash reports help us greatly with fixing bugs that affect you and others\n");
		printf("\n");
		
		do
		{
			printf("Answer (Y/N): ");
			*answerbuf = '\0';
			answer = fgets(answerbuf, sizeof(answerbuf), stdin);
			
			if (answer && (toupper(*answer) == 'N'))
			{
				printf("Ok, not sending bug report.\n\n");
				printf("Feel free to read the report at %s and if you change your mind you can submit it anyway at https://bugs.unrealircd.org/\n", fname);
				return;
			}
			if (answer && (toupper(*answer) == 'Y'))
			{
				break;
			}
			
			printf("Invalid response. Please enter either Y or N\n\n");
		} while(1);
	} else if (report_pref != REPORT_AUTO)
	{
		printf("Huh. report_pref setting is weird. Aborting.\n");
		return;
	}

	if (running_interactive())
	{
		char buf[8192], *line;

		printf("\nDo you want to give your e-mail address so we could ask for additional information or "
		       "give you feedback about the crash? This is completely optional, just press ENTER to skip.\n\n"
		       "E-mail address (optional): ");
		line = fgets(buf, sizeof(buf), stdin);
		
		if (line && *line && (*line != '\n'))
		{
			FILE *fd = fopen(fname, "a");
			if (fd)
			{
				fprintf(fd, "\nUSER E-MAIL ADDRESS: %s\n", line);
				fclose(fd);
			}
		}

		printf("\nDo you have anything else to tell about the crash, maybe the circumstances? You can type 1 single line\n"
		       "Again, this is completely optional. Just press ENTER to skip.\n\n"
		       "Additional information (optional): ");
		line = fgets(buf, sizeof(buf), stdin);
		
		if (line && *line && (*line != '\n'))
		{
			FILE *fd = fopen(fname, "a");
			if (fd)
			{
				fprintf(fd, "\nCOMMENT BY USER: %s\n", line);
				fclose(fd);
			}
		}
	}
	if (crashreport_send(fname))
	{
		printf("\nThe crash report has been sent to the UnrealIRCd developers. "
		       "Thanks a lot for helping to make UnrealIRCd a better product!\n\n");
	}
#else
	/* Windows */
	if (MessageBox(NULL, "UnrealIRCd crashed. May I send a report about this to the UnrealIRCd developers? This helps us a lot.",
	                     "UnrealIRCd crash",
	                     MB_YESNO|MB_ICONQUESTION) == IDYES)
	{
		/* Yay */
		
		if (crashreport_send(fname))
		{
			MessageBox(NULL, "The crash report has been sent to the UnrealIRCd developers. Thanks a lot for helping to make UnrealIRCd a better product!",
			           "UnrealIRCd crash report sent", MB_ICONINFORMATION|MB_OK);
		}
	}
#endif
	mark_coredump_as_read(coredump);
	
#ifdef _WIN32
	if (MessageBox(NULL, "Start UnrealIRCd again?",
	                     "UnrealIRCd crash",
	                     MB_YESNO|MB_ICONQUESTION) == IDYES)
	{
		StartUnrealAgain();
	}
#endif
}
コード例 #10
0
ファイル: crashreport.c プロジェクト: RanadeepPolavarapu/IRCd
char *find_best_coredump(void)
{
	static char best_fname[512];
	TS best_time = 0, t;
	struct dirent *dir;
#ifndef _WIN32
	DIR *fd = opendir(TMPDIR);

	if (!fd)
		return NULL;
	
	*best_fname = '\0';
	
	while ((dir = readdir(fd)))
	{
		char *fname = dir->d_name;
		if (strstr(fname, "core") && !strstr(fname, ".so") &&
		    !strstr(fname, ".conf") && !strstr(fname, ".txt") &&
		    !strstr(fname, ".done"))
		{
			char buf[512];
			
			snprintf(buf, sizeof(buf), "%s/%s", TMPDIR, fname);
			t = get_file_time(buf);
			if (t && (t > best_time))
			{
				best_time = t;
				strlcpy(best_fname, buf, sizeof(best_fname));
			}
		}
	}
	closedir(fd);
#else
	/* Windows */
	WIN32_FIND_DATA hData;
	HANDLE hFile;
	
	hFile = FindFirstFile("unrealircd.*.core", &hData);
	if (hFile == INVALID_HANDLE_VALUE)
		return NULL;
	
	while (FindNextFile(hFile, &hData))
	{
		char *fname = hData.cFileName;
		if (!strstr(fname, ".done"))
		{
			char buf[512];
			strlcpy(buf, fname, sizeof(buf));
			t = get_file_time(buf);
			if (t && (t > best_time))
			{
				best_time = t;
				strlcpy(best_fname, buf, sizeof(best_fname));
			}
		}
	}
	FindClose(hFile);
#endif	
	
	if (*best_fname)
		return best_fname;
	
	return NULL; /* none found */
}
コード例 #11
0
ファイル: ctime_001_pos.c プロジェクト: marcelhuberfoo/zfs
/* ARGSUSED */
int
main(int argc, char *argv[])
{
	int i, ret, fd;
	char *penv[] = {"TESTDIR", "TESTFILE0"};

	(void) fprintf(stdout, "Verify [acm]time is modified appropriately.\n");
	(void) atexit(cleanup);

	/*
	 * Get the environment variable values.
	 */
	for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
		if ((penv[i] = getenv(penv[i])) == NULL) {
			(void) fprintf(stderr, "getenv(penv[%d])\n", i);
			return (1);
		}
	}
	(void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]);

	/*
	 * If the test file is exists, remove it first.
	 */
	if (access(tfile, F_OK) == 0) {
		(void) unlink(tfile);
	}
	ret = 0;
	if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
		(void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
		return (1);
	}
	(void) close(fd);

	for (i = 0; i < NCOMMAND; i++) {
		time_t t1, t2;

		/*
		 * Get original time before operating.
		 */
		ret = get_file_time(tfile, timetest_table[i].type, &t1);
		if (ret != 0) {
			(void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
			    tfile, timetest_table[i].type, ret);
			return (1);
		}

		/*
		 * Sleep 2 seconds, then invoke command on given file
		 */
		(void) sleep(2);
		timetest_table[i].func(tfile);

		/*
		 * Get time after operating.
		 */
		ret = get_file_time(tfile, timetest_table[i].type, &t2);
		if (ret != 0) {
			(void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
			    tfile, timetest_table[i].type, ret);
			return (1);
		}

		if (t1 == t2) {
			(void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
			    timetest_table[i].name, (long)t1, (long)t2);
			return (1);
		} else {
			(void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
			    timetest_table[i].name, (long)t1, (long)t2);
		}
	}

	(void) fprintf(stdout, "PASS\n");
	return (0);
}
コード例 #12
0
ファイル: ctime_001_pos.c プロジェクト: cephpp/test
void
main(int argc, char *argv[])
{
	int i, ret, fd;
	char *penv[] = {"mnt", "test_file"};

	log_assert("Verify access time will be changed when file data" \
	    "was last accessed.");
	log_onexit(cleanup);

	/*
	 * Get envirnment variable value
	 */
/*	for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
		if ((penv[i] = getenv(penv[i])) == NULL) {
			log_must(-1, "getenv(penv[i])");
		}
	}*/
	(void) snprintf(tfile, sizeof (tfile), "%s/%s", "/tank/zfs","test_file");

	/*
	 * If the test file is existing, remove it firstly
	 */

        printf("file :  %s\n", tfile);
   
	if (access(tfile, F_OK) == 0) {
		unlink(tfile);
	}
	ret = 0;
	if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
		ret = errno;
	}
	if (fd != -1) {
		(void) close(fd);
	}
	(void) snprintf(msg, sizeof (msg), \
	    "open(%s, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)", tfile);
	log_must(ret, msg);

	for (i = 5; i < NCOMMAND; i++) {
		time_t t1, t2;

		/*
		 * Get original time before operating.
		 */

		ret = get_file_time(tfile, timetest_table[i].type, &t1);
		if (ret != 0) {
			(void) snprintf(msg, sizeof (msg),
			    "get_file_time(%s, %d, &t1)",
			    tfile, timetest_table[i].type);
			log_must(ret, msg);
		}

		/*
		 * Sleep 2 seconds, then invoke command on givin file
		 */
		sleep(2);
		timetest_table[i].func(tfile);

		/*
		 * Get time after operating.
		 */
		ret = get_file_time(tfile, timetest_table[i].type, &t2);
		if (ret != 0) {
			(void) snprintf(msg, sizeof (msg),
			    "get_file_time(%s, %d, &t2)",
			    tfile, timetest_table[i].type);
			log_must(ret, msg);
		}

		if (t1 == t2) {
			snprintf(msg, sizeof (msg), "%s: t1(%ld) == t2(%ld)",
			    timetest_table[i].name, (long)t1, (long)t2);
			log_must(-1, msg);
		} else {
			snprintf(msg, sizeof (msg), "%s: t1(%ld) != t2(%ld)",
			    timetest_table[i].name, (long)t1, (long)t2);
			log_must(0, msg);
		}
	}

	(void) unlink(tfile);

	log_pass("Verify access time will be changed passed.");
}
コード例 #13
0
ErrorCode MinizipUtils::add_file(zipFile zf,
                                 const std::string &name,
                                 const std::string &path)
{
    // Copy file into archive
    StandardFile file;
    int ret;

    auto open_ret = FileUtils::open_file(file, path,
                                         FileOpenMode::ReadOnly);
    if (!open_ret) {
        LOGE("%s: Failed to open for reading: %s",
             path.c_str(), open_ret.error().message().c_str());
        return ErrorCode::FileOpenError;
    }

    auto size = file.seek(0, SEEK_END);
    if (!size) {
        LOGE("%s: Failed to seek file: %s",
             path.c_str(), size.error().message().c_str());
        return ErrorCode::FileSeekError;
    }
    auto seek_ret = file.seek(0, SEEK_SET);
    if (!seek_ret) {
        LOGE("%s: Failed to seek file: %s",
             path.c_str(), seek_ret.error().message().c_str());
        return ErrorCode::FileSeekError;
    }

    bool zip64 = size.value() >= ((1ull << 32) - 1);

    zip_fileinfo zi;
    memset(&zi, 0, sizeof(zi));

    if (!get_file_time(path, &zi.dos_date)) {
        LOGE("%s: Failed to get modification time", path.c_str());
        return ErrorCode::FileOpenError;
    }

    ret = zipOpenNewFileInZip2_64(
        zf,                     // file
        name.c_str(),           // filename
        &zi,                    // zip_fileinfo
        nullptr,                // extrafield_local
        0,                      // size_extrafield_local
        nullptr,                // extrafield_global
        0,                      // size_extrafield_global
        nullptr,                // comment
        Z_DEFLATED,             // method
        Z_DEFAULT_COMPRESSION,  // level
        0,                      // raw
        zip64                   // zip64
    );

    if (ret != ZIP_OK) {
        LOGE("minizip: Failed to open inner file: %s",
             zip_error_string(ret).c_str());

        return ErrorCode::ArchiveWriteDataError;
    }

    // Write data to file
    char buf[32768];

    while (true) {
        auto bytes_read = file.read(buf, sizeof(buf));
        if (!bytes_read) {
            LOGE("%s: Failed to read data: %s",
                 path.c_str(), bytes_read.error().message().c_str());
            zipCloseFileInZip(zf);

            return ErrorCode::FileReadError;
        } else if (bytes_read.value() == 0) {
            break;
        }

        ret = zipWriteInFileInZip(
                zf, buf, static_cast<uint32_t>(bytes_read.value()));
        if (ret != ZIP_OK) {
            LOGE("minizip: Failed to write inner file data: %s",
                 zip_error_string(ret).c_str());
            zipCloseFileInZip(zf);

            return ErrorCode::ArchiveWriteDataError;
        }
    }

    ret = zipCloseFileInZip(zf);
    if (ret != ZIP_OK) {
        LOGE("minizip: Failed to close inner file: %s",
             zip_error_string(ret).c_str());

        return ErrorCode::ArchiveWriteDataError;
    }

    return ErrorCode::NoError;
}
コード例 #14
0
ファイル: sflini.c プロジェクト: cookrn/openamq
SYMTAB *
ini_dyn_load (
    SYMTAB *load_symtab,
    const char *filename)
{
    FILE
        *inifile;
    SYMTAB
        *symtab,                        /*  Symbol table to populate         */
        *envtab;                        /*  Environment, as symbol table     */
    char
        *section = NULL,                /*  Filled as we scan through        */
        *keyword = NULL,                /*    the ini file                   */
        *value   = NULL,
        *fromptr,
        *toptr,
        *section_end;                   /*  Null byte at end of section      */

    ASSERT (filename);
    inifile = file_locate ("PATH", filename, NULL);

    if (load_symtab)                    /*  Use specified symbol table       */
        symtab = load_symtab;           /*    or create a new one            */
    else {
        symtab = sym_create_table ();
        if (symtab == NULL)
            return (NULL);              /*  Quit if insufficient memory      */
    }
    /*  Store control variables in symbol table                              */
    if (inifile || load_symtab == NULL) {
        sym_assume_symbol (symtab, "filename", filename);
        snprintf (iniline, sizeof (iniline), "%ld",
            timer_to_date (get_file_time (filename)));
        sym_assume_symbol (symtab, "filedate", iniline);
        snprintf (iniline, sizeof (iniline), "%ld",
            timer_to_time (get_file_time (filename)));
        sym_assume_symbol (symtab, "filetime", iniline);
    }
    if (!inifile)
        return (symtab);                /*  File not found; empty table      */

    /*  Now load the ini file, starting from the beginning                   */
    envtab = env2symb ();
    fseek (inifile, 0, SEEK_SET);
    FOREVER
      {
        if (ini_scan_section (inifile, &keyword, &value))
          {
            if (section)
              {
                section_end = strchr (section, '\0');
                ASSERT (section_end);
                xstrcat (section, ":", keyword, NULL);
                value = tok_subst (value, envtab);

                /*  Handle value in quotes                                   */
                if (*value == '"')
                  {
                    /*  Unescape value if necessary                          */
                    if (strchr (value, '\\'))
                      {
                        toptr = value;
                        for (fromptr = value; *fromptr; fromptr++)
                          {
                            if (*fromptr == '\\')
                              {
                                fromptr++;
                                if (*fromptr == 'n')
                                    *toptr++ = '\n';
                                else
                                    *toptr++ = *fromptr;
                              }
                            else
                                *toptr++ = *fromptr;
                          }
                        *toptr = '\0';
                      }
                    strlast (value) = '\0'; 
                    sym_assume_symbol (symtab, section, value + 1);
                  }
                else
                    sym_assume_symbol (symtab, section, value);

                mem_strfree (&value);
                *section_end = '\0';
              }
          }
        else
        if (keyword)                    /*  Found new section                */
          {
            section = keyword;
            sym_assume_symbol (symtab, section, "");
          }
        else
            break;
      }
    file_close (inifile);
    sym_delete_table (envtab);
    sym_sort_table (symtab, NULL);      /*  Sort table by symbol name        */
    return (symtab);
}