示例#1
0
int
main(int argc, char **argv)
{
    if (argc < 2) {
        (void) fprintf(stderr, "Usage: %s <command> ...\n", argv[0]);
        exit(1);
    }

    rotate_logs();
    redirect_output();
    dump_privs();
    dump_args(argc, argv);

    /* print the header for the output from the program we exec (pre-flush) */
    (void) puts("=== OUTPUT ===");

    /* flush before next cmd takes over */
    (void) fflush(stdout);
    (void) fflush(stderr);

    exec_next(argc, argv);

    /* if we got here, we failed */
    (void) fprintf(stderr, "FATAL: execvp() failed.\n");
    exit(1);
}
示例#2
0
/*
 * function write sendkafka log info to local
 * file the path will depend on usr configure
 * default /var/log/sendkafka
 */
void save_error_tolocal(char *errlogpath, char *errinfo)
{

	if (NULL != errinfo) {

		int len = strlen(errinfo)+1;
		char *perrinfo = calloc(1,len+50);
		strcpy(perrinfo,getcurrenttime());
		perrinfo[strlen(perrinfo)-1]='|';
		strncat(perrinfo,errinfo,len+50-1);	

		rotate_logs(errlogpath);

		int fd = open(errlogpath, O_WRONLY | O_APPEND | O_CREAT, 0666);

		if (fd == -1) {
			char buf[1080] = { 0 };
			sprintf(buf, "%d line open %s fail...", __LINE__ - 4,errlogpath);

			perror(buf);
			free(perrinfo);
			perrinfo=NULL;
			exit(4);
		}

		write(fd, perrinfo, strlen(perrinfo));
		close(fd);
		free(perrinfo);
		perrinfo=NULL;
	}


}
示例#3
0
int
main(int argc, char **argv)
{
    time_t now;
    char time_buffer[32];

    if (argc < 2) {
        (void) fprintf(stderr, "Usage: %s <command> ...\n", argv[0]);
        exit(1);
    }

    rotate_logs();
    redirect_output();
    disable_cores();
    dump_privs();
    dump_args(argc, argv);

    /* get the current time for the log */
    time(&now);
    cftime(time_buffer, "%Y-%m-%dT%H:%M:%SZ", &now);

    /* print the header for the output from the program we exec (pre-flush) */
    (void) printf("=== OUTPUT (%s) ===\n", time_buffer);

    /* flush before next cmd takes over */
    (void) fflush(stdout);
    (void) fflush(stderr);

    exec_next(argc, argv);

    /* if we got here, we failed */
    (void) fprintf(stderr, "FATAL: execvp() failed.\n");
    exit(1);
}
示例#4
0
VOID WINAPI
WIN32_svcHandler(DWORD Opcode)
{
    DWORD status;

    switch (Opcode) {
    case _WIN_SQUID_SERVICE_CONTROL_STOP:
    case _WIN_SQUID_SERVICE_CONTROL_SHUTDOWN:
        /* Do whatever it takes to stop here. */
        svcStatus.dwWin32ExitCode = 0;
        svcStatus.dwCurrentState = SERVICE_STOP_PENDING;
        svcStatus.dwCheckPoint = 0;
        svcStatus.dwWaitHint = 10000;
        shut_down(SIGTERM);
        if (!SetServiceStatus(svcHandle, &svcStatus)) {
            status = GetLastError();
            debug(1, 1) ("SetServiceStatus error %ld\n", status);
        }
        debug(1, 1) ("Leaving Squid service\n");
        return;
    case _WIN_SQUID_SERVICE_CONTROL_INTERROGATE:
        /* Fall through to send current status. */
        if (!SetServiceStatus(svcHandle, &svcStatus)) {
            status = GetLastError();
            debug(1, 1) ("SetServiceStatus error %ld\n", status);
        }
        break;
    case _WIN_SQUID_SERVICE_CONTROL_ROTATE:
        rotate_logs(SIGUSR1);
        break;
    case _WIN_SQUID_SERVICE_CONTROL_RECONFIGURE:
        reconfigure(SIGHUP);
        break;
    case _WIN_SQUID_SERVICE_CONTROL_DEBUG:
        sigusr2_handle(SIGUSR2);
        break;
    case _WIN_SQUID_SERVICE_CONTROL_INTERRUPT:
        /* Do whatever it takes to stop here. */
        svcStatus.dwWin32ExitCode = 0;
        svcStatus.dwCurrentState = SERVICE_STOP_PENDING;
        svcStatus.dwCheckPoint = 0;
        svcStatus.dwWaitHint = 10000;
        shut_down(SIGINT);
        if (!SetServiceStatus(svcHandle, &svcStatus)) {
            status = GetLastError();
            debug(1, 1) ("SetServiceStatus error %ld\n", status);
        }
        debug(1, 1) ("Leaving Squid service\n");
        break;
    default:
        debug(1, 1) ("Unrecognized opcode %ld\n", Opcode);
    }
    return;
}
示例#5
0
static void processBuffer(struct log_device_t* dev, struct logger_entry *buf)
{
	int bytes_written = 0;
	int err;
	log_entry entry;
	char mgs_buf[1024];

	err = log_process_log_buffer(buf, &entry);

	if (err < 0) {
		goto error;
	}

	if (log_should_print_line(g_logformat, entry.tag, entry.priority)) {
		if (false && g_dev_count > 1) {
			// FIXME
			mgs_buf[0] = dev->device[0];
			mgs_buf[1] = ' ';
			bytes_written = write(g_outfd, mgs_buf, 2);
			if (bytes_written < 0)
			{
				perror("output error");
				exit(-1);
			}
		}

		bytes_written = log_print_log_line(g_logformat, g_outfd, &entry);

		if (bytes_written < 0)
		{
			perror("output error");
			exit(-1);
		}
	}

	g_out_byte_count += bytes_written;

    if (g_log_rotate_size_kbytes > 0 && (g_out_byte_count / 1024) >= g_log_rotate_size_kbytes)
	{
		rotate_logs();
	}

error:
	//fprintf (stderr, "Error processing record\n");
	return;
}
示例#6
0
Server *reload_server(Server *old_srv, const char *db_file, const char *server_uuid)
{
    log_info("------------------------ RELOAD %s -----------------------------------", server_uuid);
    MIME_destroy();
    Setting_destroy();

    Server *srv = load_server(db_file, server_uuid, old_srv);
    check(srv != NULL, "Failed to load new server config.");

    Server_stop_handlers(old_srv);

    rotate_logs();

    RELOAD = 0;
    return srv;

error:
    return NULL;
}
示例#7
0
文件: rtv.c 项目: cgbarnwell/mvpmc
void rtvVLog(const char *format, va_list ap)
{
   if (log_to_file) {
      char    tm_buf[255], newfmt[1024];
      time_t  tim = time(NULL);
      char   *ct  = ctime_r(&tim, tm_buf);

      snprintf(newfmt, sizeof(newfmt), "%15.15s %s", &ct[4], format);
      vfprintf(rtv_globals.log_fd, newfmt, ap);

      // See if it is time to rotate the log file
      //
      fflush(rtv_globals.log_fd);
      if ( ++log_count > log_rotate_cnt ) {
         rotate_logs();
      }
   } 
   else {
      vfprintf(rtv_globals.log_fd, format, ap);
   }
   return;
}
示例#8
0
void setup_log (void)
{
    set_log_level(log_level);

    if (lispd_config.daemonize) {

        freopen( "/dev/null", "r", stdin);
        freopen( "/dev/null", "w", stdout);
        freopen( "/dev/null", "w", stderr);

        rotate_logs();
        logfile = freopen(LOGFILE_LOCATION, "w", stderr);
        if (!logfile) {
            fprintf(stderr, "Failed to open logfile errno: %d", errno);
            exit(-1);
            return;
        }
    } else {
        logfile = stdout;
    }
    log_msg(INFO, "starting up...");
}
示例#9
0
/*
 * function monitor librdkafka queue size and write to   
 * local  file , the path will depend on usr configure
 * default /var/log/sendkafka
 */
void check_queuedata_size(rd_kafka_t ** rks, int num, char *queuesize_path)
{

	static time_t lasttime = 0;
	time_t curenttime = getcurrents();

	if ((curenttime % g_monitor_period) == 0 && curenttime != lasttime) {
		char buf[128] = { 0 };
		int i = 0;

		rotate_logs(queuesize_path);

		int fd = open(queuesize_path, O_WRONLY | O_APPEND | O_CREAT, 0666);

		if(fd == -1){
			char buf[1024] = { 0 };
			sprintf(buf, "%d line open %s fail...", __LINE__ - 4,queuesize_path);
			save_error(g_logsavelocal_tag, LOG_CRIT, buf);
			exit(3);
		}

		char timebuf[50] = { 0 };
		strcpy(timebuf, getcurrenttime());
		timebuf[strlen(timebuf) - 1] = '\0';

		for (; i < num; ++i) {
			sprintf(buf, "%s|%s| queue size= %d\n",
				timebuf,
				rks[i] ? rks[i]->rk_broker.name : "",
				rd_kafka_outq_len(rks[i]));
			write(fd, buf, strlen(buf));
			memset(buf, '\0', 128);
		}

		close(fd);
		lasttime = curenttime;
	}
}
示例#10
0
文件: running.c 项目: ens-ds23/fuse8
static void hupev(evutil_socket_t fd,short what,void *arg) {
  struct running *rr = (struct running *)arg;

  rotate_logs(rr);
}