Example #1
0
File: log.c Project: azuwis/mpd
void setup_log_output(bool use_stdout)
{
	fflush(NULL);
	if (!use_stdout) {
		if (out_filename != NULL) {
			redirect_logs(out_fd);
			close(out_fd);
		}

		stdout_mode = false;
		log_charset = NULL;
	}
}
Example #2
0
void setup_log_output(bool use_stdout)
{
	fflush(NULL);
	if (!use_stdout) {
#ifndef WIN32
		if (out_filename == NULL)
			out_fd = open("/dev/null", O_WRONLY);
#endif

		if (out_fd >= 0) {
			redirect_logs(out_fd);
			close(out_fd);
		}

		stdout_mode = false;
		log_charset = NULL;
	}
}
Example #3
0
File: log.c Project: azuwis/mpd
int cycle_log_files(void)
{
	int fd;

	if (stdout_mode || out_filename == NULL)
		return 0;
	assert(out_filename);

	g_debug("Cycling log files...\n");
	close_log_files();

	fd = open_log_file();
	if (fd < 0) {
		g_warning("error re-opening log file: %s\n", out_filename);
		return -1;
	}

	redirect_logs(fd);
	g_debug("Done cycling log files\n");
	return 0;
}
Example #4
0
int main(int argc, char **argv)
{
	/* pipe descriptors */
	int pd_rd[2], pd_wr[2];
	pid_t pid;
	char *pppd = STD_PPPD_PATH;
	char *log_path = STD_LOG_PATH;
	char *ip = NULL;
	char *mod_name = NULL;
	int mod_idx;
	int i;
	int need_arg = 0;
	int mod_argc = 0;
	char **mod_argv = NULL;

	prog_name = argv[0];

	/* parsing arguments */
	if (argc < 2)
		help(argv[0]);
	for (i = 1; i < argc; i++) {
		if (need_arg) {
			switch (need_arg) {
			case ARG_MODULE:
				mod_name = argv[i];
				break;
			case ARG_LOG_PATH:
				log_path = argv[i];
				break;
			default:
				fprintf(stderr, "there is internal problem with parsing arguments\n");
				return 1;
			}
			need_arg = 0;
			continue;
		}
		if (argv[i][0] != '-') {
			/* <local_ip>:<remote_ip> */
			ip = argv[i];
			continue;
		}
		if (!strcmp("-h", argv[i]) || !strcmp("--help", argv[i]))
			/* print help and exit */
			help(argv[0]);
		if (!strcmp("-l", argv[i]) || !strcmp("--list", argv[i]))
			/* print list of available modules and exit */
			list_mod();
		if (!strcmp("-L", argv[i])) {
			/* specify file for logging */
			need_arg = ARG_LOG_PATH;
			continue;
		}
		if (!strcmp("-m", argv[i])) {
			/* choose module */
			need_arg = ARG_MODULE;
			continue;
		}
		if (!strcmp("-q", argv[i]) || !strcmp("--quiet", argv[i])) {
			/* quiet mode */
			quiet = 1;
			continue;
		}
		if (!strcmp("--", argv[i])) {
			/* TODO: set pointer to i+1, the rest options are for pppd */
			mod_argv = argv + i;
			mod_argc = argc - i;
			break;
		}
		/* unrecognized options may be addressed for the module */
	}
	if (need_arg) {
		fprintf(stderr, "incomplete arguments, see %s --help\n", argv[0]);
		return 2;
	}
	/* check whether required arguments are set */
	if (!mod_name) {
		fprintf(stderr, "you must choose a module, see %s --help\n", argv[0]);
		return 2;
	}

	/* redirect logs to a file */
	redirect_logs(log_path);

	/* check whether module name is correct */
	if ((mod_idx = is_mod(mod_name)) < 0) {
		fprintf(stderr, "there isn't such a module: %s\n", mod_name);
		return 2;
	}

	/* create pipes for communication with pppd */
	if (pipe(pd_rd) < 0)
		err_exit("pipe");
	if (pipe(pd_wr) < 0)
		err_exit("pipe");

	/* exec pppd */
	if ((pid = fork()) < 0)
		err_exit("fork");
	if (!pid) {
		if (dup2(pd_rd[1], 1) < 0)
			err_exit("dup2");
		if (dup2(pd_wr[0], 0) < 0)
			err_exit("dup2");
		close(pd_rd[0]);
		close(pd_rd[1]);
		close(pd_wr[0]);
		close(pd_wr[1]);
		execl(pppd, pppd, "nodetach", "noauth", "notty", "passive", ip, NULL);
		err_exit("execl");
	}

	close(pd_rd[1]);
	close(pd_wr[0]);

	/* run appropriate module's function */
	return mod_tbl[mod_idx].func(mod_argc, mod_argv, pd_rd[0], pd_wr[1]);
}