View | Details | Raw Unified | Return to bug 265963 | Differences between
and this patch

Collapse All | Expand All

(-)clients/upslog.c (-3 / +48 lines)
Lines 32-37 Link Here
32
 */
32
 */
33
33
34
#include "common.h"
34
#include "common.h"
35
#include <unistd.h>
36
#include <sys/wait.h>
35
#include "nut_platform.h"
37
#include "nut_platform.h"
36
#include "upsclient.h"
38
#include "upsclient.h"
37
39
Lines 41-56 Link Here
41
#include "upslog.h"
43
#include "upslog.h"
42
44
43
	static	int	reopen_flag = 0, exit_flag = 0;
45
	static	int	reopen_flag = 0, exit_flag = 0;
46
	static  int	wait_status, num_monhosts = 0;
44
	static	uint16_t	port;
47
	static	uint16_t	port;
45
	static	char	*upsname, *hostname;
48
	static	char	*upsname, *hostname;
46
	static	UPSCONN_t	ups;
49
	static	UPSCONN_t	ups;
47
50
48
	static	FILE	*logfile;
51
	static	FILE	*logfile;
49
	static	const	char *logfn, *monhost;
52
	static	char *logfn, *monhost;
50
	static	sigset_t	nut_upslog_sigmask;
53
	static	sigset_t	nut_upslog_sigmask;
51
	static	char	logbuffer[LARGEBUF], *logformat;
54
	static	char	logbuffer[LARGEBUF], *logformat;
52
55
53
	static	flist_t	*fhead = NULL;
56
	static	flist_t	*fhead = NULL;
57
	struct 	monhost_child {
58
		char	*monhost;
59
		char	*logfn;
60
		char	*pidfilebase;
61
		pid_t	pid;
62
		struct	monhost_child	*next;
63
	};
64
	static	struct	monhost_child *monhost_child_anchor = NULL;
65
	static	struct	monhost_child *monhost_child_current;
66
	static	struct	monhost_child *monhost_child_prev = NULL;
67
	static	char	*m_arg;
54
68
55
#define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
69
#define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
56
		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
70
		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
Lines 396-413 Link Here
396
int main(int argc, char **argv)
410
int main(int argc, char **argv)
397
{
411
{
398
	int	interval = 30, i, foreground = -1;
412
	int	interval = 30, i, foreground = -1;
413
	size_t	monhost_len;
399
	const char	*prog = xbasename(argv[0]);
414
	const char	*prog = xbasename(argv[0]);
400
	time_t	now, nextpoll = 0;
415
	time_t	now, nextpoll = 0;
401
	const char	*user = NULL;
416
	const char	*user = NULL;
402
	struct passwd	*new_uid = NULL;
417
	struct passwd	*new_uid = NULL;
403
	const char	*pidfilebase = prog;
418
	char	*pidfilebase = prog;
404
419
405
	logformat = DEFAULT_LOGFORMAT;
420
	logformat = DEFAULT_LOGFORMAT;
406
	user = RUN_AS_USER;
421
	user = RUN_AS_USER;
407
422
408
	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
423
	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
409
424
410
	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
425
	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
411
		switch(i) {
426
		switch(i) {
412
			case 'h':
427
			case 'h':
413
				help(prog);
428
				help(prog);
Lines 415-420 Link Here
415
				break;
430
				break;
416
#endif
431
#endif
417
432
433
			case 'm':
434
				monhost_child_prev = monhost_child_current;
435
				monhost_child_current = malloc(sizeof(struct monhost_child));
436
				if (monhost_child_anchor == NULL)
437
					monhost_child_anchor = monhost_child_current;
438
				else
439
					monhost_child_prev->next = monhost_child_current;
440
				monhost_child_current->next = NULL;
441
				m_arg = optarg;
442
				monhost_child_current->monhost = strsep(&m_arg, ":");
443
				monhost_child_current->logfn = strsep(&m_arg, ":");
444
				monhost_child_current->pidfilebase = strsep(&m_arg, ":");
445
				break;
418
			case 's':
446
			case 's':
419
				monhost = optarg;
447
				monhost = optarg;
420
				break;
448
				break;
Lines 478-483 Link Here
478
		for (i = 3; i < argc; i++)
506
		for (i = 3; i < argc; i++)
479
			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
507
			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
480
	}
508
	}
509
510
	if (monhost_child_anchor != NULL) {
511
		for (monhost_child_current = monhost_child_anchor;
512
		     monhost_child_current != NULL;
513
		     monhost_child_current = monhost_child_current->next) {
514
			if ((monhost_child_current->pid = fork()) == 0) {
515
				monhost = monhost_child_current->monhost;
516
				logfn = monhost_child_current->logfn;
517
				pidfilebase = monhost_child_current->pidfilebase;
518
				break;
519
			}
520
		}
521
		if (monhost_child_anchor->pid)
522
			exit(EXIT_SUCCESS);
523
	}
524
525
	/* When num_monhosts == 1 monhost remains the only argument */
481
526
482
	if (!monhost)
527
	if (!monhost)
483
		fatalx(EXIT_FAILURE, "No UPS defined for monitoring - use -s <system>");
528
		fatalx(EXIT_FAILURE, "No UPS defined for monitoring - use -s <system>");

Return to bug 265963